Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Lexer
# The following token types are listed as those classified as `tLPAREN`.
LPAREN_CONVERSION_TOKEN_TYPES = Set.new([
:kBREAK, :tCARET, :kCASE, :tDIVIDE, :kFOR, :kIF, :kNEXT, :kRETURN, :kUNTIL, :kWHILE, :tAMPER, :tANDOP, :tBANG, :tCOMMA, :tDOT2, :tDOT3,
:tEQL, :tLPAREN, :tLPAREN2, :tLPAREN_ARG, :tLSHFT, :tNL, :tOP_ASGN, :tOROP, :tPIPE, :tSEMI, :tSTRING_DBEG, :tUMINUS, :tUPLUS
:tEQL, :tLPAREN, :tLPAREN2, :tLPAREN_ARG, :tLSHFT, :tNL, :tOP_ASGN, :tOROP, :tPIPE, :tSEMI, :tSTRING_DBEG, :tUMINUS, :tUPLUS, :tLCURLY
])

# Types of tokens that are allowed to continue a method call with comments in-between.
Expand Down
195 changes: 143 additions & 52 deletions snapshots/break.txt

Large diffs are not rendered by default.

141 changes: 116 additions & 25 deletions snapshots/next.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@ ProgramNode (location: (1,0)-(24,15))
@ ProgramNode (location: (1,0)-(28,23))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(24,15))
@ StatementsNode (location: (1,0)-(28,23))
├── flags: ∅
└── body: (length: 10)
└── body: (length: 12)
├── @ CallNode (location: (1,0)-(1,12))
│ ├── flags: newline, ignore_visibility
│ ├── receiver: ∅
Expand Down Expand Up @@ -332,41 +332,132 @@
│ │ └── keyword_loc: (22,6)-(22,10) = "next"
│ ├── opening_loc: (22,4)-(22,5) = "{"
│ └── closing_loc: (22,13)-(22,14) = "}"
└── @ CallNode (location: (24,0)-(24,15))
├── @ CallNode (location: (24,0)-(24,15))
│ ├── flags: newline, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :tap
│ ├── message_loc: (24,0)-(24,3) = "tap"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block:
│ @ BlockNode (location: (24,4)-(24,15))
│ ├── flags: ∅
│ ├── locals: []
│ ├── parameters: ∅
│ ├── body:
│ │ @ StatementsNode (location: (24,6)-(24,13))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ NextNode (location: (24,6)-(24,13))
│ │ ├── flags: newline
│ │ ├── arguments:
│ │ │ @ ArgumentsNode (location: (24,10)-(24,13))
│ │ │ ├── flags: ∅
│ │ │ └── arguments: (length: 1)
│ │ │ └── @ ParenthesesNode (location: (24,10)-(24,13))
│ │ │ ├── flags: ∅
│ │ │ ├── body:
│ │ │ │ @ StatementsNode (location: (24,11)-(24,12))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── body: (length: 1)
│ │ │ │ └── @ IntegerNode (location: (24,11)-(24,12))
│ │ │ │ ├── flags: newline, static_literal, decimal
│ │ │ │ └── value: 1
│ │ │ ├── opening_loc: (24,10)-(24,11) = "("
│ │ │ └── closing_loc: (24,12)-(24,13) = ")"
│ │ └── keyword_loc: (24,6)-(24,10) = "next"
│ ├── opening_loc: (24,4)-(24,5) = "{"
│ └── closing_loc: (24,14)-(24,15) = "}"
├── @ CallNode (location: (26,0)-(26,16))
│ ├── flags: newline, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :tap
│ ├── message_loc: (26,0)-(26,3) = "tap"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block:
│ @ BlockNode (location: (26,4)-(26,16))
│ ├── flags: ∅
│ ├── locals: []
│ ├── parameters: ∅
│ ├── body:
│ │ @ StatementsNode (location: (26,6)-(26,14))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ ParenthesesNode (location: (26,6)-(26,14))
│ │ ├── flags: newline
│ │ ├── body:
│ │ │ @ StatementsNode (location: (26,7)-(26,13))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ NextNode (location: (26,7)-(26,13))
│ │ │ ├── flags: newline
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (26,12)-(26,13))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ IntegerNode (location: (26,12)-(26,13))
│ │ │ │ ├── flags: static_literal, decimal
│ │ │ │ └── value: 1
│ │ │ └── keyword_loc: (26,7)-(26,11) = "next"
│ │ ├── opening_loc: (26,6)-(26,7) = "("
│ │ └── closing_loc: (26,13)-(26,14) = ")"
│ ├── opening_loc: (26,4)-(26,5) = "{"
│ └── closing_loc: (26,15)-(26,16) = "}"
└── @ CallNode (location: (28,0)-(28,23))
├── flags: newline, ignore_visibility
├── receiver: ∅
├── call_operator_loc: ∅
├── name: :tap
├── message_loc: (24,0)-(24,3) = "tap"
├── message_loc: (28,0)-(28,3) = "tap"
├── opening_loc: ∅
├── arguments: ∅
├── closing_loc: ∅
└── block:
@ BlockNode (location: (24,4)-(24,15))
@ BlockNode (location: (28,4)-(28,23))
├── flags: ∅
├── locals: []
├── parameters: ∅
├── body:
│ @ StatementsNode (location: (24,6)-(24,13))
│ @ StatementsNode (location: (28,6)-(28,21))
│ ├── flags: ∅
│ └── body: (length: 1)
│ └── @ NextNode (location: (24,6)-(24,13))
│ └── @ AndNode (location: (28,6)-(28,21))
│ ├── flags: newline
│ ├── arguments:
│ │ @ ArgumentsNode (location: (24,10)-(24,13))
│ ├── left:
│ │ @ CallNode (location: (28,6)-(28,9))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :foo
│ │ ├── message_loc: (28,6)-(28,9) = "foo"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── right:
│ │ @ ParenthesesNode (location: (28,13)-(28,21))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ ParenthesesNode (location: (24,10)-(24,13))
│ │ ├── flags: ∅
│ │ ├── body:
│ │ │ @ StatementsNode (location: (24,11)-(24,12))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ IntegerNode (location: (24,11)-(24,12))
│ │ │ ├── flags: newline, static_literal, decimal
│ │ │ └── value: 1
│ │ ├── opening_loc: (24,10)-(24,11) = "("
│ │ └── closing_loc: (24,12)-(24,13) = ")"
│ └── keyword_loc: (24,6)-(24,10) = "next"
├── opening_loc: (24,4)-(24,5) = "{"
└── closing_loc: (24,14)-(24,15) = "}"
│ │ ├── body:
│ │ │ @ StatementsNode (location: (28,14)-(28,20))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ NextNode (location: (28,14)-(28,20))
│ │ │ ├── flags: newline
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (28,19)-(28,20))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ IntegerNode (location: (28,19)-(28,20))
│ │ │ │ ├── flags: static_literal, decimal
│ │ │ │ └── value: 1
│ │ │ └── keyword_loc: (28,14)-(28,18) = "next"
│ │ ├── opening_loc: (28,13)-(28,14) = "("
│ │ └── closing_loc: (28,20)-(28,21) = ")"
│ └── operator_loc: (28,10)-(28,12) = "&&"
├── opening_loc: (28,4)-(28,5) = "{"
└── closing_loc: (28,22)-(28,23) = "}"
91 changes: 71 additions & 20 deletions snapshots/return.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@ ProgramNode (location: (1,0)-(23,9))
@ ProgramNode (location: (1,0)-(27,17))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(23,9))
@ StatementsNode (location: (1,0)-(27,17))
├── flags: ∅
└── body: (length: 10)
└── body: (length: 12)
├── @ ReturnNode (location: (1,0)-(1,6))
│ ├── flags: newline
│ ├── keyword_loc: (1,0)-(1,6) = "return"
Expand Down Expand Up @@ -159,21 +159,72 @@
│ ├── body: ∅
│ ├── opening_loc: (21,6)-(21,7) = "("
│ └── closing_loc: (21,7)-(21,8) = ")"
└── @ ReturnNode (location: (23,0)-(23,9))
├── @ ReturnNode (location: (23,0)-(23,9))
│ ├── flags: newline
│ ├── keyword_loc: (23,0)-(23,6) = "return"
│ └── arguments:
│ @ ArgumentsNode (location: (23,6)-(23,9))
│ ├── flags: ∅
│ └── arguments: (length: 1)
│ └── @ ParenthesesNode (location: (23,6)-(23,9))
│ ├── flags: ∅
│ ├── body:
│ │ @ StatementsNode (location: (23,7)-(23,8))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ IntegerNode (location: (23,7)-(23,8))
│ │ ├── flags: newline, static_literal, decimal
│ │ └── value: 1
│ ├── opening_loc: (23,6)-(23,7) = "("
│ └── closing_loc: (23,8)-(23,9) = ")"
├── @ ParenthesesNode (location: (25,0)-(25,10))
│ ├── flags: newline
│ ├── body:
│ │ @ StatementsNode (location: (25,1)-(25,9))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ ReturnNode (location: (25,1)-(25,9))
│ │ ├── flags: newline
│ │ ├── keyword_loc: (25,1)-(25,7) = "return"
│ │ └── arguments:
│ │ @ ArgumentsNode (location: (25,8)-(25,9))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ IntegerNode (location: (25,8)-(25,9))
│ │ ├── flags: static_literal, decimal
│ │ └── value: 1
│ ├── opening_loc: (25,0)-(25,1) = "("
│ └── closing_loc: (25,9)-(25,10) = ")"
└── @ AndNode (location: (27,0)-(27,17))
├── flags: newline
├── keyword_loc: (23,0)-(23,6) = "return"
└── arguments:
@ ArgumentsNode (location: (23,6)-(23,9))
├── flags: ∅
└── arguments: (length: 1)
└── @ ParenthesesNode (location: (23,6)-(23,9))
├── flags: ∅
├── body:
│ @ StatementsNode (location: (23,7)-(23,8))
│ ├── flags: ∅
│ └── body: (length: 1)
│ └── @ IntegerNode (location: (23,7)-(23,8))
│ ├── flags: newline, static_literal, decimal
│ └── value: 1
├── opening_loc: (23,6)-(23,7) = "("
└── closing_loc: (23,8)-(23,9) = ")"
├── left:
│ @ CallNode (location: (27,0)-(27,3))
│ ├── flags: variable_call, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :foo
│ ├── message_loc: (27,0)-(27,3) = "foo"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block: ∅
├── right:
│ @ ParenthesesNode (location: (27,7)-(27,17))
│ ├── flags: ∅
│ ├── body:
│ │ @ StatementsNode (location: (27,8)-(27,16))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ ReturnNode (location: (27,8)-(27,16))
│ │ ├── flags: newline
│ │ ├── keyword_loc: (27,8)-(27,14) = "return"
│ │ └── arguments:
│ │ @ ArgumentsNode (location: (27,15)-(27,16))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ IntegerNode (location: (27,15)-(27,16))
│ │ ├── flags: static_literal, decimal
│ │ └── value: 1
│ ├── opening_loc: (27,7)-(27,8) = "("
│ └── closing_loc: (27,16)-(27,17) = ")"
└── operator_loc: (27,4)-(27,6) = "&&"
6 changes: 6 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -19102,7 +19102,13 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
pm_binding_power_t binding_power = pm_binding_powers[parser->current.type].left;

