Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexer: fix global capture vars ending with zero, e.g. $10? #12701

Merged
merged 1 commit into from
Nov 1, 2022
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
4 changes: 3 additions & 1 deletion spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ describe "Lexer" do
":^", ":~", ":**", ":>>", ":<<", ":%", ":[]", ":[]?", ":[]=", ":<=>", ":===",
":&+", ":&-", ":&*", ":&**"]

it_lexes_global_match_data_index ["$1", "$10", "$1?", "$23?"]
it_lexes_global_match_data_index ["$1", "$10", "$1?", "$10?", "$23?"]
assert_syntax_error "$01", %(unexpected token: "1")
assert_syntax_error "$0?"

it_lexes "$~", :OP_DOLLAR_TILDE
it_lexes "$?", :OP_DOLLAR_QUESTION
Expand Down
11 changes: 5 additions & 6 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,13 @@ module Crystal
@token.type = :OP_DOLLAR_QUESTION
when .ascii_number?
start = current_pos
char = next_char
if char == '0'
char = next_char
if current_char == '0'
next_char
else
while char.ascii_number?
char = next_char
while next_char.ascii_number?
# Nothing to do
end
char = next_char if char == '?'
next_char if current_char == '?'
end
@token.type = :GLOBAL_MATCH_DATA_INDEX
@token.value = string_range_from_pool(start)
Expand Down