wrong precedence fixed

This commit is contained in:
prod2 2022-12-03 13:11:46 +01:00
parent 41e21733d3
commit c812d33a77
1 changed files with 8 additions and 10 deletions

View File

@ -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()