From 47a77d771a0a4c1b9eb037ed6cc861e67000e8dd Mon Sep 17 00:00:00 2001 From: "elias.oelschner" Date: Fri, 16 Jan 2026 13:58:18 +0100 Subject: [PATCH] Fix function call parsing and add test --- src/prometheus/parser.lua | 14 ++++++++++++++ tests/ambiguous-call.lua | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/ambiguous-call.lua diff --git a/src/prometheus/parser.lua b/src/prometheus/parser.lua index 1594b2f..10cdd5f 100644 --- a/src/prometheus/parser.lua +++ b/src/prometheus/parser.lua @@ -38,6 +38,13 @@ local ASSIGNMENT_NO_WARN_LOOKUP = lookupify{ AstKind.VarargExpression }; +local CALLABLE_PREFIX_EXPRESSION_LOOKUP = lookupify{ + AstKind.VariableExpression, + AstKind.IndexExpression, + AstKind.FunctionCallExpression, + AstKind.PassSelfFunctionCallExpression +}; + local function generateError(self, message) local token; if(self.index > self.length) then @@ -782,6 +789,10 @@ end function Parser:expressionFunctionCall(scope, base) base = base or self:expressionIndex(scope); + + if(not (base and (CALLABLE_PREFIX_EXPRESSION_LOOKUP[base.kind] or base.isParenthesizedExpression))) then + return base; + end -- Normal Function Call local args = {}; @@ -887,6 +898,9 @@ function Parser:expressionLiteral(scope) if(consume(self, TokenKind.Symbol, "(")) then local expr = self:expression(scope); expect(self, TokenKind.Symbol, ")"); + if expr then + expr.isParenthesizedExpression = true; + end return expr; end diff --git a/tests/ambiguous-call.lua b/tests/ambiguous-call.lua new file mode 100644 index 0000000..38a08b2 --- /dev/null +++ b/tests/ambiguous-call.lua @@ -0,0 +1,8 @@ +-- Reproduction for issue #203 where the parser misreads the following +-- as arguments to the previous literal assignment. +local counter = 1 + +(function() + counter = counter + 1 + print("counter:", counter) +end)();