Skip to content

Commit

Permalink
Update widlparser. Fixes #1513, closes #1514.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Sep 5, 2019
1 parent f7860c0 commit 5084c5b
Show file tree
Hide file tree
Showing 11 changed files with 1,048 additions and 117 deletions.
17 changes: 17 additions & 0 deletions bikeshed/widlparser/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Contributing to widlparser
==========================

All contributions are welcome!


Testing
-------

To ensure that there are no unexpected changes, compare the output of `test.py`:

./test.py | diff -u test-expected.txt -

If all changes are expected, include them in your pull request:

./test.py > test-expected.txt
git add test-expected.txt
773 changes: 773 additions & 0 deletions bikeshed/widlparser/test-expected.txt

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions bikeshed/widlparser/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
#

import sys
import itertools
import cgi
import codecs
import itertools
import sys

from widlparser import parser

Expand Down Expand Up @@ -131,6 +132,7 @@ def test_difference(input, output):

if __name__ == "__main__": # called from the command line
sys.excepthook = debugHook
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
parser = parser.Parser(ui=ui())

if (1 < len(sys.argv)):
Expand Down Expand Up @@ -222,13 +224,18 @@ def test_difference(input, output):
void anotherMethod(short round);
[ha!] attribute short bar getraises (an, exception);
const short fortyTwo = 42;
long foo(long x, long y);
attribute long async;
long foo(long x, long y, long async);
void bar(any constructor);
long includes();
}
[ NoInterfaceObject , MapClass (short, Foo )] interface LinkStyle {
constructor();
constructor(int x);
stringifier attribute DOMString mediaText;
readonly attribute [Extended] short bar;
readonly attribute [Extended] short bar ;
getter object (DOMString name);
getter setter object bob(DOMString name);
getter setter object bob (DOMString name);
stringifier foo me(int x);
stringifier foo ();
stringifier;
Expand Down Expand Up @@ -372,5 +379,5 @@ def test_difference(input, output):
print(', '.join(parser.normalizedMethodNames('method()', 'Foo')))
print(', '.join(parser.normalizedMethodNames('method(x)', 'Foo')))
print(', '.join(parser.normalizedMethodNames('method(x, y)', 'Foo')))
print(', '.join(parser.normalizedMethodNames('method(x, y, bar)', 'Foo')))
print(', '.join(parser.normalizedMethodNames('method (x, y, bar)', 'Foo')))
print(', '.join(parser.normalizedMethodNames('abort()', 'Foo')))
18 changes: 10 additions & 8 deletions bikeshed/widlparser/widlparser/constructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,28 +336,30 @@ def __repr__(self):
return output + ((' [default: ' + repr(self.default) + ']]') if (self.default) else ']')


class InterfaceMember(Construct): # [ExtendedAttributes] Const | Operation | SpecialOperation | Stringifier | StaticMember | AsyncIterable | Iterable | Attribute | Maplike | Setlike
class InterfaceMember(Construct): # [ExtendedAttributes] Constructor | Const | Operation | SpecialOperation | Stringifier | StaticMember | AsyncIterable | Iterable | Attribute | Maplike | Setlike
@classmethod
def peek(cls, tokens):
tokens.pushPosition(False)
Construct.peek(tokens)
return tokens.popPosition(Const.peek(tokens) or
return tokens.popPosition(Constructor.peek(tokens) or Const.peek(tokens) or
Stringifier.peek(tokens) or StaticMember.peek(tokens) or
AsyncIterable.peek(tokens) or Iterable.peek(tokens) or
Maplike.peek(tokens) or Setlike.peek(tokens) or
Attribute.peek(tokens) or
AsyncIterable.peek(tokens) or Iterable.peek(tokens) or
Maplike.peek(tokens) or Setlike.peek(tokens) or
Attribute.peek(tokens) or
SpecialOperation.peek(tokens) or Operation.peek(tokens))

def __init__(self, tokens, parent):
Construct.__init__(self, tokens, parent)
if (Const.peek(tokens)):
if (Constructor.peek(tokens)):
self.member = Constructor(tokens, parent)
elif (Const.peek(tokens)):
self.member = Const(tokens, parent)
elif (Stringifier.peek(tokens)):
self.member = Stringifier(tokens, parent)
elif (StaticMember.peek(tokens)):
self.member = StaticMember(tokens, parent)
elif (AsyncIterable.peek(tokens)):
self.member = AsyncIterable(tokens, parent)
elif (AsyncIterable.peek(tokens)):
self.member = AsyncIterable(tokens, parent)
elif (Iterable.peek(tokens)):
self.member = Iterable(tokens, parent)
elif (Maplike.peek(tokens)):
Expand Down
8 changes: 4 additions & 4 deletions bikeshed/widlparser/widlparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ def normalizedMethodName(self, methodText, interfaceName = None):
tokens = tokenizer.Tokenizer(match.group(2))
if (ArgumentList.peek(tokens)):
arguments = ArgumentList(tokens, None)
return match.group(1) + '(' + arguments.argumentNames[0] + ')'
name = match.group(1) + match.group(3)
return match.group(1).strip() + '(' + arguments.argumentNames[0] + ')'
name = match.group(1).strip() + match.group(3)
argumentNames = [argument.strip() for argument in match.group(2).split(',')]
else:
name = methodText
Expand Down Expand Up @@ -247,8 +247,8 @@ def normalizedMethodNames(self, methodText, interfaceName = None):
tokens = tokenizer.Tokenizer(match.group(2))
if (ArgumentList.peek(tokens)):
arguments = ArgumentList(tokens, None)
return [match.group(1) + '(' + argumentName + ')' for argumentName in arguments.argumentNames]
name = match.group(1) + match.group(3)
return [match.group(1).strip() + '(' + argumentName + ')' for argumentName in arguments.argumentNames]
name = match.group(1).strip() + match.group(3)
argumentNames = [argument.strip() for argument in match.group(2).split(',')]
else:
name = methodText
Expand Down
Loading

0 comments on commit 5084c5b

Please sign in to comment.