diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2015-08-19 23:34:49 +0300 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2015-08-19 23:34:49 +0300 |
| commit | ee4e785b1ee366249cc2e2217dc54dc7af38ee73 (patch) | |
| tree | 8afd8519422ca097a321488651ae1e4b99b3c8a7 /mparser.py | |
| parent | 60ff47f7361f0a92f4e852e3caa2e1ff5fc31191 (diff) | |
| download | meson-ee4e785b1ee366249cc2e2217dc54dc7af38ee73.tar.gz | |
Add support for subscripting array objects with [].
Diffstat (limited to 'mparser.py')
| -rw-r--r-- | mparser.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/mparser.py b/mparser.py index 83d9cca78..455182a6d 100644 --- a/mparser.py +++ b/mparser.py @@ -210,6 +210,13 @@ class CodeBlockNode: self.colno = colno self.lines = [] +class IndexNode: + def __init__(self, iobject, index): + self.iobject = iobject + self.index = index + self.lineno = iobject.lineno + self.colno = iobject.colno + class MethodNode: def __init__(self, lineno, colno, source_object, name, args): self.lineno = lineno @@ -429,8 +436,15 @@ class Parser: raise ParseException('Function call must be applied to plain id', left.lineno, left.colno) left = FunctionNode(left.lineno, left.colno, left.value, args) - while self.accept('dot'): - left = self.method_call(left) + go_again = True + while go_again: + go_again = False + if self.accept('dot'): + go_again = True + left = self.method_call(left) + if self.accept('lbracket'): + go_again = True + left = self.index_call(left) return left def e8(self): @@ -492,6 +506,11 @@ class Parser: return self.method_call(method) return method + def index_call(self, source_object): + index_statement = self.statement() + self.expect('rbracket') + return IndexNode(source_object, index_statement) + def foreachblock(self): t = self.current self.expect('id') |
