Skip to content

Commit

Permalink
+ Added lexing for "beginless range" (bdots).
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 13014]
  • Loading branch information
zenspider committed Jan 30, 2021
1 parent 03cc8a9 commit 2d19d4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/ruby_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class RubyLexer

HAS_ENC = "".respond_to? :encoding

BTOKENS = {
".." => :tBDOT2,
"..." => :tBDOT3,
}

TOKENS = {
"!" => :tBANG,
"!=" => :tNEQ,
Expand Down Expand Up @@ -131,6 +136,10 @@ def end_of_stream?
ss.eos?
end

def expr_beg?
lex_state =~ EXPR_BEG
end

def expr_dot?
lex_state =~ EXPR_DOT
end
Expand Down Expand Up @@ -580,6 +589,12 @@ def process_colon2 text
end
end

def process_dots text
tokens = ruby27plus? && expr_beg? ? BTOKENS : TOKENS

result EXPR_BEG, tokens[text], text
end

def process_float text
rb_compile_error "Invalid numeric format" if text =~ /__/

Expand Down Expand Up @@ -1136,6 +1151,10 @@ def ruby24minus?
parser.class.version <= 24
end

def ruby27plus?
parser.class.version >= 27
end

def scan re
ss.scan re
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lexer.rex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rule
| /\![=~]?/ { result :arg_state, TOKENS[text], text }
: /\./
| /\.\.\.?/ { result EXPR_BEG, TOKENS[text], text }
| /\.\.\.?/ process_dots
| /\.\d/ { rb_compile_error "no .<digit> floating literal anymore put 0 before dot" }
| /\./ { self.lex_state = EXPR_BEG; result EXPR_DOT, :tDOT, "." }
Expand Down

0 comments on commit 2d19d4e

Please sign in to comment.