diff --git a/ast/ast.go b/ast/ast.go index 4154914..fb326b8 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -520,6 +520,15 @@ type ObjectComp struct { // --------------------------------------------------------------------------- +// Parens represents parentheses +// ( e ) +type Parens struct { + NodeBase + Inner Node +} + +// --------------------------------------------------------------------------- + // Self represents the self keyword. type Self struct{ NodeBase } diff --git a/ast/stdast.go b/ast/stdast.go index d9da41e..ef60584 100644 --- a/ast/stdast.go +++ b/ast/stdast.go @@ -15797,7 +15797,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(67), - Column: int(79), + Column: int(80), }, file: p1, }, @@ -22348,7 +22348,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(102), - Column: int(86), + Column: int(87), }, file: p1, }, @@ -30534,7 +30534,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(162), - Column: int(58), + Column: int(59), }, file: p1, }, @@ -31033,7 +31033,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(164), - Column: int(67), + Column: int(68), }, file: p1, }, @@ -31722,7 +31722,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(166), - Column: int(95), + Column: int(96), }, file: p1, }, @@ -37243,7 +37243,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(193), - Column: int(81), + Column: int(82), }, file: p1, }, @@ -37954,7 +37954,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(195), - Column: int(87), + Column: int(88), }, file: p1, }, @@ -39367,7 +39367,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(201), - Column: int(90), + Column: int(91), }, file: p1, }, @@ -40078,7 +40078,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(203), - Column: int(87), + Column: int(88), }, file: p1, }, @@ -41512,7 +41512,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(209), - Column: int(88), + Column: int(89), }, file: p1, }, @@ -41955,7 +41955,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(211), - Column: int(86), + Column: int(87), }, file: p1, }, @@ -69708,7 +69708,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(439), - Column: int(59), + Column: int(60), }, file: p1, }, @@ -69737,7 +69737,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(439), - Column: int(59), + Column: int(60), }, file: p1, }, @@ -69913,7 +69913,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(439), - Column: int(59), + Column: int(60), }, file: p1, }, @@ -70867,7 +70867,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(442), - Column: int(74), + Column: int(75), }, file: p1, }, @@ -73709,7 +73709,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(461), - Column: int(53), + Column: int(54), }, file: p1, }, @@ -73732,7 +73732,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(460), - Column: int(74), + Column: int(75), }, file: p1, }, @@ -90882,7 +90882,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(576), - Column: int(95), + Column: int(96), }, file: p1, }, @@ -103665,7 +103665,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(694), - Column: int(94), + Column: int(95), }, file: p1, }, @@ -104109,7 +104109,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(696), - Column: int(92), + Column: int(93), }, file: p1, }, @@ -104553,7 +104553,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(698), - Column: int(83), + Column: int(84), }, file: p1, }, @@ -116822,7 +116822,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(770), - Column: int(54), + Column: int(55), }, file: p1, }, @@ -140302,7 +140302,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(907), - Column: int(62), + Column: int(63), }, file: p1, }, @@ -140327,7 +140327,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(907), - Column: int(62), + Column: int(63), }, file: p1, }, @@ -142156,7 +142156,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(923), - Column: int(87), + Column: int(88), }, file: p1, }, @@ -142838,7 +142838,7 @@ var StdAst = &DesugaredObject{ }, End: Location{ Line: int(927), - Column: int(96), + Column: int(97), }, file: p1, }, diff --git a/desugarer.go b/desugarer.go index f873b76..42e53c3 100644 --- a/desugarer.go +++ b/desugarer.go @@ -560,6 +560,13 @@ func desugar(astPtr *ast.Node, objLevel int) (err error) { } *astPtr = comp + case *ast.Parens: + *astPtr = node.Inner + err = desugar(astPtr, objLevel) + if err != nil { + return err + } + case *ast.Self: // Nothing to do. diff --git a/parser/context.go b/parser/context.go index f76b4df..ab3a4b5 100644 --- a/parser/context.go +++ b/parser/context.go @@ -99,6 +99,8 @@ func directChildren(node ast.Node) []ast.Node { spec = spec.Outer } return result + case *ast.Parens: + return []ast.Node{node.Inner} case *ast.Self: return nil case *ast.SuperIndex: @@ -172,6 +174,8 @@ func thunkChildren(node ast.Node) []ast.Node { return []ast.Node{node.Body} case *ast.ObjectComp: return nil + case *ast.Parens: + return nil case *ast.Self: return nil case *ast.SuperIndex: diff --git a/parser/parser.go b/parser/parser.go index 3bc76c4..54dba33 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -724,11 +724,14 @@ func (p *parser) parseTerminal() (ast.Node, error) { if err != nil { return nil, err } - _, err = p.popExpect(tokenParenR) + tokRight, err := p.popExpect(tokenParenR) if err != nil { return nil, err } - return inner, nil + return &ast.Parens{ + NodeBase: ast.NewNodeBaseLoc(locFromTokens(tok, tokRight)), + Inner: inner, + }, nil // Literals case tokenNumber: diff --git a/parser/parser_test.go b/parser/parser_test.go index 8d3f3f7..440841d 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -229,9 +229,9 @@ var errorTests = []testError{ {`function a a`, `test:1:10-11 Expected ( but got (IDENTIFIER, "a")`}, {`import (a b)`, `test:1:11-12 Expected token ")" but got (IDENTIFIER, "b")`}, - {`import (a+b)`, `test:1:9-12 Computed imports are not allowed`}, + {`import (a+b)`, `test:1:8-13 Computed imports are not allowed`}, {`importstr (a b)`, `test:1:14-15 Expected token ")" but got (IDENTIFIER, "b")`}, - {`importstr (a+b)`, `test:1:12-15 Computed imports are not allowed`}, + {`importstr (a+b)`, `test:1:11-16 Computed imports are not allowed`}, {`local a = b ()`, `test:1:15 Expected , or ; but got end of file`}, {`local a = b; (a b)`, `test:1:17-18 Expected token ")" but got (IDENTIFIER, "b")`}, diff --git a/testdata/div4.golden b/testdata/div4.golden index 4042503..b5eecc2 100644 --- a/testdata/div4.golden +++ b/testdata/div4.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Overflow ------------------------------------------------- - testdata/div4:1:1-19 $ + testdata/div4:1:1-20 $ 1/(1e-160)/(1e-160) diff --git a/testdata/error_function_fail.golden b/testdata/error_function_fail.golden index 56407c5..6af81dc 100644 --- a/testdata/error_function_fail.golden +++ b/testdata/error_function_fail.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Couldn't manifest function in JSON output. ------------------------------------------------- - testdata/error_function_fail:1:1-22 $ + testdata/error_function_fail:1:1-23 $ error (function(x) 42) diff --git a/testdata/percent_bad2.golden b/testdata/percent_bad2.golden index 45a15a0..aa9e42f 100644 --- a/testdata/percent_bad2.golden +++ b/testdata/percent_bad2.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Too many values to format: 1, expected 0 ------------------------------------------------- - :576:21-95 function + :576:21-96 function error ("Too many values to format: " + std.length(arr) + ", expected " + j) diff --git a/testdata/percent_format_str4.golden b/testdata/percent_format_str4.golden index 9fef110..4ebff81 100644 --- a/testdata/percent_format_str4.golden +++ b/testdata/percent_format_str4.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Too many values to format: 2, expected 1 ------------------------------------------------- - :576:21-95 function + :576:21-96 function error ("Too many values to format: " + std.length(arr) + ", expected " + j) diff --git a/testdata/string_plus_function.golden b/testdata/string_plus_function.golden index f4fa1ed..6f0d429 100644 --- a/testdata/string_plus_function.golden +++ b/testdata/string_plus_function.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Couldn't manifest function in JSON output. ------------------------------------------------- - testdata/string_plus_function:1:1-23 $ + testdata/string_plus_function:1:1-24 $ "xxx" + (function() 42)