Skip to content

Commit edf77d0

Browse files
committed
Fix constants with colons parsing, evaluating objects in function calls
Soldier: 76 was matching as an annotation, so the order of lexical analysis was modified. Function body is not necessarily a ruleblock, so lines need to be joined by hand.
1 parent 698b9be commit edf77d0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

OWScript/AST.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def __init__(self, name):
3535
super().__init__()
3636
self.name = name
3737

38+
def __eq__(self, other):
39+
return self.name == other.name
40+
41+
def __hash__(self):
42+
return hash(self.__class__.__name__ + self.name)
43+
3844
def __repr__(self):
3945
if not self.children:
4046
return self.name

OWScript/Tokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Tokens:
8383
PVAR : r'PVAR\b'
8484
GVAR : r'GVAR\b'
8585
RULE : r'RULE\b'
86-
ANNOTATION : r'[_a-zA-Z0-9][_a-zA-Z0-9]*:(?!\n)'
8786
OWID : fr'({"|".join(OWID)})(?=[\b\s\n\(\),]+)'
87+
ANNOTATION : r'[_a-zA-Z0-9][_a-zA-Z0-9]*:(?!\n)'
8888
RULEBLOCK : r'(EVENT|CONDITIONS|ACTIONS)\b'
8989
NAME : r'[_a-zA-Z][_\-a-zA-Z0-9]*'
9090
WHITESPACE : r'[ \t]+'

OWScript/Transpiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def visitGlobalVar(self, node):
258258
for scope in self.scopes[::-1]:
259259
if node.name in scope.namespace:
260260
value = scope.namespace.get(node.name)
261-
if value == node:
261+
if type(value) == type(node) and value == node:
262262
continue
263263
result = self.visit(value)
264264
return result
@@ -330,7 +330,7 @@ def visitCall(self, node):
330330
if method == 'append':
331331
try:
332332
assert len(args) == 1
333-
value = node.args[0]
333+
value = self.visit(node.args[0])
334334
self.arrays[callee.parent.name].append(value)
335335
index = self.lookup(callee.parent)
336336
if type(callee.parent) == GlobalVar:
@@ -350,7 +350,7 @@ def visitCall(self, node):
350350
scope = Scope(name=callee.name)
351351
scope.namespace.update(dict(zip(params, node.args)))
352352
self.scopes.append(scope)
353-
code += self.visitChildren(function)
353+
code += (';\n' + self.tabs).join(map(self.visit, function.children))
354354
self.scopes.pop()
355355
else:
356356
try:

0 commit comments

Comments
 (0)