add key: val syntax to tables, update tests to match replacement of -> with :
This commit is contained in:
parent
c812d33a77
commit
3a73ed75ec
|
@ -151,7 +151,7 @@ proc parseTable(parser: Parser): Node =
|
||||||
result.keys.add(Node(kind: nkConst, constant: parser.previous.get().text.fromNimString(), line: parser.line))
|
result.keys.add(Node(kind: nkConst, constant: parser.previous.get().text.fromNimString(), line: parser.line))
|
||||||
else:
|
else:
|
||||||
parser.errorAtCurrent("Key expected (have you forgotten to put the key in brackets?).")
|
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())
|
result.values.add(parser.exprNonAssign())
|
||||||
if parser.peek().tokenType != tkRightBrace and not parser.consume(tkComma, "',' expected after table key value pair."):
|
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'.")
|
discard parser.consume(tkLeftParen, "'(' expected after 'proc'.")
|
||||||
return parser.parseProcDeclaration()
|
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] =
|
proc parseArgList(parser: Parser): seq[Node] =
|
||||||
# once ( has been consumed, consume args and the ) or just a )
|
# once ( has been consumed, consume args and the ) or just a )
|
||||||
|
|
|
@ -53,14 +53,15 @@ var mix = @{
|
||||||
print(mix.ident, mix["ident2"], mix[3], mix.ident4);
|
print(mix.ident, mix["ident2"], mix[3], mix.ident4);
|
||||||
//expect:5.0 6.0 7.0 8.0
|
//expect:5.0 6.0 7.0 8.0
|
||||||
|
|
||||||
// -> method call syntax
|
// : method call syntax
|
||||||
|
// formerly ->
|
||||||
|
|
||||||
var class = @{
|
var class = @{
|
||||||
method = proc(self) print ("i was called")
|
method = proc(self) print ("i was called")
|
||||||
};
|
};
|
||||||
|
|
||||||
// no args needed then no parentheses needed
|
// no args needed then no parentheses needed
|
||||||
class->method;
|
class:method;
|
||||||
//expect:i was called
|
//expect:i was called
|
||||||
|
|
||||||
var multiplier = @{
|
var multiplier = @{
|
||||||
|
@ -68,7 +69,7 @@ var multiplier = @{
|
||||||
do = proc(self, arg) self.multiple * arg,
|
do = proc(self, arg) self.multiple * arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
multiplier->do(7) :: print;
|
multiplier:do(7) :: print;
|
||||||
//expect:35.0
|
//expect:35.0
|
||||||
|
|
||||||
// -> method call syntax with :: - check for precedence
|
// -> method call syntax with :: - check for precedence
|
||||||
|
@ -77,7 +78,7 @@ var returner = @{
|
||||||
method = proc(self) proc(n) n * 2
|
method = proc(self) proc(n) n * 2
|
||||||
};
|
};
|
||||||
|
|
||||||
1.7 :: returner->method :: print;
|
1.7 :: returner:method :: print;
|
||||||
//expect:3.4
|
//expect:3.4
|
||||||
|
|
||||||
print("finish");
|
print("finish");
|
||||||
|
|
Loading…
Reference in New Issue