diff --git a/builtin/core.wren b/builtin/core.wren index 8031f8fe..91695011 100644 --- a/builtin/core.wren +++ b/builtin/core.wren @@ -34,9 +34,9 @@ class List is Sequence { return result } - + that { + +(other) { var result = this[0..-1] - for (element in that) { + for (element in other) { result.add(element) } return result diff --git a/src/wren_compiler.c b/src/wren_compiler.c index 80267b06..0844c9e1 100644 --- a/src/wren_compiler.c +++ b/src/wren_compiler.c @@ -1977,7 +1977,9 @@ void infixSignature(Compiler* compiler, char* name, int* length) name[(*length)++] = ' '; // Parse the parameter name. + consume(compiler, TOKEN_LEFT_PAREN, "Expect '(' after operator name."); declareNamedVariable(compiler); + consume(compiler, TOKEN_RIGHT_PAREN, "Expect ')' after parameter name."); } // Compiles a method signature for an unary operator (i.e. "!"). @@ -1990,14 +1992,15 @@ void unarySignature(Compiler* compiler, char* name, int* length) // infix (i.e. "-"). void mixedSignature(Compiler* compiler, char* name, int* length) { - // If there is a parameter name, it's an infix operator, otherwise it's unary. - if (compiler->parser->current.type == TOKEN_NAME) + // If there is a parameter, it's an infix operator, otherwise it's unary. + if (match(compiler, TOKEN_LEFT_PAREN)) { // Add a space for the RHS parameter. name[(*length)++] = ' '; // Parse the parameter name. declareNamedVariable(compiler); + consume(compiler, TOKEN_RIGHT_PAREN, "Expect ')' after parameter name."); } } @@ -2011,7 +2014,9 @@ void namedSignature(Compiler* compiler, char* name, int* length) name[(*length)++] = ' '; // Parse the value parameter. + consume(compiler, TOKEN_LEFT_PAREN, "Expect '(' after '='."); declareNamedVariable(compiler); + consume(compiler, TOKEN_RIGHT_PAREN, "Expect ')' after parameter name."); } else { diff --git a/src/wren_core.c b/src/wren_core.c index d79f0539..3004de07 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -77,9 +77,9 @@ static const char* libSource = " return result\n" " }\n" "\n" -" + that {\n" +" +(other) {\n" " var result = this[0..-1]\n" -" for (element in that) {\n" +" for (element in other) {\n" " result.add(element)\n" " }\n" " return result\n" diff --git a/test/constructor/infix_class_expression.wren b/test/constructor/infix_class_expression.wren index 4274b58c..fc93e135 100644 --- a/test/constructor/infix_class_expression.wren +++ b/test/constructor/infix_class_expression.wren @@ -1,5 +1,5 @@ class Foo { - + other { "Foo " + other } + +(other) { "Foo " + other } } IO.print(new Foo + "value") // expect: Foo value diff --git a/test/implicit_receiver/inherited_methods.wren b/test/implicit_receiver/inherited_methods.wren index c1edbfff..331cec20 100644 --- a/test/implicit_receiver/inherited_methods.wren +++ b/test/implicit_receiver/inherited_methods.wren @@ -3,7 +3,7 @@ class Foo { IO.print("getter") } - setter = value { + setter=(value) { IO.print("setter") } diff --git a/test/implicit_receiver/instance_methods.wren b/test/implicit_receiver/instance_methods.wren index 8092b415..3d32ba30 100644 --- a/test/implicit_receiver/instance_methods.wren +++ b/test/implicit_receiver/instance_methods.wren @@ -3,7 +3,7 @@ class Foo { IO.print("getter") } - setter = value { + setter=(value) { IO.print("setter") } diff --git a/test/implicit_receiver/locals_shadow_setter.wren b/test/implicit_receiver/locals_shadow_setter.wren index 3ca911eb..c5312240 100644 --- a/test/implicit_receiver/locals_shadow_setter.wren +++ b/test/implicit_receiver/locals_shadow_setter.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { + bar=(value) { IO.print("setter") return value } diff --git a/test/implicit_receiver/nested_class.wren b/test/implicit_receiver/nested_class.wren index 1d88e4d8..fc2cc209 100644 --- a/test/implicit_receiver/nested_class.wren +++ b/test/implicit_receiver/nested_class.wren @@ -3,7 +3,7 @@ class Outer { IO.print("outer getter") } - setter = value { + setter=(value) { IO.print("outer setter") } @@ -21,7 +21,7 @@ class Outer { IO.print("inner getter") } - setter = value { + setter=(value) { IO.print("inner setter") } diff --git a/test/implicit_receiver/static_methods.wren b/test/implicit_receiver/static_methods.wren index 3c4594eb..95631ca8 100644 --- a/test/implicit_receiver/static_methods.wren +++ b/test/implicit_receiver/static_methods.wren @@ -3,7 +3,7 @@ class Foo { IO.print("getter") } - static setter = value { + static setter=(value) { IO.print("setter") } diff --git a/test/method/operators.wren b/test/method/operators.wren index c070b455..4e9c6059 100644 --- a/test/method/operators.wren +++ b/test/method/operators.wren @@ -1,17 +1,17 @@ class Foo { - + other { "infix + " + other } - - other { "infix - " + other } - * other { "infix * " + other } - / other { "infix / " + other } - % other { "infix % " + other } - < other { "infix < " + other } - > other { "infix > " + other } - <= other { "infix <= " + other } - >= other { "infix >= " + other } - == other { "infix == " + other } - != other { "infix != " + other } - & other { "infix & " + other } - | other { "infix | " + other } + +(other) { "infix + " + other } + -(other) { "infix - " + other } + *(other) { "infix * " + other } + /(other) { "infix / " + other } + %(other) { "infix % " + other } + <(other) { "infix < " + other } + >(other) { "infix > " + other } + <=(other) { "infix <= " + other } + >=(other) { "infix >= " + other } + ==(other) { "infix == " + other } + !=(other) { "infix != " + other } + &(other) { "infix & " + other } + |(other) { "infix | " + other } ! { "prefix !" } - { "prefix -" } diff --git a/test/setter/associativity.wren b/test/setter/associativity.wren index 3df35eff..2c0e526f 100644 --- a/test/setter/associativity.wren +++ b/test/setter/associativity.wren @@ -1,7 +1,7 @@ class Foo { new(value) { _value = value } toString { _value } - bar = value { + bar=(value) { _value = value return value } diff --git a/test/setter/grouping.wren b/test/setter/grouping.wren index f3c5625c..47fd97b8 100644 --- a/test/setter/grouping.wren +++ b/test/setter/grouping.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { value } + bar=(value) { value } } var foo = new Foo diff --git a/test/setter/infix_operator.wren b/test/setter/infix_operator.wren index aebbd0a6..e694c545 100644 --- a/test/setter/infix_operator.wren +++ b/test/setter/infix_operator.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { value } + bar=(value) { value } } var foo = new Foo diff --git a/test/setter/instance.wren b/test/setter/instance.wren index d61254d7..e2941fab 100644 --- a/test/setter/instance.wren +++ b/test/setter/instance.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { + bar=(value) { IO.print(value) } } diff --git a/test/setter/is.wren b/test/setter/is.wren index 812da466..1797bccb 100644 --- a/test/setter/is.wren +++ b/test/setter/is.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { value } + bar=(value) { value } } var foo = new Foo diff --git a/test/setter/prefix_operator.wren b/test/setter/prefix_operator.wren index 09e48fad..20b80542 100644 --- a/test/setter/prefix_operator.wren +++ b/test/setter/prefix_operator.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { value } + bar=(value) { value } } var foo = new Foo diff --git a/test/setter/result.wren b/test/setter/result.wren index e8db2fa6..ca153aa7 100644 --- a/test/setter/result.wren +++ b/test/setter/result.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { "result" } + bar=(value) { "result" } } var foo = new Foo diff --git a/test/setter/same_name_as_method.wren b/test/setter/same_name_as_method.wren index 82814c0b..c409328a 100644 --- a/test/setter/same_name_as_method.wren +++ b/test/setter/same_name_as_method.wren @@ -1,5 +1,5 @@ class Foo { - bar = value { IO.print("set") } + bar=(value) { IO.print("set") } bar { IO.print("get") } } diff --git a/test/setter/static.wren b/test/setter/static.wren index 157d8847..e0c3850b 100644 --- a/test/setter/static.wren +++ b/test/setter/static.wren @@ -1,5 +1,5 @@ class Foo { - static bar = value { + static bar=(value) { IO.print(value) } }