aboutsummaryrefslogtreecommitdiff
path: root/mparser.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-11-05 20:38:35 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2014-11-05 20:38:35 +0200
commitb44ca46e92c5d48de825f1f1e5b1b042461448ef (patch)
treefc3a566c22ec97f033708e0c0a51050009c5733f /mparser.py
parent0c86f30d4bd1fa53df139dd3a182381477a1fc12 (diff)
downloadmeson-b44ca46e92c5d48de825f1f1e5b1b042461448ef.zip
meson-b44ca46e92c5d48de825f1f1e5b1b042461448ef.tar.gz
meson-b44ca46e92c5d48de825f1f1e5b1b042461448ef.tar.bz2
Implement a foreach loop construct. Closes #17.
Diffstat (limited to 'mparser.py')
-rw-r--r--mparser.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/mparser.py b/mparser.py
index d0058ac..e85a154 100644
--- a/mparser.py
+++ b/mparser.py
@@ -17,6 +17,8 @@
import re
import sys
from coredata import MesonException
+from array import array
+from orca.messages import itemsFound
class ParseException(MesonException):
def __init__(self, text, lineno, colno):
@@ -39,7 +41,7 @@ class Token:
class Lexer:
def __init__(self):
self.keywords = {'true', 'false', 'if', 'else', 'elif',
- 'endif', 'and', 'or', 'not'}
+ 'endif', 'and', 'or', 'not', 'foreach', 'endforeach'}
self.token_specification = [
# Need to be sorted longest to shortest.
('ignore', re.compile(r'[ \t]')),
@@ -214,6 +216,14 @@ class AssignmentNode:
assert(isinstance(var_name, str))
self.value = value
+class ForeachClauseNode():
+ def __init__(self, lineno, colno, varname, items, block):
+ self.lineno = lineno
+ self.colno = colno
+ self.varname = varname
+ self.items = items
+ self.block = block
+
class IfClauseNode():
def __init__(self, lineno, colno):
self.lineno = lineno
@@ -417,6 +427,15 @@ class Parser:
return self.method_call(method)
return method
+ def foreachblock(self):
+ t = self.current
+ self.expect('id')
+ varname = t
+ self.expect('colon')
+ items = self.statement()
+ block = self.codeblock()
+ return ForeachClauseNode(varname.lineno, varname.colno, varname, items, block)
+
def ifblock(self):
condition = self.statement()
clause = IfClauseNode(condition.lineno, condition.colno)
@@ -445,6 +464,10 @@ class Parser:
block = self.ifblock()
self.expect('endif')
return block
+ if self.accept('foreach'):
+ block = self.foreachblock()
+ self.expect('endforeach')
+ return block
return self.statement()
def codeblock(self):