diff --git a/src/PASTGrammar.tg b/src/PASTGrammar.tg index 2ebf819..930d952 100644 --- a/src/PASTGrammar.tg +++ b/src/PASTGrammar.tg @@ -681,8 +681,13 @@ transform past (Lua::Grammar::simple_expression) :language('PIR') { transform past (Lua::Grammar::primary_expression) :language('PIR') { + .local pmc source, pos + .local int line .local pmc past $P0 = node['prefix_expression'] + source = getattribute $P0, '$.target' + pos = $P0.'from'() + line = source.'lineof'(pos) past = tree.'get'('past', $P0, 'Lua::Grammar::prefix_expression') $P0 = node['slice_expression'] if null $P0 goto L1 @@ -694,8 +699,22 @@ transform past (Lua::Grammar::primary_expression) :language('PIR') { $P1 = $P0['function_args'] if null $P1 goto L3 args = tree.'get'('explist', $P1, 'Lua::Grammar::function_args') + $P2 = $P1['expression_list'] + if null $P2 goto L9 + source = getattribute $P1, '$.target' + pos = $P1.'from'() + $I1 = source.'lineof'(pos) + if line == $I1 goto L9 + $P2 = get_hll_global [ 'Lua';'Grammar' ], 'syntaxerror' + $P2($P1, 'ambiguous syntax (function call x new statement)') + L9: + pos = $P1.'to'() + line = source.'lineof'(pos) $P1 = $P0['Name'] if null $P1 goto L4 + source = getattribute $P1, '$.target' + pos = $P1.'from'() + line = source.'lineof'(pos) .local pmc meth, obj key = tree.'get'('key', $P1, 'Lua::Grammar::Name') $P2 = get_hll_global ['PAST'], 'Var' @@ -711,6 +730,9 @@ transform past (Lua::Grammar::primary_expression) :language('PIR') { L3: $P1 = $P0['Name'] if null $P1 goto L5 + source = getattribute $P1, '$.target' + pos = $P1.'from'() + line = source.'lineof'(pos) key = tree.'get'('key', $P1, 'Lua::Grammar::Name') $P2 = get_hll_global ['PAST'], 'Var' past = $P2.'new'(past, key, 'node'=>node, 'scope'=>'keyed') @@ -718,6 +740,9 @@ transform past (Lua::Grammar::primary_expression) :language('PIR') { L5: $P1 = $P0['index'] if null $P1 goto L6 + source = getattribute $P1, '$.target' + pos = $P1.'to'() + line = source.'lineof'(pos) key = tree.'get'('key', $P1, 'Lua::Grammar::index') $P2 = get_hll_global ['PAST'], 'Var' past = $P2.'new'(past, key, 'node'=>node, 'scope'=>'keyed') diff --git a/t/function.t b/t/function.t index 83166f1..4eda19c 100644 --- a/t/function.t +++ b/t/function.t @@ -281,7 +281,7 @@ CODE 2 OUT -language_output_like( 'lua', <<'CODE', <<'OUT', 'ambiguous' , todo => 'ambigous function call'); +language_output_like( 'lua', <<'CODE', <<'OUT', 'ambiguous' ); a = f (g).x(a) CODE