From 3c475f01ee87f732ec2f56b45c141346feeba2d6 Mon Sep 17 00:00:00 2001 From: ruby0x1 Date: Sat, 19 Sep 2020 22:03:16 -0700 Subject: [PATCH] allow newline before dot for subscript as well, and add to tests --- src/vm/wren_compiler.c | 2 + test/language/chained_newline.wren | 127 +++++++++++++++++++---------- 2 files changed, 84 insertions(+), 45 deletions(-) diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 856ce0f04..2a43dac3b 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -2378,6 +2378,8 @@ static void subscript(Compiler* compiler, bool canAssign) finishArgumentList(compiler, &signature); consume(compiler, TOKEN_RIGHT_BRACKET, "Expect ']' after arguments."); + allowLineBeforeDot(compiler); + if (canAssign && match(compiler, TOKEN_EQ)) { signature.type = SIG_SUBSCRIPT_SETTER; diff --git a/test/language/chained_newline.wren b/test/language/chained_newline.wren index 72dcbae1b..bd1aaf847 100644 --- a/test/language/chained_newline.wren +++ b/test/language/chained_newline.wren @@ -12,6 +12,11 @@ class Test { System.print("test2") return this } + + [index] { + System.print("testSubscript") + return this + } } class Tester { @@ -22,36 +27,48 @@ class Tester { //test local access test. - test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 test - .test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + .test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 test - .test0() // expect: test0 - .test1(). // expect: test1 - test2() // expect: test2 + .test0() // expect: test0 + .test1(). // expect: test1 + test2() // expect: test2 + + test[0] // expect: testSubscript + .test0() // expect: test0 + + test[0]. // expect: testSubscript + test0() // expect: test0 //test field access _test. - test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 _test - .test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + .test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 _test - .test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + .test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 + + _test[0] // expect: testSubscript + .test0() // expect: test0 + + _test[0]. // expect: testSubscript + test0() // expect: test0 } @@ -65,50 +82,70 @@ class Tester { var external = Tester.new() external.getter. - test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 external.getter - .test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + .test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 external.getter. - test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 + +external.getter[0]. // expect: testSubscript + test0() // expect: test0 + +external.getter[0] // expect: testSubscript + .test0() // expect: test0 external.method(). - test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 external.method() - .test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + .test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 external.method(). - test0() // expect: test0 - .test1(). // expect: test1 - test2() // expect: test2 + test0() // expect: test0 + .test1(). // expect: test1 + test2() // expect: test2 + +external.method()[0]. // expect: testSubscript + test0() // expect: test0 + +external.method()[0] // expect: testSubscript + .test0() // expect: test0 + //regular access in module scope var other = Test.new() other. - test0(). // expect: test0 - test1(). // expect: test1 - test2() // expect: test2 + test0(). // expect: test0 + test1(). // expect: test1 + test2() // expect: test2 other - .test0() // expect: test0 - .test1() // expect: test1 - .test2() // expect: test2 + .test0() // expect: test0 + .test1() // expect: test1 + .test2() // expect: test2 other - .test0(). // expect: test0 - test1() // expect: test1 - .test2() // expect: test2 + .test0(). // expect: test0 + test1() // expect: test1 + .test2() // expect: test2 + + +other[0] // expect: testSubscript + .test0() // expect: test0 + +other[0]. // expect: testSubscript + test0() // expect: test0