From 3a73ed75ecaa9a6ce62d8686ca5c148481eaeef3 Mon Sep 17 00:00:00 2001 From: prod2 <95874442+prod2@users.noreply.github.com> Date: Sat, 3 Dec 2022 13:16:47 +0100 Subject: [PATCH] add key: val syntax to tables, update tests to match replacement of -> with : --- src/ndspkg/compv2/parser.nim | 5 +++-- tests/sugar.nds | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ndspkg/compv2/parser.nim b/src/ndspkg/compv2/parser.nim index 2a4ec34..0a3271d 100644 --- a/src/ndspkg/compv2/parser.nim +++ b/src/ndspkg/compv2/parser.nim @@ -151,7 +151,7 @@ proc parseTable(parser: Parser): Node = result.keys.add(Node(kind: nkConst, constant: parser.previous.get().text.fromNimString(), line: parser.line)) else: parser.errorAtCurrent("Key expected (have you forgotten to put the key in brackets?).") - discard parser.consume(tkEqual, "'=' expected after key.") + discard parser.consume({tkEqual, tkColon}, "'=' expected after key.") result.values.add(parser.exprNonAssign()) if parser.peek().tokenType != tkRightBrace and not parser.consume(tkComma, "',' expected after table key value pair."): @@ -230,7 +230,8 @@ proc primary(parser: Parser): Node = discard parser.consume(tkLeftParen, "'(' expected after 'proc'.") return parser.parseProcDeclaration() - parser.errorAtCurrent("Primary expected, but something else found.") + parser.errorAtCurrent(&"Primary expected, but found: {parser.current.tokenType}.") + parser.advance() # to always go forward if a completely unknown symbol is found proc parseArgList(parser: Parser): seq[Node] = # once ( has been consumed, consume args and the ) or just a ) diff --git a/tests/sugar.nds b/tests/sugar.nds index 7cd2663..619f4ba 100644 --- a/tests/sugar.nds +++ b/tests/sugar.nds @@ -53,14 +53,15 @@ var mix = @{ print(mix.ident, mix["ident2"], mix[3], mix.ident4); //expect:5.0 6.0 7.0 8.0 -// -> method call syntax +// : method call syntax +// formerly -> var class = @{ method = proc(self) print ("i was called") }; // no args needed then no parentheses needed -class->method; +class:method; //expect:i was called var multiplier = @{ @@ -68,7 +69,7 @@ var multiplier = @{ do = proc(self, arg) self.multiple * arg, }; -multiplier->do(7) :: print; +multiplier:do(7) :: print; //expect:35.0 // -> method call syntax with :: - check for precedence @@ -77,7 +78,7 @@ var returner = @{ method = proc(self) proc(n) n * 2 }; -1.7 :: returner->method :: print; +1.7 :: returner:method :: print; //expect:3.4 print("finish");