Now parses a lot more.

pull/15/head
Jussi Pakkanen 11 years ago
parent 8c14ead3ed
commit cddb5b7bcb
  1. 21
      parsertest.py

@ -52,7 +52,7 @@ class Lexer:
('lparen', re.compile(r'\(')), ('lparen', re.compile(r'\(')),
('rparen', re.compile(r'\)')), ('rparen', re.compile(r'\)')),
('lbracket', re.compile(r'\[')), ('lbracket', re.compile(r'\[')),
('lbracket', re.compile(r'\]')), ('rbracket', re.compile(r'\]')),
('string', re.compile("'[^']*?'")), ('string', re.compile("'[^']*?'")),
('comma', re.compile(r',')), ('comma', re.compile(r',')),
('dot', re.compile(r'\.')), ('dot', re.compile(r'\.')),
@ -142,6 +142,12 @@ class StringNode:
self.value = token.value self.value = token.value
assert(isinstance(self.value, str)) assert(isinstance(self.value, str))
class ArrayNode:
def __init__(self, args):
self.lineno = args.lineno
self.colno = args.colno
self.args = args
class EmptyNode: class EmptyNode:
def __init__(self): def __init__(self):
self.lineno = 0 self.lineno = 0
@ -351,10 +357,14 @@ class Parser:
return left return left
def e7(self): def e7(self):
if self.accept('('): if self.accept('lparen'):
e = self.expression() e = self.expression()
self.expect(')') self.expect('rparen')
return e return e
elif self.accept('lbracket'):
args = self.args()
self.expect('rbracket')
return ArrayNode(args)
else: else:
return self.e8() return self.e8()
@ -403,7 +413,10 @@ class Parser:
self.expect('lparen') self.expect('lparen')
args = self.args() args = self.args()
self.expect('rparen') 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): def ifblock(self):
condition = self.statement() condition = self.statement()

Loading…
Cancel
Save