From c812d33a7790401131141d5a64b68672b139fed9 Mon Sep 17 00:00:00 2001 From: prod2 <95874442+prod2@users.noreply.github.com> Date: Sat, 3 Dec 2022 13:11:46 +0100 Subject: [PATCH] wrong precedence fixed --- src/ndspkg/compv2/parser.nim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ndspkg/compv2/parser.nim b/src/ndspkg/compv2/parser.nim index dacf8e9..2a4ec34 100644 --- a/src/ndspkg/compv2/parser.nim +++ b/src/ndspkg/compv2/parser.nim @@ -244,10 +244,11 @@ proc parseArgList(parser: Parser): seq[Node] = return args -proc parseIndex(parser: Parser): Node = +proc parseIndexOrCall(parser: Parser): Node = + # parses calls and indexes result = parser.primary() - while parser.match({tkLeftBracket, tkDot, tkIdentifier}): + while parser.match({tkLeftBracket, tkDot, tkIdentifier, tkLeftParen}): # NOTE: :index is counted as a single identifier, so two identifiers after eachother will be handled here if parser.previous.get().tokenType == tkLeftBracket: let index = parser.expression() @@ -267,19 +268,16 @@ proc parseIndex(parser: Parser): Node = args = parser.parseArgList() let funct = Node(kind: nkGetIndex, gCollection: result, gIndex: ident, line: parser.line) result = Node(kind: nkColonCall, arguments: args, function: funct, line: parser.line) + elif parser.previous.get().tokenType == tkLeftParen: + # call + let args = parser.parseArgList() + result = Node(kind: nkCall, arguments: args, function: result, line: parser.line) else: # dot if not parser.consume(tkIdentifier, "Identifier expected after '.' index operator."): break result = Node(kind: nkGetIndex, gCollection: result, gIndex: Node(kind: nkConst, constant: parser.previous.get().text.fromNimString()), line: parser.line) -proc parseCall(parser: Parser): Node = - result = parser.parseIndex() - if parser.match(tkLeftParen): - let args = parser.parseArgList() - result = Node(kind: nkCall, arguments: args, function: result, line: parser.line) - - proc parseIf(parser: Parser): Node = discard parser.consume(tkLeftParen, "'(' expected after 'if'.") let cond = parser.expression() @@ -319,7 +317,7 @@ proc unary(parser: Parser): Node = return parser.parseWhile() else: parser.errorAtCurrent("Invalid parser state: unaryOps and case statement out of line.") - return parser.parseCall() + return parser.parseIndexOrCall() proc factor(parser: Parser): Node = result = parser.unary()