From d36c21c4f53270f9ba8137bb1e84a7de45fea0f3 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 22 Jul 2015 22:12:05 +0100 Subject: Load the WebIDL files specified in the binding This loads the WebIDL specified in the bindings into an Abstract Syntax Tree (AST) and performs the mixin operations for implements. Additionally the specs now use a slightly extended IDL syntax. Instead of wholesale implementing the second edition of the IDL spec the parser has been updated to cope with iterator and Promise keywords as those are the only changes used in the dom and html specifications. A bug was also fixed in the lexer where negative int literals were not recognised. --- src/webidl-parser.y | 104 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 15 deletions(-) (limited to 'src/webidl-parser.y') diff --git a/src/webidl-parser.y b/src/webidl-parser.y index 9324212..9717b8c 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -9,6 +9,9 @@ * * Derived from the the grammar in apendix A of W3C WEB IDL * http://www.w3.org/TR/WebIDL/ + * + * WebIDL now has a second edition draft (mid 2015) that the dom and + * html specs are using. https://heycam.github.io/webidl */ #include @@ -17,11 +20,17 @@ #include #include -#include "webidl-ast.h" +#define YYFPRINTF webidl_fprintf +#define YY_LOCATION_PRINT(File, Loc) \ + webidl_fprintf(File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) #include "webidl-parser.h" #include "webidl-lexer.h" +#include "webidl-ast.h" + char *errtxt; static void @@ -77,6 +86,8 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %token TOK_INFINITY %token TOK_INHERIT %token TOK_INTERFACE +%token TOK_ITERABLE +%token TOK_LEGACYITERABLE %token TOK_LONG %token TOK_MODULE %token TOK_NAN @@ -88,6 +99,7 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %token TOK_OPTIONAL %token TOK_OR %token TOK_PARTIAL +%token TOK_PROMISE %token TOK_RAISES %token TOK_READONLY %token TOK_SETRAISES @@ -105,12 +117,12 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %token TOK_POUND_SIGN -%token TOK_IDENTIFIER -%token TOK_INT_LITERAL -%token TOK_FLOAT_LITERAL -%token TOK_STRING_LITERAL -%token TOK_OTHER_LITERAL -%token TOK_JAVADOC +%token TOK_IDENTIFIER +%token TOK_INT_LITERAL +%token TOK_FLOAT_LITERAL +%token TOK_STRING_LITERAL +%token TOK_OTHER_LITERAL +%token TOK_JAVADOC %type Inheritance @@ -153,6 +165,8 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %type ArgumentName %type ArgumentNameKeyword %type Ellipsis +%type Iterable +%type OptionalType %type Type %type ReturnType @@ -165,6 +179,7 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %type FloatType %type UnsignedIntegerType %type IntegerType +%type PromiseType %type TypeSuffix %type TypeSuffixStartingWithArray @@ -356,7 +371,7 @@ InterfaceMembers: if (ident_node == NULL) { /* something with no ident - possibly constructors? */ - /* @todo understand this abtter */ + /* @todo understand this better */ $$ = webidl_node_prepend($1, $3); @@ -389,11 +404,17 @@ InterfaceMembers: } ; - /* [10] */ + /* [10] + * SE[10] + * Second edition actually splits up AttributeOrOperation completely + * here we "just" add Iterable as thats what the specs use + */ InterfaceMember: Const | AttributeOrOperation + | + Iterable ; /* [11] */ @@ -474,18 +495,28 @@ Enum: } ; -/* [21] */ + /* Second edition changes enumeration rules to allow trailing comma */ + + /* SE[20] */ EnumValueList: - TOK_STRING_LITERAL EnumValues + TOK_STRING_LITERAL EnumValueListComma ; -/* [22] */ -EnumValues: + /* SE[21] */ +EnumValueListComma: + ',' EnumValueListString + | /* empty */ + ; + + /* SE[22] */ +EnumValueListString: + TOK_STRING_LITERAL EnumValueListComma | - ',' TOK_STRING_LITERAL EnumValues + /* empty */ ; + /* [23] - bug in w3c grammar? it doesnt list the equals as a terminal */ CallbackRest: TOK_IDENTIFIER '=' ReturnType '(' ArgumentList ')' ';' @@ -835,6 +866,32 @@ Ellipsis: } ; + /* SE[59] */ +Iterable: + TOK_ITERABLE '<' Type OptionalType '>' ';' + { + $$ = NULL; + } + | + TOK_LEGACYITERABLE '<' Type '>' ';' + { + $$ = NULL; + } + ; + + /* SE[60] */ +OptionalType: + /* empty */ + { + $$ = NULL; + } + | + ',' Type + { + $$ = NULL; + } + ; + /* [47] */ ExceptionMember: Const @@ -1301,13 +1358,22 @@ UnionMemberTypes: TOK_OR UnionMemberType UnionMemberTypes ; - /* [62] */ + /* [62] + * SE[78] + * Second edition adds several types + */ NonAnyType: PrimitiveType TypeSuffix { $$ = webidl_node_prepend($1, $2); } | + PromiseType TypeSuffix + { + /* second edition adds promise types */ + $$ = webidl_node_prepend($1, $2); + } + | TOK_STRING TypeSuffix { $$ = webidl_node_new(WEBIDL_NODE_TYPE_TYPE_BASE, $2, (void *)WEBIDL_TYPE_STRING); @@ -1442,6 +1508,14 @@ OptionalLong: } ; +/* SE[87] */ +PromiseType: + TOK_PROMISE '<' ReturnType '>' + { + $$ = NULL; + } + ; + /* [70] */ TypeSuffix: /* empty */ -- cgit v1.2.3