%{ /* 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_INTERFACE %token TOK_TYPE %token TOK_EXTRA %token TOK_NODE %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 TypeArgs %type Extra %type Interface %type Node %% 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 ; /* [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); } ; Binding : TOK_BINDING TOK_IDENTIFIER '{' BindingArgs '}' ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING, NULL, genbind_new_node(GENBIND_NODE_TYPE_BINDING_IDENT, $4, $2)); } ; BindingArgs : BindingArg | BindingArgs BindingArg { $$ = genbind_node_link($2, $1); } ; BindingArg : Type | Extra | Interface ; Type : TOK_TYPE TOK_IDENTIFIER '{' TypeArgs '}' ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_TYPE, NULL, genbind_new_node(GENBIND_NODE_TYPE_TYPE_IDENT, $4, $2)); } ; TypeArgs : /* empty */ { $$ = NULL; } | Node ; Node : TOK_NODE TOK_IDENTIFIER ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_TYPE_NODE, NULL, $2); } ; Extra : TOK_EXTRA Strings ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_TYPE_EXTRA, NULL, $2); } ; Interface : TOK_INTERFACE TOK_IDENTIFIER ';' { $$ = genbind_new_node(GENBIND_NODE_TYPE_TYPE_INTERFACE, NULL, $2); } ; %%