summaryrefslogtreecommitdiff
path: root/lib/parse.ypp
diff options
context:
space:
mode:
authorTizenOpenSource <tizenopensrc@samsung.com>2024-01-22 15:17:04 +0900
committerTizenOpenSource <tizenopensrc@samsung.com>2024-01-22 15:17:04 +0900
commitd6ea7e7c4172902086eab521ac7e74fab2009efd (patch)
treeb52a4d6e16b14445a5b6c7b7d6b893813fdaa490 /lib/parse.ypp
parentd97bcaac29892fdfedf726d9127af64b98390d1c (diff)
downloadre2c-upstream.tar.gz
re2c-upstream.tar.bz2
re2c-upstream.zip
Imported Upstream version 3.1upstream/3.1upstream
Diffstat (limited to 'lib/parse.ypp')
-rw-r--r--lib/parse.ypp89
1 files changed, 44 insertions, 45 deletions
diff --git a/lib/parse.ypp b/lib/parse.ypp
index 37bb54b1..bfdee3e9 100644
--- a/lib/parse.ypp
+++ b/lib/parse.ypp
@@ -1,3 +1,11 @@
+%code requires {
+/* pull in types to populate YYSTYPE: */
+#include "src/parse/ast.h"
+namespace re2c {
+ struct AstNode;
+}
+}
+
%{
#include <stdio.h>
@@ -5,41 +13,36 @@
#include "src/parse/ast.h"
#include "src/util/attribute.h"
-#include "src/util/c99_stdint.h"
+#include <stdint.h>
#include "lib/lex.h"
-// disable certain GCC and/or Clang warnings, as we have no control over
-// autogenerated code (Clang also understands '#pragma GCC')
#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wpragmas"
-#pragma GCC diagnostic ignored "-Wconversion"
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#pragma GCC diagnostic ignored "-Wunused-macros"
-#pragma GCC diagnostic ignored "-Wmissing-variable-declarations"
-#pragma GCC diagnostic ignored "-Wunreachable-code"
-#pragma GCC diagnostic ignored "-Wunreachable-code-break"
+#include "src/util/nowarn_in_bison.h"
using namespace re2c;
-
-extern "C" {
-
-int yylex(const char *&pattern);
-void yyerror(const char *pattern, const char*) RE2C_ATTR((noreturn));
-
-} // extern "C"
-
%}
-%lex-param {const char *&pattern}
-%parse-param {const char *&pattern}
+%define api.pure full
+%lex-param {const uint8_t*& pattern}
+%lex-param {re2c::Ast& ast}
+%parse-param {const uint8_t*& pattern}
+%parse-param {re2c::Ast& ast}
%start regexp
%union {
- const re2c::AST *regexp;
- re2c::ASTBounds bounds;
+ const re2c::AstNode* regexp;
+ re2c::AstBounds bounds;
};
+%{
+extern "C" {
+ static int yylex(YYSTYPE* yylval, const uint8_t*& pattern, Ast& ast);
+ static void yyerror(const uint8_t* pattern, Ast&, const char* msg) RE2C_ATTR((noreturn));
+}
+
+%}
+
%token TOKEN_COUNT
%token TOKEN_ERROR
%token TOKEN_REGEXP
@@ -53,26 +56,26 @@ regexp: expr { regexp = $$; };
expr
: term
-| expr '|' term { $$ = ast_alt($1, $3); }
+| expr '|' term { $$ = ast.alt($1, $3); }
;
term
: factor
-| factor term { $$ = ast_cat($1, $2); } // in POSIX concatenation is right-associative
+| factor term { $$ = ast.cat($1, $2); } // in POSIX concatenation is right-associative
;
factor
: primary
-| primary '*' { $$ = ast_iter($1, 0, AST::MANY); }
-| primary '+' { $$ = ast_iter($1, 1, AST::MANY); }
-| primary '?' { $$ = ast_iter($1, 0, 1); }
-| primary TOKEN_COUNT { $$ = ast_iter($1, $2.min, $2.max); }
+| primary '*' { $$ = ast.iter($1, 0, Ast::MANY); }
+| primary '+' { $$ = ast.iter($1, 1, Ast::MANY); }
+| primary '?' { $$ = ast.iter($1, 0, 1); }
+| primary TOKEN_COUNT { $$ = ast.iter($1, $2.min, $2.max); }
;
primary
: TOKEN_REGEXP
-| '(' ')' { $$ = ast_cap(ast_nil(NOWHERE)); }
-| '(' expr ')' { $$ = ast_cap($2); }
+| '(' ')' { $$ = ast.cap(ast.nil(NOWHERE), CAPTURE); }
+| '(' expr ')' { $$ = ast.cap($2, CAPTURE); }
;
%%
@@ -80,25 +83,21 @@ primary
#pragma GCC diagnostic pop
extern "C" {
-
-void yyerror(const char *pattern, const char *msg)
-{
- fprintf(stderr, "%s (on RE %s)", msg, pattern);
- exit(1);
+ static void yyerror(const uint8_t* pattern, Ast&, const char* msg) {
+ fprintf(stderr, "%s (on regexp %s)", msg, pattern);
+ exit(1);
+ }
+
+ static int yylex(YYSTYPE* yylval, const uint8_t*& pattern, Ast& ast) {
+ return lex(yylval, pattern, ast);
+ }
}
-int yylex(const char *&pattern)
-{
- return lex(pattern);
-}
-
-} // extern "C"
-
namespace re2c {
-const AST *parse(const char *pattern)
-{
- yyparse(pattern);
+const AstNode* parse(const char* pattern, Ast& ast) {
+ const uint8_t *p = reinterpret_cast<const uint8_t*>(pattern);
+ yyparse(p, ast);
return regexp;
}