Can invoke methods on general statements and not just variable names.

pull/15/head
Jussi Pakkanen 12 years ago
parent 5e2278d6d4
commit a52336b429
  1. 8
      interpreter.py
  2. 2
      mparser.py
  3. 4
      nodes.py
  4. 3
      test cases/common/38 run program/meson.build

@ -1107,10 +1107,14 @@ class Interpreter():
raise InterpreterException('Unknown method "%s" for a string.' % method_name)
def method_call(self, node):
object_name = node.object_name.get_value()
invokable = node.invokable
if isinstance(invokable, nodes.AtomStatement):
object_name = invokable.get_value()
obj = self.get_variable(object_name)
else:
obj = self.evaluate_statement(invokable)
method_name = node.method_name.get_value()
args = node.arguments
obj = self.get_variable(object_name)
if isinstance(obj, str):
return self.string_method_call(obj, method_name)
if not isinstance(obj, InterpreterObject):

@ -168,7 +168,7 @@ def p_statement_func_call(t):
t[0] = nodes.FunctionCall(t[1], t[3], t[1].lineno())
def p_statement_method_call(t):
'statement : expression DOT expression LPAREN args RPAREN'
'statement : statement DOT expression LPAREN args RPAREN'
t[0] = nodes.MethodCall(t[1], t[3], t[5], t[1].lineno())
def p_statement_if(t):

@ -141,9 +141,9 @@ class FunctionCall(Statement):
return self.func_name.value
class MethodCall(Statement):
def __init__(self, object_name, method_name, arguments, lineno):
def __init__(self, invokable, method_name, arguments, lineno):
Statement.__init__(self, lineno)
self.object_name = object_name
self.invokable = invokable
self.method_name = method_name
self.arguments = arguments

@ -7,8 +7,7 @@ if c.returncode() != 0
error('Executing echo failed.')
endif
result = c.stdout()
result = result.strip()
result = c.stdout().strip()
if result != correct
error('Getting stdout failed.')

Loading…
Cancel
Save