Skip to content
Open
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
22 changes: 15 additions & 7 deletions lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,25 @@ class Lexer # :nodoc:
EXPR_BEG = 0x1
EXPR_LABEL = 0x400

# It is used to determine whether `do` is of the token type `kDO` or `kDO_LAMBDA`.
# It is used to determine whether `do` is of the token type `kDO` or
# `kDO_LAMBDA`.
#
# NOTE: In edge cases like `-> (foo = -> (bar) {}) do end`, please note that `kDO` is still returned
# instead of `kDO_LAMBDA`, which is expected: https://github.com/ruby/prism/pull/3046
# NOTE: In edge cases like `-> (foo = -> (bar) {}) do end`, please note
# that `kDO` is still returned instead of `kDO_LAMBDA`, which is
# expected: https://github.com/ruby/prism/pull/3046
LAMBDA_TOKEN_TYPES = Set.new([:kDO_LAMBDA, :tLAMBDA, :tLAMBEG])

# The `PARENTHESIS_LEFT` token in Prism is classified as either `tLPAREN` or `tLPAREN2` in the Parser gem.
# The following token types are listed as those classified as `tLPAREN`.
# The `PARENTHESIS_LEFT` token in Prism is classified as either
# `tLPAREN` or `tLPAREN2` in the Parser gem. 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, :tLCURLY
:kAND, :kBEGIN, :kBREAK, :kCASE, :kDO_COND, :kDO_LAMBDA, :kDO, :kELSE,
:kELSIF, :kENSURE, :kFOR, :kIF_MOD, :kIF, :kIN, :kNEXT, :kOR,
:kRESCUE_MOD, :kRESCUE, :kRETURN, :kTHEN, :kUNLESS_MOD, :kUNLESS,
:kUNTIL_MOD, :kUNTIL, :kWHEN, :kWHILE_MOD, :kWHILE,
:tAMPER, :tANDOP, :tBANG, :tCARET, :tCOMMA, :tDIVIDE, :tDOT2, :tDOT3,
:tEQL, :tLCURLY, :tLPAREN_ARG, :tLPAREN, :tLPAREN2, :tLSHFT, :tNL,
:tOP_ASGN, :tOROP, :tPIPE, :tSEMI, :tSTRING_DBEG, :tUMINUS, :tUPLUS
])

