summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/genjsbind-lexer.l22
-rw-r--r--src/genjsbind-parser.y42
-rw-r--r--src/webidl-lexer.l7
3 files changed, 54 insertions, 17 deletions
diff --git a/src/genjsbind-lexer.l b/src/genjsbind-lexer.l
index 8364247..af49db9 100644
--- a/src/genjsbind-lexer.l
+++ b/src/genjsbind-lexer.l
@@ -33,6 +33,8 @@ multicomment \/\*(([^*])|(\*[^/]))*\*\/
quotedstring [^\"\\\n\r]
+identifier [A-Z_a-z][0-9A-Z_a-z]*
+
other [^\t\n\r 0-9A-Z_a-z]
cblockopen \[\[\[
@@ -45,16 +47,34 @@ cblockclose \]\]\]
{whitespace} /* nothing */
+ /* terminals */
+
webidlfile return TOK_IDLFILE;
hdrcomment return TOK_HDR_COMMENT;
+preamble return TOK_PREAMBLE;
+
+binding return TOK_BINDING;
+
interface return TOK_INTERFACE;
-preamble return TOK_PREAMBLE;
+type return TOK_TYPE;
+
+extra return TOK_EXTRA;
+
+%token <text> TOK_IDENTIFIER
{cblockopen} BEGIN(cblock);
+{identifier} {
+ /* A leading "_" is used to escape an identifier from
+ * looking like a reserved word terminal.
+ */
+ yylval->text = (yytext[0] == '_') ? strdup(yytext + 1) : strdup(yytext);
+ return TOK_IDENTIFIER;
+ }
+
\"{quotedstring}*\" yylval->text = strndup(yytext + 1,strlen(yytext+1) - 1 ); return TOK_STRING_LITERAL;
{multicomment} /* nothing */
diff --git a/src/genjsbind-parser.y b/src/genjsbind-parser.y
index 8436034..ce8a1fd 100644
--- a/src/genjsbind-parser.y
+++ b/src/genjsbind-parser.y
@@ -37,12 +37,19 @@ int genjsbind_wrap()
%token TOK_IDLFILE
%token TOK_HDR_COMMENT
-%token TOK_INTERFACE
%token TOK_PREAMBLE
+%token TOK_BINDING
+%token TOK_INTERFACE
+%token TOK_TYPE
+%token TOK_EXTRA
+
+%token <text> TOK_IDENTIFIER
+
%token <text> TOK_STRING_LITERAL
%token <text> TOK_CCODE_LITERAL
+
%%
/* [1] start with Statements */
@@ -59,7 +66,7 @@ Statement
|
Preamble
|
- Interface
+ Binding
;
/* [3] load a web IDL file */
@@ -73,33 +80,25 @@ IdlFile
;
HdrComment
- : TOK_HDR_COMMENT Strings ';'
+ : TOK_HDR_COMMENT HdrStrings ';'
{
}
;
-Strings
+HdrStrings
:
TOK_STRING_LITERAL
{
genjsbind_header_comment($1);
}
|
- Strings TOK_STRING_LITERAL
+ HdrStrings TOK_STRING_LITERAL
{
genjsbind_header_comment($2);
}
;
-Interface
- :
- TOK_INTERFACE TOK_STRING_LITERAL ';'
- {
- genjsbind_interface($2);
- }
- ;
-
Preamble
:
TOK_PREAMBLE CBlock
@@ -118,4 +117,21 @@ CBlock
}
;
+Binding
+ :
+ TOK_BINDING TOK_IDENTIFIER '{' BindingArgs '}' ';'
+ ;
+
+BindingArgs
+:
+;
+
+Interface
+ :
+ TOK_INTERFACE TOK_STRING_LITERAL ';'
+ {
+ genjsbind_interface($2);
+ }
+ ;
+
%%
diff --git a/src/webidl-lexer.l b/src/webidl-lexer.l
index 20ee4c5..0a0a5df 100644
--- a/src/webidl-lexer.l
+++ b/src/webidl-lexer.l
@@ -87,7 +87,7 @@ escseq {characterescseq}|0|{hexescseq}|{unicodeescseq}
quotedstring ([^\"\\\n\r]|\\{escseq})
/* web idl identifier direct from spec */
-Identifier [A-Z_a-z][0-9A-Z_a-z]*
+identifier [A-Z_a-z][0-9A-Z_a-z]*
/* web idl other direct from spec */
other [^\t\n\r 0-9A-Z_a-z]
@@ -193,8 +193,9 @@ void return TOK_VOID;
readonly return TOK_READONLY;
-{Identifier} {
- // A leading "_" is used to escape an identifier from looking like a reserved word terminal.
+{identifier} {
+ /* A leading "_" is used to escape an identifier from
+ * looking like a reserved word terminal. */
yylval->text = (yytext[0] == '_') ? strdup(yytext + 1) : strdup(yytext);
return TOK_IDENTIFIER;
}