diff options
-rw-r--r-- | src/genjsbind-lexer.l | 50 | ||||
-rw-r--r-- | src/genjsbind-parser.y | 24 | ||||
-rw-r--r-- | src/webidl-lexer.l | 29 | ||||
-rw-r--r-- | src/webidl-parser.y | 14 |
4 files changed, 76 insertions, 41 deletions
diff --git a/src/genjsbind-lexer.l b/src/genjsbind-lexer.l index 8bfa391..1406872 100644 --- a/src/genjsbind-lexer.l +++ b/src/genjsbind-lexer.l @@ -1,33 +1,47 @@ +%{ + /* * binding generator lexer */ -/* lexer options */ -%option never-interactive -%option bison-bridge -%option nodefault -%option warn -%option prefix="genjsbind_" -%option nounput - -/* header block */ -%{ - #include <stdbool.h> #include <stdio.h> #include <string.h> #include "genjsbind-parser.h" +#define YY_USER_ACTION yylloc->first_line = yylloc->last_line; \ + yylloc->first_column = yylloc->last_column + 1; \ + yylloc->last_column += yyleng; + %} - /* other Unicode “space separator” */ +/* lexer options */ +%option never-interactive +%option yylineno +%option bison-bridge +%option bison-locations +%option nodefault +%option warn +%option prefix="genjsbind_" +%option nounput +%option noinput + +/* other Unicode “space separator” */ USP (\xe1\x9a\x80)|(\xe1\xa0\x8e)|(\xe2\x80[\x80-\x8a])|(\xe2\x80\xaf)|(\xe2\x81\x9f)|(\xe3\x80\x80) /* non breaking space \u00A0 */ NBSP (\xc2\xa0) -whitespace ([ \t\v\f\n]|{NBSP}|{USP}) +/* Line separator \u2028 */ +LS (\xe2\x80\xa8) + +/* paragraph separator \u2029 */ +PS (\xe2\x80\xa9) + +whitespace ([ \t\v\f]|{NBSP}|{USP}) + +lineend ([\n\r]|{LS}|{PS}) multicomment \/\*(([^*])|(\*[^/]))*\*\/ @@ -45,7 +59,13 @@ cblockclose \]\]\] %% -{whitespace} /* nothing */ +{whitespace} ++yylloc->last_column;/* nothing */ + +{lineend} if (yytext[0] != '\r') { + /* update position counts */ + ++yylloc->last_line; + yylloc->last_column = 0; + } /* terminals */ @@ -75,7 +95,7 @@ node return TOK_NODE; return TOK_IDENTIFIER; } -\"{quotedstring}*\" yylval->text = strndup(yytext + 1,strlen(yytext+1) - 1 ); return TOK_STRING_LITERAL; +\"{quotedstring}*\" yylval->text = strndup(yytext + 1, yyleng - 2 ); return TOK_STRING_LITERAL; {multicomment} /* nothing */ diff --git a/src/genjsbind-parser.y b/src/genjsbind-parser.y index c3122ea..1a342ae 100644 --- a/src/genjsbind-parser.y +++ b/src/genjsbind-parser.y @@ -1,10 +1,9 @@ +%{ /* * This is a bison parser for genbind * */ -%{ - #include <stdio.h> #include <string.h> @@ -13,9 +12,11 @@ #include "webidl-ast.h" #include "jsapi-binding.h" +char *errtxt; + static void genjsbind_error(const char *str) { - fprintf(stderr,"error: %s\n",str); + errtxt = strdup(str); } @@ -24,11 +25,11 @@ int genjsbind_wrap() return 1; } - - %} +%locations %define api.pure +%error-verbose %union { @@ -55,8 +56,17 @@ int genjsbind_wrap() /* [1] start with Statements */ Statements - : Statement - | Statements Statement + : + Statement + | + Statements Statement + | + error ';' + { + fprintf(stderr, "%d: %s\n", yylloc.first_line, errtxt); + free(errtxt); + YYABORT ; + } ; Statement diff --git a/src/webidl-lexer.l b/src/webidl-lexer.l index 0a0a5df..d240edc 100644 --- a/src/webidl-lexer.l +++ b/src/webidl-lexer.l @@ -1,5 +1,7 @@ +%{ + /* - * This is a unicode capable lexer for web IDL mostly derived from: + * This is a unicode capable lexer for web IDL derived from: * * W3C WEB IDL - http://www.w3.org/TR/WebIDL/ (especially the grammar * in apendix A) @@ -9,19 +11,6 @@ * section 7.2 for unicode value handling) */ -/* lexer options */ -%option never-interactive -%option yylineno -%option bison-bridge -%option bison-locations -%option nodefault -%option warn -%option prefix="webidl_" -%option nounput - -/* header block */ -%{ - #include <stdbool.h> #include <stdio.h> #include <string.h> @@ -34,6 +23,16 @@ %} + +/* lexer options */ +%option never-interactive +%option yylineno +%option bison-bridge +%option bison-locations +%option warn +%option prefix="webidl_" +%option nounput + /* regular definitions */ /* ecmascript section 7.2 defines whitespace http://ecma-international.org/ecma-262/5.1/#sec-7.2 @@ -100,7 +99,7 @@ poundsign ^{whitespace}*# {whitespace} ++yylloc->last_column; /* skip whitespace */ -{lineend} if (yytext[0] == '\n') { +{lineend} if (yytext[0] != '\r') { /* update position counts */ ++yylloc->last_line; yylloc->last_column = 0; diff --git a/src/webidl-parser.y b/src/webidl-parser.y index c4e25f1..1a40e41 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -14,11 +14,11 @@ #include "webidl-parser.h" #include "webidl-lexer.h" - +char *errtxt; static void webidl_error(const char *str) { - fprintf(stderr,"error: %s\n",str); + errtxt = strdup(str); } int webidl_wrap() @@ -26,12 +26,11 @@ int webidl_wrap() return 1; } - - %} %locations %define api.pure +%error-verbose /* the w3c grammar results in 10 shift/reduce, 2 reduce/reduce conflicts * The reduce/reduce error are both the result of empty sequences @@ -118,6 +117,13 @@ Definitions: /* empty */ | ExtendedAttributeList Definition Definitions + | + error ';' + { + fprintf(stderr, "%d: %s\n", yylloc.first_line, errtxt); + free(errtxt); + YYABORT ; + } ; /* [2] */ |