if (binding_power == PM_BINDING_POWER_UNSET || binding_power >= PM_BINDING_POWER_RANGE) {
pm_token_t next = parser->current;
parse_arguments(parser, &arguments, false, PM_TOKEN_EOF, (uint16_t) (depth + 1));

// Reject `foo && return bar`.
if (!accepts_command_call && arguments.arguments != NULL) {
PM_PARSER_ERR_TOKEN_FORMAT(parser, next, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(next.type));
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/prism/errors/command_calls_32.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
foo && return bar
^~~ unexpected local variable or method, expecting end-of-input

tap { foo && break bar }
^~~ unexpected local variable or method, expecting end-of-input

tap { foo && next bar }
^~~ unexpected local variable or method, expecting end-of-input

foo && return()
^ unexpected '(', expecting end-of-input

foo && return(bar)
^ unexpected '(', expecting end-of-input

foo && return(bar, baz)
^~~~~~~~~~ unexpected write target
^ unexpected '(', expecting end-of-input

4 changes: 4 additions & 0 deletions test/prism/fixtures/break.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ tap { break() }

tap { break(1) }

tap { (break 1) }

tap { foo && (break 1) }

foo { break 42 } == 42

foo { |a| break } == 42
Expand Down
4 changes: 4 additions & 0 deletions test/prism/fixtures/next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ tap { next
tap { next() }

tap { next(1) }

tap { (next 1) }

tap { foo && (next 1) }
3 changes: 3 additions & 0 deletions test/prism/fixtures/return.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ return()

return(1)

(return 1)

foo && (return 1)
Loading