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: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ tokens:
comment: "def"
- name: KEYWORD_DEFINED
comment: "defined?"
- name: KEYWORD_DO_BLOCK
comment: "do keyword for a block attached to a command"
- name: KEYWORD_DO_LOOP
comment: "do keyword for a predicate in a while, until, or for loop"
- name: KEYWORD_END_UPCASE
Expand Down
7 changes: 7 additions & 0 deletions include/prism/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ struct pm_parser {
/** Whether or not we're at the beginning of a command. */
bool command_start;

/**
* Whether or not we're currently parsing the body of an endless method
* definition. In this context, PM_TOKEN_KEYWORD_DO_BLOCK should not be
* consumed by commands (it should bubble up to the outer context).
*/
bool in_endless_def_body;

/** Whether or not we're currently recovering from a syntax error. */
bool recovering;

Expand Down
1 change: 1 addition & 0 deletions lib/prism/lex_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def deconstruct_keys(keys) # :nodoc:
KEYWORD_DEF: :on_kw,
KEYWORD_DEFINED: :on_kw,
KEYWORD_DO: :on_kw,
KEYWORD_DO_BLOCK: :on_kw,
KEYWORD_DO_LOOP: :on_kw,
KEYWORD_ELSE: :on_kw,
KEYWORD_ELSIF: :on_kw,
Expand Down
1 change: 1 addition & 0 deletions lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Lexer # :nodoc:
KEYWORD_DEF: :kDEF,
KEYWORD_DEFINED: :kDEFINED,
KEYWORD_DO: :kDO,
KEYWORD_DO_BLOCK: :kDO_BLOCK,
KEYWORD_DO_LOOP: :kDO_COND,
KEYWORD_END: :kEND,
KEYWORD_END_UPCASE: :klEND,
Expand Down
231 changes: 182 additions & 49 deletions snapshots/4.0/endless_methods_command_call.txt

Large diffs are not rendered by default.

283 changes: 263 additions & 20 deletions snapshots/blocks.txt

Large diffs are not rendered by default.

168 changes: 126 additions & 42 deletions snapshots/endless_methods.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@ ProgramNode (location: (1,0)-(7,15))
@ ProgramNode (location: (1,0)-(11,18))
├── flags: ∅
├── locals: [:x]
└── statements:
@ StatementsNode (location: (1,0)-(7,15))
@ StatementsNode (location: (1,0)-(11,18))
├── flags: ∅
└── body: (length: 4)
└── body: (length: 6)
├── @ DefNode (location: (1,0)-(1,11))
│ ├── flags: newline
│ ├── name: :foo
Expand Down Expand Up @@ -116,44 +116,128 @@
│ ├── rparen_loc: ∅
│ ├── equal_loc: (5,11)-(5,12) = "="
│ └── end_keyword_loc: ∅
└── @ LocalVariableWriteNode (location: (7,0)-(7,15))
├── @ LocalVariableWriteNode (location: (7,0)-(7,15))
│ ├── flags: newline
│ ├── name: :x
│ ├── depth: 0
│ ├── name_loc: (7,0)-(7,1) = "x"
│ ├── value:
│ │ @ DefNode (location: (7,4)-(7,15))
│ │ ├── flags: ∅
│ │ ├── name: :f
│ │ ├── name_loc: (7,8)-(7,9) = "f"
│ │ ├── receiver: ∅
│ │ ├── parameters: ∅
│ │ ├── body:
│ │ │ @ StatementsNode (location: (7,12)-(7,15))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ CallNode (location: (7,12)-(7,15))
│ │ │ ├── flags: ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :p
│ │ │ ├── message_loc: (7,12)-(7,13) = "p"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (7,14)-(7,15))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ IntegerNode (location: (7,14)-(7,15))
│ │ │ │ ├── flags: static_literal, decimal
│ │ │ │ └── value: 1
│ │ │ ├── closing_loc: ∅
│ │ │ ├── equal_loc: ∅
│ │ │ └── block: ∅
│ │ ├── locals: []
│ │ ├── def_keyword_loc: (7,4)-(7,7) = "def"
│ │ ├── operator_loc: ∅
│ │ ├── lparen_loc: ∅
│ │ ├── rparen_loc: ∅
│ │ ├── equal_loc: (7,10)-(7,11) = "="
│ │ └── end_keyword_loc: ∅
│ └── operator_loc: (7,2)-(7,3) = "="
├── @ DefNode (location: (9,0)-(9,17))
│ ├── flags: newline
│ ├── name: :foo
│ ├── name_loc: (9,4)-(9,7) = "foo"
│ ├── receiver: ∅
│ ├── parameters: ∅
│ ├── body:
│ │ @ StatementsNode (location: (9,10)-(9,17))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ CallNode (location: (9,10)-(9,17))
│ │ ├── flags: ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :bar
│ │ ├── message_loc: (9,10)-(9,13) = "bar"
│ │ ├── opening_loc: ∅
│ │ ├── arguments:
│ │ │ @ ArgumentsNode (location: (9,14)-(9,17))
│ │ │ ├── flags: ∅
│ │ │ └── arguments: (length: 1)
│ │ │ └── @ CallNode (location: (9,14)-(9,17))
│ │ │ ├── flags: variable_call, ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :baz
│ │ │ ├── message_loc: (9,14)-(9,17) = "baz"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ ├── equal_loc: ∅
│ │ │ └── block: ∅
│ │ ├── closing_loc: ∅
│ │ ├── equal_loc: ∅
│ │ └── block: ∅
│ ├── locals: []
│ ├── def_keyword_loc: (9,0)-(9,3) = "def"
│ ├── operator_loc: ∅
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── equal_loc: (9,8)-(9,9) = "="
│ └── end_keyword_loc: ∅
└── @ DefNode (location: (11,0)-(11,18))
├── flags: newline
├── name: :x
├── depth: 0
├── name_loc: (7,0)-(7,1) = "x"
├── value:
│ @ DefNode (location: (7,4)-(7,15))
├── name: :foo
├── name_loc: (11,4)-(11,7) = "foo"
├── receiver: ∅
├── parameters: ∅
├── body:
│ @ StatementsNode (location: (11,10)-(11,18))
│ ├── flags: ∅
── name: :f
── name_loc: (7,8)-(7,9) = "f"
│ ├── receiver: ∅
│ ├── parameters: ∅
│ ├── body:
@ StatementsNode (location: (7,12)-(7,15))
├── flags: ∅
── body: (length: 1)
── @ CallNode (location: (7,12)-(7,15))
├── flags: ignore_visibility
├── receiver: ∅
── call_operator_loc: ∅
── name: :p
│ │ ├── message_loc: (7,12)-(7,13) = "p"
│ │ ├── opening_loc: ∅
│ │ ├── arguments:
@ ArgumentsNode (location: (7,14)-(7,15))
├── flags: ∅
── arguments: (length: 1)
── @ IntegerNode (location: (7,14)-(7,15))
│ ├── flags: static_literal, decimal
── value: 1
│ │ ── closing_loc: ∅
├── equal_loc: ∅
── block: ∅
── locals: []
├── def_keyword_loc: (7,4)-(7,7) = "def"
├── operator_loc: ∅
├── lparen_loc: ∅
├── rparen_loc: ∅
├── equal_loc: (7,10)-(7,11) = "="
│ └── end_keyword_loc: ∅
└── operator_loc: (7,2)-(7,3) = "="
── body: (length: 1)
── @ CallNode (location: (11,10)-(11,18))
├── flags: ignore_visibility
├── receiver: ∅
├── call_operator_loc: ∅
├── name: :bar
├── message_loc: (11,10)-(11,13) = "bar"
── opening_loc: (11,13)-(11,14) = "("
── arguments:
@ ArgumentsNode (location: (11,14)-(11,17))
├── flags: ∅
── arguments: (length: 1)
── @ CallNode (location: (11,14)-(11,17))
│ ├── flags: variable_call, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
├── name: :baz
├── message_loc: (11,14)-(11,17) = "baz"
── opening_loc: ∅
── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ ── equal_loc: ∅
── block: ∅
│ ├── closing_loc: (11,17)-(11,18) = ")"
── equal_loc: ∅
── block: ∅
├── locals: []
├── def_keyword_loc: (11,0)-(11,3) = "def"
├── operator_loc: ∅
├── lparen_loc: ∅
├── rparen_loc: ∅
── equal_loc: (11,8)-(11,9) = "="
└── end_keyword_loc: ∅
Loading