From f9a691eff4e7935dde309b16e25c11e4ec10d6bd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 9 Mar 2019 18:15:37 +0000 Subject: [PATCH] Add libpakfire-parser This library is now a prototype for a bison/flex parser of the package metadata. Signed-off-by: Michael Tremer --- Makefile.am | 24 +++++++++- src/libpakfire/archive.c | 5 +- src/libpakfire/include/pakfire/parser.h | 30 ++++++++++++ src/libpakfire/parser/.gitignore | 2 + src/libpakfire/parser/grammar.y | 63 +++++++++++++++++++++++++ src/libpakfire/parser/scanner.l | 45 ++++++++++++++++++ 6 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 src/libpakfire/include/pakfire/parser.h create mode 100644 src/libpakfire/parser/.gitignore create mode 100644 src/libpakfire/parser/grammar.y create mode 100644 src/libpakfire/parser/scanner.l diff --git a/Makefile.am b/Makefile.am index b8af3230b..9e0fd84f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,6 +70,7 @@ PAKFIRE_LIBS = libpakfire.la check_PROGRAMS = lib_LTLIBRARIES = libexec_PROGRAMS = +noinst_LTLIBRARIES = pkgpyexec_LTLIBRARIES = pkginclude_HEADERS = @@ -239,6 +240,24 @@ _pakfire_la_LIBADD = \ # ------------------------------------------------------------------------------ +CLEANFILES += \ + src/libpakfire/grammar.c \ + src/libpakfire/grammar.h \ + src/libpakfire/scanner.c + +noinst_LTLIBRARIES += \ + libpakfire-parser.la + +libpakfire_parser_la_SOURCES = \ + src/libpakfire/parser/grammar.h \ + src/libpakfire/parser/grammar.y \ + src/libpakfire/parser/scanner.l + +libpakfire_parser_la_CFLAGS = \ + $(AM_CFLAGS) + +src/libpakfire/parser/scanner.c: src/libpakfire/parser/grammar.h + lib_LTLIBRARIES += \ libpakfire.la @@ -276,6 +295,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/package.h \ src/libpakfire/include/pakfire/packagelist.h \ src/libpakfire/include/pakfire/pakfire.h \ + src/libpakfire/include/pakfire/parser.h \ src/libpakfire/include/pakfire/private.h \ src/libpakfire/include/pakfire/problem.h \ src/libpakfire/include/pakfire/relation.h \ @@ -307,6 +327,7 @@ libpakfire_la_LDFLAGS = \ -Wl,--version-script=$(top_srcdir)/src/libpakfire/libpakfire.sym libpakfire_la_LIBADD = \ + libpakfire-parser.la \ $(ARCHIVE_LIBS) \ $(GPGME_LIBS) \ $(LIBGCRYPT_LIBS) \ @@ -314,7 +335,8 @@ libpakfire_la_LIBADD = \ $(SOLV_LIBS) libpakfire_la_DEPENDENCIES = \ - src/libpakfire/libpakfire.sym + src/libpakfire/libpakfire.sym \ + libpakfire-parser.la EXTRA_DIST += \ src/libpakfire/libpakfire.sym diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index e47284fd6..54cf977d9 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -357,11 +357,12 @@ static int pakfire_archive_parse_entry_metadata(PakfireArchive archive, return 1; } - #warning actually parse this + // Parse metadata file + r = pakfire_parser_parse_metadata(archive->pakfire, data, data_size); pakfire_free(data); - return 0; + return r; } static int pakfire_archive_parse_entry_filelist(PakfireArchive archive, diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h new file mode 100644 index 000000000..4f73a9845 --- /dev/null +++ b/src/libpakfire/include/pakfire/parser.h @@ -0,0 +1,30 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2019 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_PARSER_H +#define PAKFIRE_PARSER_H + +#ifdef PAKFIRE_PRIVATE + +int pakfire_parser_parse_metadata(const char* data, size_t len); + +#endif /* PAKFIRE_PRIVATE */ + +#endif /* PAKFIRE_PARSER_H */ diff --git a/src/libpakfire/parser/.gitignore b/src/libpakfire/parser/.gitignore new file mode 100644 index 000000000..59f9e3cc0 --- /dev/null +++ b/src/libpakfire/parser/.gitignore @@ -0,0 +1,2 @@ +/grammar.[ch] +/scanner.c diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y new file mode 100644 index 000000000..04c76167a --- /dev/null +++ b/src/libpakfire/parser/grammar.y @@ -0,0 +1,63 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2019 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +%{ +#include +#include + +#define YYERROR_VERBOSE 1 + +typedef struct yy_buffer_state* YY_BUFFER_STATE; +extern YY_BUFFER_STATE yy_scan_bytes(const char* buffer, size_t len); +extern void yy_delete_buffer(YY_BUFFER_STATE buffer); + +extern int yylex(); +extern int yyparse(); +void yyerror(const char* s); +%} + +%token APPEND +%token ASSIGN +%token DEFINE +%token END +%token NEWLINE +%token TAB +%token VARIABLE +%token VALUE +%token WHITESPACE + +%% + +top: NEWLINE + +%% + +int pakfire_parser_parse_metadata(const char* data, size_t len) { + YY_BUFFER_STATE buffer = yy_scan_bytes(data, len); + int r = yyparse(); + yy_delete_buffer(buffer); + + return r; +} + +void yyerror(const char* s) { + fprintf(stderr, "Parse error: %s\n", s); + abort(); +} diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l new file mode 100644 index 000000000..406c5c4c8 --- /dev/null +++ b/src/libpakfire/parser/scanner.l @@ -0,0 +1,45 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2019 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +%option nounput noinput noyywrap yylineno + +%{ +#define YY_DECL int yylex() + +#include "grammar.h" +%} + +%% + +[ \t] { return WHITESPACE; } +\t { return TAB; } +\n { return NEWLINE; } + +[A-Za-z] { return VARIABLE; } +[A-Za-z0-9] { return VALUE; } + +"=" { return ASSIGN; } +"+=" { return APPEND; } + +"define" { return DEFINE; } +"def" { return DEFINE; } +"end" { return END; } + +%% -- 2.39.5