From b00346cd08b55d25e427cfabafbaa66e09a8444b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 23 Oct 2012 17:43:09 +0100 Subject: The name of teh tool is nsgenbind correct this everywhere --- src/nsgenbind-parser.y | 228 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 src/nsgenbind-parser.y (limited to 'src/nsgenbind-parser.y') diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y new file mode 100644 index 0000000..500f4b8 --- /dev/null +++ b/src/nsgenbind-parser.y @@ -0,0 +1,228 @@ +%{ +/* parser for the binding generation config file + * + * This file is part of nsgenbind. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2012 Vincent Sanders + */ + +#include +#include + +#include "nsgenbind-parser.h" +#include "nsgenbind-lexer.h" +#include "webidl-ast.h" +#include "nsgenbind-ast.h" + +char *errtxt; + + static void nsgenbind_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 TOK_STRING_LITERAL TOK_IDENTIFIER ';' + { + $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_PRIVATE, NULL, + genbind_new_node(GENBIND_NODE_TYPE_IDENT, + genbind_new_node(GENBIND_NODE_TYPE_STRING, NULL, $2), $3)); + } + ; + +Interface + : + TOK_INTERFACE TOK_IDENTIFIER ';' + { + $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_INTERFACE, NULL, $2); + } + ; + +%% -- cgit v1.2.3