From 6ba84a0f507270fba8e7a68901dc256c2979d7f9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 14 Dec 2018 17:49:36 -0800 Subject: Initial setup work for syntax version 5. --- syntax_tree.moon | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'syntax_tree.moon') diff --git a/syntax_tree.moon b/syntax_tree.moon index 71b9bac..e2bbb4e 100644 --- a/syntax_tree.moon +++ b/syntax_tree.moon @@ -29,7 +29,6 @@ class SyntaxTree return false if type(@) != type(other) or #@ != #other or getmetatable(@) != getmetatable(other) for i=1,#@ return false if @[i] != other[i] - return false if @target != other.target return true as_lua: => @@ -74,13 +73,20 @@ class SyntaxTree return replacement get_args: => - assert(@type == "Action", "Only actions have arguments") - args = {@target} - for tok in *@ - if type(tok) != 'string' then args[#args+1] = tok + assert(@type == "Action" or @type == "MethodCall", "Only actions and method calls have arguments") + args = {} + if @type == "MethodCall" + args[1] = @[1] + for tok in *@[2] + if type(tok) != 'string' then args[#args+1] = tok + else + for tok in *@ + if type(tok) != 'string' then args[#args+1] = tok return args get_stub: => + if @type == "MethodCall" + return @[2]\get_stub! stub_bits = {} arg_i = 1 for a in *@ @@ -103,6 +109,8 @@ getmetatable(SyntaxTree).__call = (t)=> setmetatable(t, @__base) if t.type == 'Action' t.stub = t\get_stub! + elseif t.type == 'MethodCall' + t.stub = t[2]\get_stub! return t return SyntaxTree -- cgit v1.2.3