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 @@ -496,6 +496,8 @@ tokens:
comment: "defined?"
- name: KEYWORD_DO_BLOCK
comment: "do keyword for a block attached to a command"
- name: KEYWORD_DO_LAMBDA
comment: "do keyword that opens the body of a lambda literal"
- name: KEYWORD_DO_LOOP
comment: "do keyword for a predicate in a while, until, or for loop"
- name: KEYWORD_END_UPCASE
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 @@ -141,6 +141,7 @@ def deconstruct_keys(keys) # :nodoc:
KEYWORD_DEFINED: :on_kw,
KEYWORD_DO: :on_kw,
KEYWORD_DO_BLOCK: :on_kw,
KEYWORD_DO_LAMBDA: :on_kw,
KEYWORD_DO_LOOP: :on_kw,
KEYWORD_ELSE: :on_kw,
KEYWORD_ELSIF: :on_kw,
Expand Down
19 changes: 2 additions & 17 deletions lib/prism/translation/parser/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Lexer # :nodoc:
KEYWORD_DEFINED: :kDEFINED,
KEYWORD_DO: :kDO,
KEYWORD_DO_BLOCK: :kDO_BLOCK,
KEYWORD_DO_LAMBDA: :kDO_LAMBDA,
KEYWORD_DO_LOOP: :kDO_COND,
KEYWORD_END: :kEND,
KEYWORD_END_UPCASE: :klEND,
Expand Down Expand Up @@ -192,14 +193,6 @@ 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`.
#
# 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`.
Expand All @@ -221,7 +214,7 @@ class Lexer # :nodoc:
# Heredocs are complex and require us to keep track of a bit of info to refer to later
HeredocData = Struct.new(:identifier, :common_whitespace, keyword_init: true)

private_constant :TYPES, :EXPR_BEG, :EXPR_LABEL, :LAMBDA_TOKEN_TYPES, :LPAREN_CONVERSION_TOKEN_TYPES, :HeredocData
private_constant :TYPES, :EXPR_BEG, :EXPR_LABEL, :LPAREN_CONVERSION_TOKEN_TYPES, :HeredocData

# The Parser::Source::Buffer that the tokens were lexed from.
attr_reader :source_buffer
Expand Down Expand Up @@ -269,14 +262,6 @@ def to_a
location = range(token.location.start_offset, token.location.end_offset)

case type
when :kDO
nearest_lambda_token = tokens.reverse_each.find do |token|
LAMBDA_TOKEN_TYPES.include?(token.first)
end

if nearest_lambda_token&.first == :tLAMBDA
type = :kDO_LAMBDA
end
when :tCHARACTER
value.delete_prefix!("?")
# Character literals behave similar to double-quoted strings. We can use the same escaping mechanism.
Expand Down
Loading
Loading