From cddb5b7bcb64e530fad5e8940761f62d741957de Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 14 Mar 2014 00:02:44 +0200 Subject: [PATCH] Now parses a lot more. --- parsertest.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/parsertest.py b/parsertest.py index 9e8fdfafb..a933117b1 100755 --- a/parsertest.py +++ b/parsertest.py @@ -52,7 +52,7 @@ class Lexer: ('lparen', re.compile(r'\(')), ('rparen', re.compile(r'\)')), ('lbracket', re.compile(r'\[')), - ('lbracket', re.compile(r'\]')), + ('rbracket', re.compile(r'\]')), ('string', re.compile("'[^']*?'")), ('comma', re.compile(r',')), ('dot', re.compile(r'\.')), @@ -142,6 +142,12 @@ class StringNode: self.value = token.value assert(isinstance(self.value, str)) +class ArrayNode: + def __init__(self, args): + self.lineno = args.lineno + self.colno = args.colno + self.args = args + class EmptyNode: def __init__(self): self.lineno = 0 @@ -351,10 +357,14 @@ class Parser: return left def e7(self): - if self.accept('('): + if self.accept('lparen'): e = self.expression() - self.expect(')') + self.expect('rparen') return e + elif self.accept('lbracket'): + args = self.args() + self.expect('rbracket') + return ArrayNode(args) else: return self.e8() @@ -403,7 +413,10 @@ class Parser: self.expect('lparen') args = self.args() self.expect('rparen') - return MethodNode(methodname.lineno, methodname.colno, source_object, methodname.value, args) + method = MethodNode(methodname.lineno, methodname.colno, source_object, methodname.value, args) + if self.accept('dot'): + return self.method_call(method) + return method def ifblock(self): condition = self.statement()