%{ /* parser for the binding generation config file * * This file is part of nsgenjsbind. * Licensed under the MIT License, * http://www.opensource.org/licenses/mit-license.php * Copyright 2012 Vincent Sanders */ #include #include #include "genjsbind-parser.h" #include "genjsbind-lexer.h" #include "webidl-ast.h" #include "genjsbind-ast.h" char *errtxt; static void genjsbind_error(YYLTYPE *locp, struct genbind_node **genbind_ast, const char *str) { locp = locp; genbind_ast = genbind_ast; errtxt = strdup(str); } %} %locations %define api.pure %error-verbose %parse-param { struct genbind_node **genbind_ast } %union { char* text; struct genbind_node *node; } %token TOK_IDLFILE %token TOK_HDR_COMMENT %token TOK_PREAMBLE %token TOK_BINDING %token TOK_OPERATION %token TOK_INTERFACE %token TOK_TYPE %token TOK_PRIVATE %token TOK_IDENTIFIER %token TOK_STRING_LITERAL %token TOK_CCODE_LITERAL %type CBlock %type Statement %type Statements %type IdlFile %type Preamble %type HdrComment %type Strings %type Binding %type BindingArgs %type BindingArg %type Type %type Private %type Interface %type Operation %% Input : Statements { *genbind_ast = $1; } ; Statements : Statement | Statements Statement { $$ = genbind_node_link($2, $1); } | error ';' { fprintf(stderr, "%d: %s\n", yylloc.first_line, errtxt); free(errtxt); YYABORT ; } ; Statement : IdlFile | HdrComment | Preamble | Binding | Operation ; /* [3] load a web IDL file */ IdlFile : TOK_IDLFILE TOK_STRING_LITERAL ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_WEBIDLFILE, NULL, $2); } ; HdrComment : TOK_HDR_COMMENT Strings ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_HDRCOMMENT, NULL, $2); } ; Strings : TOK_STRING_LITERAL { $$ = genbind_new_node(GENBIND_NODE_TYPE_STRING, NULL, $1); } | Strings TOK_STRING_LITERAL { $$ = genbind_new_node(GENBIND_NODE_TYPE_STRING, $1, $2); } ; Preamble : TOK_PREAMBLE CBlock { $$ = genbind_new_node(GENBIND_NODE_TYPE_PREAMBLE, NULL, $2); } ; CBlock : TOK_CCODE_LITERAL | CBlock TOK_CCODE_LITERAL { $$ = genbind_strapp($1, $2); } ; Operation : TOK_OPERATION TOK_IDENTIFIER CBlock { $$ = genbind_new_node(GENBIND_NODE_TYPE_OPERATION, NULL, genbind_new_node(GENBIND_NODE_TYPE_IDENT, genbind_new_node(GENBIND_NODE_TYPE_CBLOCK, NULL, $3), $2)); } Binding : TOK_BINDING TOK_IDENTIFIER '{' BindingArgs '}' { $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING, NULL, genbind_new_node(GENBIND_NODE_TYPE_IDENT, $4, $2)); } ; BindingArgs : BindingArg | BindingArgs BindingArg { $$ = genbind_node_link($2, $1); } ; BindingArg : Type | Private | Interface ; Type : TOK_TYPE TOK_IDENTIFIER ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_TYPE, NULL, $2); } ; Private : TOK_PRIVATE Strings ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_PRIVATE, NULL, $2); } ; Interface : TOK_INTERFACE TOK_IDENTIFIER ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_INTERFACE, NULL, $2); } ; %%