From b86883a7cce7d982c3f0d0069332dd490331e630 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 11 Aug 2015 14:32:54 +0100 Subject: Extend WebIDL parsing to cope with second edition IDL static interface elements --- src/webidl-ast.h | 3 ++ src/webidl-parser.y | 106 ++++++++++++++++++++++++++++++++----- test/data/bindings/browser-duk.bnd | 1 + test/data/idl/urlutils.idl | 65 +++++++++++++++++++++++ 4 files changed, 161 insertions(+), 14 deletions(-) create mode 100644 test/data/idl/urlutils.idl diff --git a/src/webidl-ast.h b/src/webidl-ast.h index 25ef9a0..5126de8 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -63,11 +63,14 @@ enum webidl_type { WEBIDL_TYPE_VOID, }; +/** modifiers for operations, attributes and arguments */ enum webidl_type_modifier { WEBIDL_TYPE_MODIFIER_NONE, WEBIDL_TYPE_MODIFIER_UNSIGNED, WEBIDL_TYPE_MODIFIER_UNRESTRICTED, WEBIDL_TYPE_MODIFIER_READONLY, + WEBIDL_TYPE_MODIFIER_STATIC, /**< operation or attribute is static */ + WEBIDL_TYPE_MODIFIER_INHERIT, /**< attribute inherits */ }; /* the type of special node */ diff --git a/src/webidl-parser.y b/src/webidl-parser.y index 9cfd84e..14385d6 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -150,10 +150,13 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %type CallbackRestOrInterface %type Attribute +%type AttributeRest %type AttributeOrOperation %type StringifierAttributeOrOperation %type Const +%type StaticMember +%type StaticMemberRest %type Operation %type SpecialOperation %type Specials @@ -412,13 +415,15 @@ InterfaceMembers: /* [10] * SE[10] * Second edition actually splits up AttributeOrOperation completely - * here we "just" add Iterable as thats what the specs use + * here we "just" add Iterable and static member as thats what the specs use */ InterfaceMember: Const | AttributeOrOperation | + StaticMember + | Iterable ; @@ -690,28 +695,97 @@ StringifierAttributeOrOperation: } ; - /* [32] */ + /* [32] + * Modified for SE to use AttributeRest + */ Attribute: - Inherit ReadOnly TOK_ATTRIBUTE Type TOK_IDENTIFIER ';' + Inherit ReadOnly AttributeRest { - struct webidl_node *attribute; + struct webidl_node *attribute; - attribute = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, NULL, $5); + attribute = $3; - /* add attributes type */ - attribute = webidl_node_prepend(attribute, $4); + /* deal with inherit modifier */ + if ($1) { + attribute = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, + attribute, + (void *)WEBIDL_TYPE_MODIFIER_INHERIT); + } - /* deal with readonly modifier */ - if ($2) { - attribute = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, attribute, (void *)WEBIDL_TYPE_MODIFIER_READONLY); - } + /* deal with readonly modifier */ + if ($2) { + attribute = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, + attribute, + (void *)WEBIDL_TYPE_MODIFIER_READONLY); + } + + $$ = webidl_node_new(WEBIDL_NODE_TYPE_ATTRIBUTE, + NULL, + attribute); + } + ; + + +/* SE[37] */ +StaticMember: + TOK_STATIC StaticMemberRest + { + $$ = $2; + } + ; + + +/* SE[38] */ +StaticMemberRest: + ReadOnly AttributeRest + { + struct webidl_node *attribute; + + attribute = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, + $2, (void *)WEBIDL_TYPE_MODIFIER_STATIC); + + /* deal with readonly modifier */ + if ($1) { + attribute = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, + attribute, + (void *)WEBIDL_TYPE_MODIFIER_READONLY); + } + + $$ = webidl_node_new(WEBIDL_NODE_TYPE_ATTRIBUTE, + NULL, + attribute); + } + | + ReturnType OperationRest + { + struct webidl_node *operation; + + /* add static modifier */ + operation = webidl_node_new(WEBIDL_NODE_TYPE_MODIFIER, + $2, (void *)WEBIDL_TYPE_MODIFIER_STATIC); + + /* put return type on the operation */ + operation = webidl_node_prepend($1, operation); - $$ = webidl_node_new(WEBIDL_NODE_TYPE_ATTRIBUTE, NULL, attribute); + $$ = webidl_node_new(WEBIDL_NODE_TYPE_OPERATION, + NULL, + operation); + } + ; + + /* SE[42] */ +AttributeRest: + TOK_ATTRIBUTE Type TOK_IDENTIFIER ';' + { + $$ = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, $2, $3); } ; - /* [33] */ + +/* [33] + * SE[45] + */ Inherit: /* empty */ { @@ -724,7 +798,10 @@ Inherit: } ; - /* [34] */ + +/* [34] + * SE[46] + */ ReadOnly: /* empty */ { @@ -737,6 +814,7 @@ ReadOnly: } ; + /* SE[47] */ Operation: ReturnType OperationRest diff --git a/test/data/bindings/browser-duk.bnd b/test/data/bindings/browser-duk.bnd index d0c2c41..44497a1 100644 --- a/test/data/bindings/browser-duk.bnd +++ b/test/data/bindings/browser-duk.bnd @@ -12,6 +12,7 @@ binding duk_libdom { webidl "dom.idl"; webidl "html.idl"; webidl "uievents.idl"; + webidl "urlutils.idl"; webidl "console.idl"; preface diff --git a/test/data/idl/urlutils.idl b/test/data/idl/urlutils.idl new file mode 100644 index 0000000..e79d4ad --- /dev/null +++ b/test/data/idl/urlutils.idl @@ -0,0 +1,65 @@ +// Retrived from https://url.spec.whatwg.org +// Tue Aug 11 12:11:31 BST 2015 +// Removed duplicate IDL from appendix + +[Constructor(USVString url, optional USVString base), + Exposed=(Window,Worker)] +interface URL { + static USVString domainToASCII(USVString domain); + static USVString domainToUnicode(USVString domain); +}; +URL implements URLUtils; +URL implements URLUtilsSearchParams; + +[NoInterfaceObject, + Exposed=(Window,Worker)] +interface URLUtils { + stringifier attribute USVString href; + readonly attribute USVString origin; + + attribute USVString protocol; + attribute USVString username; + attribute USVString password; + attribute USVString host; + attribute USVString hostname; + attribute USVString port; + attribute USVString pathname; + attribute USVString search; + attribute USVString hash; +}; + +[NoInterfaceObject, + Exposed=(Window, Worker)] +interface URLUtilsSearchParams { + attribute URLSearchParams searchParams; +}; + +[NoInterfaceObject, + Exposed=(Window,Worker)] +interface URLUtilsReadOnly { + stringifier readonly attribute USVString href; + readonly attribute USVString origin; + + readonly attribute USVString protocol; + readonly attribute USVString host; + readonly attribute USVString hostname; + readonly attribute USVString port; + readonly attribute USVString pathname; + readonly attribute USVString search; + readonly attribute USVString hash; +}; + +[Constructor(optional (USVString or URLSearchParams) init = ""), + Exposed=(Window,Worker)] +interface URLSearchParams { + void append(USVString name, USVString value); + void delete(USVString name); + USVString? get(USVString name); + sequence getAll(USVString name); + boolean has(USVString name); + void set(USVString name, USVString value); + iterable; + stringifier; +}; + + -- cgit v1.2.3