@@ -24,7 +24,7 @@ namespace Wikimedia\WebIDL;
2424 }
2525}
2626
27- start = _ Definitions
27+ start = _ d: Definitions { return $d; }
2828
2929/* Line number bookkeeping.
3030 * Be careful about backtracking after you successfully match this production.
@@ -53,7 +53,7 @@ identifier = !(ArgumentNameKeyword / BufferRelatedType / OtherIdLike)
5353 s:$( [-_]? [A-Za-z] [-_0-9A-Za-z]* )
5454 // weird special case reserved identifiers:
5555 &{ return $s !== "_constructor" && $s !== "_toString" && $s !== "toString"; }
56- { return $s; }
56+ { return $s[0] == "_" ? substr($s, 1) : $s ; }
5757
5858string = "\"" s:$([^\"]*) "\"" { return $s; }
5959
@@ -70,7 +70,10 @@ _ = ( whitespace / comment )*
7070i_ = ![-_0-9A-Za-z] _
7171
7272/* WebIDL non-terminals */
73- Definitions = (ExtendedAttributeList Definition)*
73+ Definitions = (e:ExtendedAttributeList d:Definition {
74+ $d['extAttrs'] = $e;
75+ return $d;
76+ })*
7477
7578Definition =
7679 CallbackOrInterfaceOrMixin
@@ -109,18 +112,27 @@ ArgumentNameKeyword =
109112 / "unrestricted" ) i_
110113
111114CallbackOrInterfaceOrMixin =
112- "callback" i_ CallbackRestOrInterface
113- / "interface" i_ InterfaceOrMixin
115+ "callback" i_ CallbackRestOrInterface
116+ / "interface" i_ im:InterfaceOrMixin {
117+ $im['type'] = "interface"; return $im;
118+ }
114119InterfaceOrMixin = InterfaceRest / MixinRest
115120InterfaceRest =
116- identifier _ Inheritance "{" _ InterfaceMembers "}" _ ";" _
121+ name:identifier _ inh:Inheritance "{" _ m:InterfaceMembers "}" _ ";" _ {
122+ return [
123+ 'name' => $name,
124+ 'inheritance' => $inh,
125+ 'members' => $m,
126+ 'partial' => false,
127+ ];
128+ }
117129Partial = "partial" i_ PartialDefinition
118130PartialDefinition =
119131 "interface" i_ PartialInterfaceOrPartialMixin
120132 / PartialDictionary
121133 / Namespace
122134PartialInterfaceOrPartialMixin =
123- PartialInterfaceRest
135+ PartialInterfaceRest
124136 / MixinRest
125137PartialInterfaceRest =
126138 identifier _ "{" _ PartialInterfaceMembers "}" _ ";" _
@@ -141,7 +153,9 @@ PartialInterfaceMember =
141153 / ReadWriteMaplike
142154 / ReadWriteSetlike
143155 / InheritAttribute
144- Inheritance = ( ":" _ identifier _ )?
156+ Inheritance =
157+ ( ":" _ name:identifier _ ) { return $name; }
158+ / "" { return null; }
145159MixinRest = "mixin" i_ identifier _ "{" _ MixinMembers "}" _ ";" _
146160MixinMembers = ( ExtendedAttributeList MixinMember )*
147161MixinMember =
@@ -150,8 +164,14 @@ MixinMember =
150164 / Stringifier
151165 / OptionalReadOnly AttributeRest
152166
153- IncludesStatement = identifier _ "includes" i_ identifier _ ";" _
154-
167+ IncludesStatement =
168+ target:identifier _ "includes" i_ incl:identifier _ ";" _ {
169+ return [
170+ 'type' => 'includes',
171+ 'target' => $target,
172+ 'includes' => $incl,
173+ ];
174+ }
155175CallbackRestOrInterface =
156176 CallbackRest
157177 / "interface" i_ identifier _ "{" _ CallbackInterfaceMembers "}" _ ";" _
@@ -247,7 +267,14 @@ SetlikeRest =
247267 "setlike" i_ "<" _ TypeWithExtendedAttributes ">" _ ";" _
248268
249269Namespace =
250- "namespace" i_ identifier _ "{" _ NamespaceMembers "}" _ ";" _
270+ "namespace" i_ name:identifier _ "{" _ m:NamespaceMembers "}" _ ";" _ {
271+ return [
272+ 'type' => 'namespace',
273+ 'name' => $name,
274+ 'partial' => false,
275+ 'members' => $m,
276+ ];
277+ }
251278NamespaceMembers = ( ExtendedAttributeList NamespaceMember )*
252279NamespaceMember =
253280 RegularOperation
@@ -340,13 +367,18 @@ BufferRelatedType =
340367 / "Float64Array" ) i_
341368
342369ExtendedAttributeList =
343- "[" _ ExtendedAttribute ExtendedAttributes "]" _ / !"[" ""
344- ExtendedAttributes = "," _ ExtendedAttribute ExtendedAttributes / ""
370+ "[" _ e:$ExtendedAttribute rest:ExtendedAttributes "]" _
371+ { array_unshift($rest, $e); return $rest; }
372+ / !"[" "" { return []; }
373+ ExtendedAttributes =
374+ "," _ e:$ExtendedAttribute rest:ExtendedAttributes
375+ { array_unshift($rest, $e); return $rest; }
376+ / "" { return []; }
345377ExtendedAttribute =
346378 "(" _ ExtendedAttributeInner ")" _ ExtendedAttributeRest
347379 / "[" _ ExtendedAttributeInner "]" _ ExtendedAttributeRest
348380 / "{" _ ExtendedAttributeInner "}" _ ExtendedAttributeRest
349- / Other ExtendedAttributeRest
381+ / Other+ ExtendedAttributeRest
350382ExtendedAttributeRest = ExtendedAttribute?
351383ExtendedAttributeInner =
352384 "(" _ ExtendedAttributeInner ")" _ ExtendedAttributeInner
0 commit comments