summaryrefslogtreecommitdiff
path: root/src/nsgenbind-parser.y
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2012-10-23 17:43:09 +0100
committerVincent Sanders <vincent.sanders@collabora.co.uk>2012-10-23 17:43:09 +0100
commitb00346cd08b55d25e427cfabafbaa66e09a8444b (patch)
treee3b6477843762d86698b70fd27fec28b52fc22db /src/nsgenbind-parser.y
parent0c61abc9f71a128c5045738af3489aac743986bd (diff)
downloadnsgenbind-b00346cd08b55d25e427cfabafbaa66e09a8444b.tar.gz
nsgenbind-b00346cd08b55d25e427cfabafbaa66e09a8444b.tar.bz2
The name of teh tool is nsgenbind correct this everywhere
Diffstat (limited to 'src/nsgenbind-parser.y')
-rw-r--r--src/nsgenbind-parser.y228
1 files changed, 228 insertions, 0 deletions
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 <vince@netsurf-browser.org>
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#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 <text> TOK_IDENTIFIER
+%token <text> TOK_STRING_LITERAL
+%token <text> TOK_CCODE_LITERAL
+
+%type <text> CBlock
+
+%type <node> Statement
+%type <node> Statements
+%type <node> IdlFile
+%type <node> Preamble
+%type <node> HdrComment
+%type <node> Strings
+%type <node> Binding
+%type <node> BindingArgs
+%type <node> BindingArg
+%type <node> Type
+%type <node> Private
+%type <node> Interface
+%type <node> 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);
+ }
+ ;
+
+%%