wrong precedence fixed
This commit is contained in:
parent
41e21733d3
commit
c812d33a77
|
@ -244,10 +244,11 @@ proc parseArgList(parser: Parser): seq[Node] =
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
proc parseIndex(parser: Parser): Node =
|
proc parseIndexOrCall(parser: Parser): Node =
|
||||||
|
# parses calls and indexes
|
||||||
result = parser.primary()
|
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
|
# NOTE: :index is counted as a single identifier, so two identifiers after eachother will be handled here
|
||||||
if parser.previous.get().tokenType == tkLeftBracket:
|
if parser.previous.get().tokenType == tkLeftBracket:
|
||||||
let index = parser.expression()
|
let index = parser.expression()
|
||||||
|
@ -267,19 +268,16 @@ proc parseIndex(parser: Parser): Node =
|
||||||
args = parser.parseArgList()
|
args = parser.parseArgList()
|
||||||
let funct = Node(kind: nkGetIndex, gCollection: result, gIndex: ident, line: parser.line)
|
let funct = Node(kind: nkGetIndex, gCollection: result, gIndex: ident, line: parser.line)
|
||||||
result = Node(kind: nkColonCall, arguments: args, function: funct, 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:
|
else:
|
||||||
# dot
|
# dot
|
||||||
if not parser.consume(tkIdentifier, "Identifier expected after '.' index operator."):
|
if not parser.consume(tkIdentifier, "Identifier expected after '.' index operator."):
|
||||||
break
|
break
|
||||||
result = Node(kind: nkGetIndex, gCollection: result, gIndex: Node(kind: nkConst, constant: parser.previous.get().text.fromNimString()), line: parser.line)
|
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 =
|
proc parseIf(parser: Parser): Node =
|
||||||
discard parser.consume(tkLeftParen, "'(' expected after 'if'.")
|
discard parser.consume(tkLeftParen, "'(' expected after 'if'.")
|
||||||
let cond = parser.expression()
|
let cond = parser.expression()
|
||||||
|
@ -319,7 +317,7 @@ proc unary(parser: Parser): Node =
|
||||||
return parser.parseWhile()
|
return parser.parseWhile()
|
||||||
else:
|
else:
|
||||||
parser.errorAtCurrent("Invalid parser state: unaryOps and case statement out of line.")
|
parser.errorAtCurrent("Invalid parser state: unaryOps and case statement out of line.")
|
||||||
return parser.parseCall()
|
return parser.parseIndexOrCall()
|
||||||
|
|
||||||
proc factor(parser: Parser): Node =
|
proc factor(parser: Parser): Node =
|
||||||
result = parser.unary()
|
result = parser.unary()
|
||||||
|
|
Loading…
Reference in New Issue