diff --git a/ast/ast_test.go b/ast/ast_test.go index 6211c1a..b0b6aea 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -29,8 +29,8 @@ func TestString(t *testing.T) { `true ? puts(true) : puts(false)`, }, { - "foreach i, e in [1, 2, 3] {\n puts(i)\n}", - "foreach i, e in [1, 2, 3] {\n puts(i)\n}", + "foreach i, e in [1, 2, 3] \n puts(i)\nend", + "foreach i, e in [1, 2, 3] \n puts(i)\nend", }, { "if (true)\n return (true)\nelse\n puts(false)\nend", @@ -41,12 +41,12 @@ func TestString(t *testing.T) { "while (true)\n puts(true)\nend", }, { - "while (true) {\n puts(true)\n}", + "while (true)\n puts(true)\nend", "while (true)\n puts(true)\nend", }, { - "while {\n puts(true)\n}", - "", + "while\n puts(true)\n", + "puts(true)", }, } diff --git a/ast/foreach.go b/ast/foreach.go index 18a5b32..e24c810 100644 --- a/ast/foreach.go +++ b/ast/foreach.go @@ -23,8 +23,8 @@ func (fes *Foreach) String() string { out.WriteString(fes.Ident) out.WriteString(" in ") out.WriteString(fes.Value.String()) - out.WriteString(" {\n ") + out.WriteString(" \n ") out.WriteString(fes.Body.String()) - out.WriteString("\n}") + out.WriteString("\nend") return out.String() } diff --git a/docs/content/_index.md b/docs/content/_index.md index 380939d..293d0d0 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -25,28 +25,28 @@ input = open("examples/aoc/2021/day-1/input").lines() a = [] -foreach i, number in input { +foreach i, number in input a.yoink(number.strip().plz_i()) -} +end input = a increase = 0 -foreach i, number in input { +foreach i, number in input if (number > input[i-1]) increase = increase + 1 end -} +end puts(increase + 1) increase = 0 -foreach i, number in input { +foreach i, number in input sum = number + input[i+1] + input[i+2] sum_two = input[i+1] + input[i+2] + input[i+3] if (sum_two > sum) increase = increase + 1 end -} +end puts(increase + 1) ``` diff --git a/docs/content/docs/control_expressions/foreach.md b/docs/content/docs/control_expressions/foreach.md index ff5825e..651eb37 100644 --- a/docs/content/docs/control_expressions/foreach.md +++ b/docs/content/docs/control_expressions/foreach.md @@ -15,10 +15,10 @@ input = open("examples/aoc/2021/day-1/input").lines() // define temporary array a = [] -foreach i, number in input { +foreach i, number in input // read each line into temporary array and cast it into an integer a.yoink(number.strip().plz_i()) -} +end // assign temporary array to input array input = a @@ -28,7 +28,10 @@ input = a Count form zero to a given number (excluding): ```js -🚀 > foreach i in 5 { puts(i) } +🚀 > foreach i in 5 + puts(i) +end + 0 1 2 @@ -40,7 +43,10 @@ Count form zero to a given number (excluding): Iterate over a string: ```js -🚀 > foreach i in "test" { puts(i) } +🚀 > foreach i in "test" + puts(i) +end + "t" "e" "s" diff --git a/docs/content/docs/control_expressions/if.md b/docs/content/docs/control_expressions/if.md index 9a29c30..02ecd12 100644 --- a/docs/content/docs/control_expressions/if.md +++ b/docs/content/docs/control_expressions/if.md @@ -7,19 +7,6 @@ menu: # If With `if` and `else` keywords the flow of a program can be controlled. -```js -🚀 > if (a.type() == "STRING") { - puts("is a string") -} else { - puts("is not a string") -} - -// which prints -is a string -``` - -> 👉 Since `0.13` curly braces are completely optional (closing brace needs to be replaced with `end`) - ```js 🚀 > if (a.type() == "STRING") puts("is a string") diff --git a/docs/content/docs/literals/file.md b/docs/content/docs/literals/file.md index 829bb9d..1c868ba 100644 --- a/docs/content/docs/literals/file.md +++ b/docs/content/docs/literals/file.md @@ -58,9 +58,9 @@ Seek sets the offset for the next Read or Write on file to offset, interpreted a ### write(STRING) -> Returns `BOOLEAN|ERROR` +> Returns `INTEGER|ERROR` -Writes the given string to the file. Returns `true` on success. +Writes the given string to the file. Returns number of written bytes on success. diff --git a/docs/content/docs/literals/http.md b/docs/content/docs/literals/http.md index 0128d18..8ebc1fe 100644 --- a/docs/content/docs/literals/http.md +++ b/docs/content/docs/literals/http.md @@ -10,10 +10,10 @@ menu: ```js -def test() { +def test() puts(request["body"]) return("test") -} +end HTTP.handle("/", test) diff --git a/docs/content/docs/specification/closures.md b/docs/content/docs/specification/closures.md index 3e4c6f3..7c8ab72 100644 --- a/docs/content/docs/specification/closures.md +++ b/docs/content/docs/specification/closures.md @@ -7,9 +7,11 @@ toc: true --- # Closures ```js -newGreeter = def (greeting) { - return def (name) { puts(greeting + " " + name); } -}; +newGreeter = def (greeting) + return def (name) + puts(greeting + " " + name) + end +end hello = newGreeter("Hello"); diff --git a/docs/content/docs/specification/comments.md b/docs/content/docs/specification/comments.md index 5f3bbe4..b6a536c 100644 --- a/docs/content/docs/specification/comments.md +++ b/docs/content/docs/specification/comments.md @@ -11,8 +11,8 @@ All following content up to the end of the line is part of the comment. ```js // This is a comment -def (a) { +def (a) // This is also a comment a + a // And this -} +end ``` \ No newline at end of file diff --git a/docs/content/docs/specification/functions.md b/docs/content/docs/specification/functions.md index 1f19fa1..23fb9ca 100644 --- a/docs/content/docs/specification/functions.md +++ b/docs/content/docs/specification/functions.md @@ -9,7 +9,7 @@ toc: true Implicit and explicit return statements are supported. ```js -fibonacci = def (x) { +fibonacci = def (x) if (x == 0) 0 else @@ -19,7 +19,7 @@ fibonacci = def (x) { fibonacci(x - 1) + fibonacci(x - 2); end end -}; +end ``` > New in `0.11`: @@ -27,10 +27,13 @@ fibonacci = def (x) { Functions can now also be created as named functions: ```js -🚀 > def test() { puts("test")} -=> def () { -puts(test) -} +🚀 > def test() + puts("test") +end + +=> def () + puts(test) +end 🚀 > test() "test" diff --git a/docs/content/docs/specification/modules.md b/docs/content/docs/specification/modules.md index 65cef92..30ecf56 100644 --- a/docs/content/docs/specification/modules.md +++ b/docs/content/docs/specification/modules.md @@ -18,11 +18,9 @@ For example take this module: a = 1 A = 5 -Sum = def (a, b) { +Sum = def (a, b) return a + b -} - - +end ``` You can import it with: diff --git a/docs/generate.go b/docs/generate.go index fcca519..2938347 100644 --- a/docs/generate.go +++ b/docs/generate.go @@ -166,10 +166,10 @@ To cast a negative integer a digit can be prefixed with a - eg. -456.`, tempData = templateData{ Title: "HTTP", - Example: `def test() { + Example: `def test() puts(request["body"]) return("test") -} +end HTTP.handle("/", test) diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index fadc4dc..3b519c1 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -117,17 +117,13 @@ func TestIfElseExpressions(t *testing.T) { input string expected interface{} }{ - {"if (true) { 10 }", 10}, - {"if (false) { 10 }", nil}, - {"if (true)\n 10 end", 10}, - {"if (false) \n 10 end", nil}, - {"if (1) { 10 }", 10}, - {"if (1) \n 10 end", 10}, - {"if (1 < 2) { 10 }", 10}, - {"if (1 > 2) { 10 }", nil}, - {"if (1 > 2) { 10 } else { 20 }", 20}, - {"if (1 < 2) { 10 } else { 20 }", 10}, - {"if (1 < 2) \n 10 \n else \n 20 end", 10}, + {"if (true) \n 10 \nend", 10}, + {"if (false) \n 10 \nend", nil}, + {"if (1) \n 10 \nend", 10}, + {"if (1 < 2) \n 10 \nend", 10}, + {"if (1 > 2) \n 10 \nend", nil}, + {"if (1 > 2) \n 10 \n else \n 20 \nend", 20}, + {"if (1 < 2) \n 10 \n else \n 20 \nend", 10}, } for _, tt := range tests { @@ -151,12 +147,12 @@ func TestReturnStatements(t *testing.T) { {"return 2 * 5; 9;", 10}, {"9; return 2 * 5; 9;", 10}, {` - if (10 > 1) { - if (10 > 1) { + if (10 > 1) + if (10 > 1) return 10; - } + end return 1; - } + end `, 10}, } @@ -176,17 +172,16 @@ func TestErrorHandling(t *testing.T) { {"-true", "unknown operator: -BOOLEAN"}, {"true + false", "unknown operator: BOOLEAN + BOOLEAN"}, {"5; true + false; 5", "unknown operator: BOOLEAN + BOOLEAN"}, - {"if (10 > 1) { true + false }", "unknown operator: BOOLEAN + BOOLEAN"}, + {"if (10 > 1) \n true + false \n", "unknown operator: BOOLEAN + BOOLEAN"}, {"foobar", "identifier not found: foobar"}, { ` - if (10 > 1) { - if (10 > 1) { + if (10 > 1) + if (10 > 1) return true + false - } - + end return 1 - } + end `, "unknown operator: BOOLEAN + BOOLEAN", }, {`"Hello" - "World"`, "unknown operator: STRING - STRING"}, @@ -198,15 +193,15 @@ func TestErrorHandling(t *testing.T) { {"if (5 % 0)\n puts(true)\nend", "division by zero not allowed"}, {"a = {(5%0): true}", "division by zero not allowed"}, {"a = {true: (5%0)}", "division by zero not allowed"}, - {"def test() { puts(true) }; a = {test: true}", "unusable as hash key: FUNCTION"}, + {"def test() \n puts(true) \nend; a = {test: true}", "unusable as hash key: FUNCTION"}, {"import(true)", "Import Error: invalid import path '&{%!s(bool=true)}'"}, {"import(5%0)", "division by zero not allowed"}, {`import("fixtures/nope")`, "Import Error: no module named 'fixtures/nope' found"}, { `import("../fixtures/parser_error")`, - "Parse Error: [0:10: expected next token to be EOF, got EOF instead 0:10: expected next token to be EOF, got EOF instead]", + "Parse Error: [0:10: expected next token to be EOF, got EOF instead]", }, - {"def test() { puts(true) }; test[1]", "index operator not supported: FUNCTION"}, + {"def test() \n puts(true) \nend; test[1]", "index operator not supported: FUNCTION"}, {"[1] - [1]", "unknown operator: ARRAY - ARRAY"}, } @@ -242,7 +237,7 @@ func TestAssignStatements(t *testing.T) { } func TestFunctionObject(t *testing.T) { - input := "def(x) { x + 2; };" + input := "def(x) \n x + 2; \nend;" evaluated := testEval(input) def, ok := evaluated.(*object.Function) @@ -270,12 +265,12 @@ func TestFunctionApplication(t *testing.T) { input string expected int64 }{ - {"identity = def(x) { x; }; identity(5);", 5}, - {"identity = def(x) { return x; }; identity(5);", 5}, - {"double = def(x) { x * 2; }; double(5);", 10}, - {"add = def(x, y) { x + y; }; add(5, 5);", 10}, - {"add = def(x, y) { x + y; }; add(5 + 5, add(5, 5));", 20}, - {"def(x) { x; }(5)", 5}, + {"identity = def(x) \n x; \nend; identity(5);", 5}, + {"identity = def(x) \n return x; \nend; identity(5);", 5}, + {"double = def(x) \n x * 2; \nend; double(5);", 10}, + {"add = def(x, y) \n x + y; \nend; add(5, 5);", 10}, + {"add = def(x, y) \n x + y; \nend; add(5 + 5, add(5, 5));", 20}, + {"def(x) \n x; \nend(5)", 5}, } for _, tt := range tests { @@ -285,9 +280,11 @@ func TestFunctionApplication(t *testing.T) { func TestClosures(t *testing.T) { input := ` - newAdder = def(x) { - def(y) { x + y }; - }; + newAdder = def(x) + def(y) + x + y + end + end; addTwo = newAdder(2); addTwo(2);` @@ -570,9 +567,9 @@ func TestNamedFunctionStatements(t *testing.T) { input string expected int64 }{ - {"def five() { return 5 } five()", 5}, - {"def ten() { return 10 } ten()", 10}, - {"def fifteen() { return 15 } fifteen()", 15}, + {"def five() \n return 5 \nend five()", 5}, + {"def ten() \n return 10 \nend ten()", 10}, + {"def fifteen() \n return 15 \nend fifteen()", 15}, } for _, tt := range tests { diff --git a/examples/aoc/2015/day1.rl b/examples/aoc/2015/day1.rl index 79f5d32..c803e10 100644 --- a/examples/aoc/2015/day1.rl +++ b/examples/aoc/2015/day1.rl @@ -2,12 +2,12 @@ "// Last Updated: 2022.01.18" "// RocketLang Version: 0.14.1" "// ------------------------------------" -part_one = def (input) { +part_one = def (input) "// There is a foreach loop now but I wanted to stick as close to the original version as possible" calc(input, input.size(), 0) -} +end -calc = def (input, idx, floor) { +calc = def (input, idx, floor) char_to_value = { "(": 1, ")": -1 @@ -24,7 +24,7 @@ calc = def (input, idx, floor) { end calc(input, new_idx, floor + delta) -} +end "// Test some inputs to check that our code is correct..." if (part_one("(())") != 0) diff --git a/examples/aoc/2021/day-1/complete.rl b/examples/aoc/2021/day-1/complete.rl index 08af972..873e219 100644 --- a/examples/aoc/2021/day-1/complete.rl +++ b/examples/aoc/2021/day-1/complete.rl @@ -5,18 +5,18 @@ input = open("examples/aoc/2021/day-1/input").lines() increase = 0 a = [] -foreach i, number in input { +foreach i, number in input a.yoink(number.strip().plz_i()) -} +end input = a -foreach i, number in input { +foreach i, number in input if (input[i-1].type() != "NULL") if (number > input[i-1]) increase = increase + 1 end end -} +end puts(increase) @@ -24,13 +24,13 @@ puts(increase) increase = 0 -foreach i, number in input { +foreach i, number in input sum = number + input[i+1].plz_i() + input[i+2].plz_i() sum_two = input[i+1].plz_i() + input[i+2].plz_i() + input[i+3].plz_i() if (sum_two > sum) increase = increase + 1 end -} +end puts(increase) \ No newline at end of file diff --git a/examples/aoc/2021/day-2/complete.rl b/examples/aoc/2021/day-2/complete.rl index 64bf29b..b199cb3 100644 --- a/examples/aoc/2021/day-2/complete.rl +++ b/examples/aoc/2021/day-2/complete.rl @@ -4,7 +4,7 @@ depth = 0 hor = 0 aim = 0 -foreach i, line in input { +foreach i, line in input command = line.split(" ")[0] value = line.strip().split(" ")[1].plz_i() if (command == "forward") @@ -19,6 +19,6 @@ foreach i, line in input { if (command == "up") aim = aim - value end -} +end puts(hor * depth) \ No newline at end of file diff --git a/examples/misc/foreach.rl b/examples/misc/foreach.rl new file mode 100644 index 0000000..f7bca99 --- /dev/null +++ b/examples/misc/foreach.rl @@ -0,0 +1,3 @@ +foreach i in 5 + puts(i) +end \ No newline at end of file diff --git a/examples/misc/function.rl b/examples/misc/function.rl new file mode 100644 index 0000000..9f6e37e --- /dev/null +++ b/examples/misc/function.rl @@ -0,0 +1,11 @@ +def test(a) + puts(a) +end + +test("test") + +a = def() + puts("test2") +end + +a() \ No newline at end of file diff --git a/examples/misc/while.rl b/examples/misc/while.rl new file mode 100644 index 0000000..9abc677 --- /dev/null +++ b/examples/misc/while.rl @@ -0,0 +1,5 @@ +a = 0 +while (a != 4) + puts(a) + a = a + 1 +end \ No newline at end of file diff --git a/fixtures/module.rl b/fixtures/module.rl index 3ff220e..846bb91 100644 --- a/fixtures/module.rl +++ b/fixtures/module.rl @@ -1,6 +1,6 @@ a = 1 A = 5 -Sum = def (a, b) { +Sum = def (a, b) return a + b -} +end diff --git a/object/array_test.go b/object/array_test.go index be152f4..7316e04 100644 --- a/object/array_test.go +++ b/object/array_test.go @@ -36,12 +36,12 @@ func TestArrayObjectMethods(t *testing.T) { {`a = []; a.yoink(1); a`, "[1]"}, {`[].nope()`, "undefined method `.nope()` for ARRAY"}, {`([].wat().lines().size() == [].methods().size() + 1).plz_s()`, "true"}, - {`a = ["a", "b"]; b = []; foreach i, item in a { b.yoink(item) }; b.size()`, 2}, + {"a = [\"a\", \"b\"]; b = []; foreach i, item in a \n b.yoink(item) \nend; b.size()", 2}, {`[1,2,3].index(4)`, -1}, {`[1,2,3].index(3)`, 2}, {`[1,2,3].index(true)`, -1}, {`[1,2,3].index()`, "to few arguments: want=1, got=0"}, - {`a = []; b = []; foreach i in a { b.yoink(a[i]) }; a.size()==b.size()`, true}, + {"a = []; b = []; foreach i in a \n b.yoink(a[i]) \nend; a.size()==b.size()", true}, {`[1,1,2].uniq().size()`, 2}, {`[true,true,2].uniq().size()`, 2}, {`["test","test",2].uniq().size()`, 2}, diff --git a/object/function.go b/object/function.go index 67ccf78..6d6ff7a 100644 --- a/object/function.go +++ b/object/function.go @@ -33,9 +33,9 @@ func (f *Function) Inspect() string { out.WriteString("def ") out.WriteString("(") out.WriteString(strings.Join(params, ", ")) - out.WriteString(") {\n") + out.WriteString(") \n") out.WriteString(f.Body.String()) - out.WriteString("\n}") + out.WriteString("\nend") return out.String() } diff --git a/object/function_test.go b/object/function_test.go index 8afb044..222a825 100644 --- a/object/function_test.go +++ b/object/function_test.go @@ -8,15 +8,15 @@ import ( func TestFunctionObjectMethods(t *testing.T) { tests := []inputTestCase{ - {`def(){}.nope()`, "undefined method `.nope()` for FUNCTION"}, + {"def()\n\nend.nope()", "undefined method `.nope()` for FUNCTION"}, } testInput(t, tests) } func TestFunctionType(t *testing.T) { tests := []inputTestCase{ - {"def(){}", "def () {\n\n}"}, - {"def(a){puts(a)}", "def (a) {\nputs(a)\n}"}, + {"def()\n\nend", "def () \n\nend"}, + {"def(a)\nputs(a)\nend", "def (a) \nputs(a)\nend"}, } for _, tt := range tests { diff --git a/object/hash_test.go b/object/hash_test.go index 88cc219..478d19c 100644 --- a/object/hash_test.go +++ b/object/hash_test.go @@ -24,7 +24,7 @@ func TestHashObjectMethods(t *testing.T) { {`{}.nope()`, "undefined method `.nope()` for HASH"}, {`({}.wat().lines().size() == {}.methods().size() + 1).plz_s()`, "true"}, {`{}.type()`, "HASH"}, - {`a = {"a": "b", "b":"a"};b = []; foreach key, value in a { b.yoink(key) }; b.size()`, 2}, + {"a = {\"a\": \"b\", \"b\":\"a\"};b = []; foreach key, value in a \n b.yoink(key) \nend; b.size()", 2}, {`{"a": 1, "b": 2}["a"]`, 1}, {`{"a": 1, "b": 2}.keys().size()`, 2}, {`{"a": 1, "b": 2}.values().size()`, 2}, diff --git a/object/http_test.go b/object/http_test.go index f16c69e..d24f5bf 100644 --- a/object/http_test.go +++ b/object/http_test.go @@ -17,7 +17,7 @@ func TestHTTPObjectMethods(t *testing.T) { {`HTTP.handle(1, "test")`, "wrong argument type on position 0: got=INTEGER, want=STRING"}, {`HTTP.handle("/", "test")`, "wrong argument type on position 1: got=STRING, want=FUNCTION"}, {`HTTP.listen(3000)`, "Invalid handler. Call only supported on instance."}, - {`def test(){};HTTP.handle("/", test)`, "Invalid handler. Call only supported on instance."}, + {"def test()\nend;HTTP.handle(\"/\", test)", "Invalid handler. Call only supported on instance."}, {`a = HTTP.new(); a.listen(-1)`, "listening on port -1: listen tcp: address -1: invalid port"}, {`a = HTTP.new(); a.listen(80)`, "listening on port 80: listen tcp :80: bind: permission denied"}, {"HTTP.new().to_json()", "HTTP is not serializable"}, @@ -41,12 +41,17 @@ func TestHTTPType(t *testing.T) { } func TestHTTPServerMethods(t *testing.T) { - httpServer := `def test(){response["body"] = "test"}; -def test_a(){response = "test"}; -a = HTTP.new(); -a.handle("/", test); -a.handle("/test2", test_a); -a.listen(3000)` + httpServer := ` + def test() + response["body"] = "test" + end + def test_a() + response = "test" + end + a = HTTP.new(); + a.handle("/", test); + a.handle("/test2", test_a); + a.listen(3000)` go testEval(httpServer) time.Sleep(100 * time.Millisecond) // workaround to give testIntput time to evaluate the input and start the http handle diff --git a/object/string_test.go b/object/string_test.go index 4de65c2..1bfe8c5 100644 --- a/object/string_test.go +++ b/object/string_test.go @@ -83,7 +83,7 @@ func TestStringObjectMethods(t *testing.T) { {`a = "test"; a.reverse!(); a`, "tset"}, {`a = " test "; a.strip!(); a`, "test"}, {`("test".wat().lines().size() == "test".methods().size() + 1).plz_s()`, "true"}, - {`a = "test"; b = []; foreach char in a { b.yoink(char) }; b.size()`, 4}, + {"a = \"test\"; b = []; foreach char in a \n b.yoink(char) \nend; b.size()", 4}, {`"test" * 2`, "testtest"}, {`2 * "test"`, "testtest"}, {`"test".to_json()`, `"test"`}, diff --git a/parser/foreach.go b/parser/foreach.go index beb0347..97566d9 100644 --- a/parser/foreach.go +++ b/parser/foreach.go @@ -52,7 +52,6 @@ func (p *Parser) parseForEach() ast.Expression { return nil } - p.nextToken() expression.Body = p.parseBlock() return expression diff --git a/parser/function.go b/parser/function.go index 67aa70c..bf6c0ef 100644 --- a/parser/function.go +++ b/parser/function.go @@ -20,10 +20,6 @@ func (p *Parser) parseFunction() ast.Expression { lit.Parameters = p.parseFunctionParameters() - if !p.expectPeek(token.LBRACE) { - return nil - } - lit.Body = p.parseBlock() return lit diff --git a/parser/if.go b/parser/if.go index fc5877e..33a3f75 100644 --- a/parser/if.go +++ b/parser/if.go @@ -18,20 +18,10 @@ func (p *Parser) parseIf() ast.Expression { return nil } - if p.peekTokenIs(token.LBRACE) { - p.nextToken() - } expression.Consequence = p.parseBlock() - if p.curTokenIs(token.RBRACE) { - p.nextToken() - } - if p.curTokenIs(token.ELSE) { - if p.peekTokenIs(token.LBRACE) { - p.nextToken() - } expression.Alternative = p.parseBlock() } return expression diff --git a/parser/parser_test.go b/parser/parser_test.go index 2899e81..d99ebcb 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -424,7 +424,7 @@ func testBooleanLiteral(t *testing.T, exp ast.Expression, value bool) bool { } func TestIfExpression(t *testing.T) { - input := `if (x < y) { x }` + input := "if (x < y) \n x \nend" program, p := createProgram(input) checkParserErrors(t, p) @@ -466,7 +466,7 @@ func TestIfExpression(t *testing.T) { } func TestFunctionLiteralParsing(t *testing.T) { - input := `def (x, y) { x + y; }` + input := "def (x, y) \n x + y; \nend" program, p := createProgram(input) checkParserErrors(t, p) @@ -720,7 +720,7 @@ func TestParsingHashLiteralWithExpressions(t *testing.T) { } func TestNamedFunctionLiteralParsing(t *testing.T) { - input := `def test(x, y) { x + y; }` + input := "def test(x, y) \n x + y; \nend" program, p := createProgram(input) diff --git a/parser/while.go b/parser/while.go index 3829ff5..1b6ba28 100644 --- a/parser/while.go +++ b/parser/while.go @@ -19,14 +19,7 @@ func (p *Parser) parseWhile() ast.Expression { return nil } - if p.peekTokenIs(token.LBRACE) { - p.nextToken() - } expression.Body = p.parseBlock() - if p.curTokenIs(token.RBRACE) { - p.nextToken() - } - return expression } diff --git a/tests/while.rl b/tests/while.rl index c46de95..76e56bc 100644 --- a/tests/while.rl +++ b/tests/while.rl @@ -5,7 +5,7 @@ while (a != 3) end -def test_one() { +def test_one() a = 0 while (a != 3) puts(a) @@ -14,15 +14,15 @@ def test_one() { end a = a + 1 end -} +end -def test_two() { +def test_two() a = 0 while (a != 3) puts(a) a = a % 0 end -} +end test_one() test_two() \ No newline at end of file