From 3db9b84cd1a23f4718260a6b2487dcedbb7fc526 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 6 Sep 2012 19:07:15 +0100 Subject: move towards having a binding stanza --- src/genjsbind-lexer.l | 22 ++++++++++++++++++- src/genjsbind-parser.y | 42 +++++++++++++++++++++++++------------ src/webidl-lexer.l | 7 ++++--- test/data/bindings/htmldocument.bnd | 16 ++++++++++++-- 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 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 TOK_IDENTIFIER + %token TOK_STRING_LITERAL %token 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 -- cgit v1.2.3