summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/genjsbind-lexer.l22
-rw-r--r--src/genjsbind-parser.y42
-rw-r--r--src/webidl-lexer.l7
-rw-r--r--test/data/bindings/htmldocument.bnd16
4 files changed, 68 insertions, 19 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;
}
diff --git a/test/data/bindings/htmldocument.bnd b/test/data/bindings/htmldocument.bnd
index 55a8ac7..24699c1 100644
--- a/test/data/bindings/htmldocument.bnd
+++ b/test/data/bindings/htmldocument.bnd
@@ -51,6 +51,18 @@ static JSBool JSAPI_NATIVE(write, JSContext *cx, uintN argc, jsval *vp)
return JS_TRUE;
}
-]]]
+]]];
-interface "Document";
+binding document {
+ type js_libdom {
+ node dom_document;
+
+ }; /* the binding type and any instance specific extra data */
+
+ extra "struct html_content *htmlc"; /* extra parameters to constructor
+ * value stored in private context
+ * structure.
+ */
+
+ interface Document; /* Web IDL interface to generate */
+}; \ No newline at end of file