# Types of tokens that are allowed to continue a method call with comments in-between.
Expand Down
156 changes: 156 additions & 0 deletions snapshots/rescue_modifier_assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
@ ProgramNode (location: (1,0)-(3,23))
├── flags: ∅
├── locals: [:x, :y, :a, :b, :c]
└── statements:
@ StatementsNode (location: (1,0)-(3,23))
├── flags: ∅
└── body: (length: 3)
├── @ MultiWriteNode (location: (1,0)-(1,24))
│ ├── flags: newline
│ ├── lefts: (length: 2)
│ │ ├── @ LocalVariableTargetNode (location: (1,0)-(1,1))
│ │ │ ├── flags: ∅
│ │ │ ├── name: :x
│ │ │ └── depth: 0
│ │ └── @ LocalVariableTargetNode (location: (1,3)-(1,4))
│ │ ├── flags: ∅
│ │ ├── name: :y
│ │ └── depth: 0
│ ├── rest: ∅
│ ├── rights: (length: 0)
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── operator_loc: (1,5)-(1,6) = "="
│ └── value:
│ @ RescueModifierNode (location: (1,7)-(1,24))
│ ├── flags: ∅
│ ├── expression:
│ │ @ IntegerNode (location: (1,7)-(1,8))
│ │ ├── flags: static_literal, decimal
│ │ └── value: 1
│ ├── keyword_loc: (1,9)-(1,15) = "rescue"
│ └── rescue_expression:
│ @ MultiWriteNode (location: (1,16)-(1,24))
│ ├── flags: ∅
│ ├── lefts: (length: 2)
│ │ ├── @ LocalVariableTargetNode (location: (1,16)-(1,17))
│ │ │ ├── flags: ∅
│ │ │ ├── name: :a
│ │ │ └── depth: 0
│ │ └── @ LocalVariableTargetNode (location: (1,19)-(1,20))
│ │ ├── flags: ∅
│ │ ├── name: :b
│ │ └── depth: 0
│ ├── rest: ∅
│ ├── rights: (length: 0)
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── operator_loc: (1,21)-(1,22) = "="
│ └── value:
│ @ IntegerNode (location: (1,23)-(1,24))
│ ├── flags: static_literal, decimal
│ └── value: 1
├── @ MultiWriteNode (location: (2,0)-(2,24))
│ ├── flags: newline
│ ├── lefts: (length: 2)
│ │ ├── @ LocalVariableTargetNode (location: (2,0)-(2,1))
│ │ │ ├── flags: ∅
│ │ │ ├── name: :x
│ │ │ └── depth: 0
│ │ └── @ LocalVariableTargetNode (location: (2,3)-(2,4))
│ │ ├── flags: ∅
│ │ ├── name: :y
│ │ └── depth: 0
│ ├── rest: ∅
│ ├── rights: (length: 0)
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── operator_loc: (2,5)-(2,6) = "="
│ └── value:
│ @ RescueModifierNode (location: (2,7)-(2,24))
│ ├── flags: ∅
│ ├── expression:
│ │ @ LocalVariableReadNode (location: (2,7)-(2,8))
│ │ ├── flags: ∅
│ │ ├── name: :a
│ │ └── depth: 0
│ ├── keyword_loc: (2,9)-(2,15) = "rescue"
│ └── rescue_expression:
│ @ MultiWriteNode (location: (2,16)-(2,24))
│ ├── flags: ∅
│ ├── lefts: (length: 2)
│ │ ├── @ LocalVariableTargetNode (location: (2,16)-(2,17))
│ │ │ ├── flags: ∅
│ │ │ ├── name: :b
│ │ │ └── depth: 0
│ │ └── @ LocalVariableTargetNode (location: (2,19)-(2,20))
│ │ ├── flags: ∅
│ │ ├── name: :c
│ │ └── depth: 0
│ ├── rest: ∅
│ ├── rights: (length: 0)
│ ├── lparen_loc: ∅
│ ├── rparen_loc: ∅
│ ├── operator_loc: (2,21)-(2,22) = "="
│ └── value:
│ @ IntegerNode (location: (2,23)-(2,24))
│ ├── flags: static_literal, decimal
│ └── value: 1
└── @ MultiWriteNode (location: (3,0)-(3,23))
├── flags: newline
├── lefts: (length: 2)
│ ├── @ LocalVariableTargetNode (location: (3,0)-(3,1))
│ │ ├── flags: ∅
│ │ ├── name: :x
│ │ └── depth: 0
│ └── @ LocalVariableTargetNode (location: (3,3)-(3,4))
│ ├── flags: ∅
│ ├── name: :y
│ └── depth: 0
├── rest: ∅
├── rights: (length: 0)
├── lparen_loc: ∅
├── rparen_loc: ∅
├── operator_loc: (3,5)-(3,6) = "="
└── value:
@ RescueModifierNode (location: (3,7)-(3,23))
├── flags: ∅
├── expression:
│ @ LocalVariableReadNode (location: (3,7)-(3,8))
│ ├── flags: ∅
│ ├── name: :a
│ └── depth: 0
├── keyword_loc: (3,9)-(3,15) = "rescue"
└── rescue_expression:
@ LocalVariableWriteNode (location: (3,16)-(3,23))
├── flags: ∅
├── name: :b
├── depth: 0
├── name_loc: (3,16)-(3,17) = "b"
├── value:
│ @ CallNode (location: (3,20)-(3,23))
│ ├── flags: ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :c
│ ├── message_loc: (3,20)-(3,21) = "c"
│ ├── opening_loc: ∅
│ ├── arguments:
│ │ @ ArgumentsNode (location: (3,22)-(3,23))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ CallNode (location: (3,22)-(3,23))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :d
│ │ ├── message_loc: (3,22)-(3,23) = "d"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ ├── equal_loc: ∅
│ │ └── block: ∅
│ ├── closing_loc: ∅
│ ├── equal_loc: ∅
│ └── block: ∅
└── operator_loc: (3,18)-(3,19) = "="
Loading
Loading