-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add support for sigils containing integers #13448
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
Merged
josevalim
merged 10 commits into
elixir-lang:main
from
starbelly:support-sigils-with-integers
May 17, 2024
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a82d87
Add support for sigils containing integers.
starbelly 0db41e1
Update lib/elixir/src/elixir_tokenizer.erl
starbelly 2d27d8b
Address PR feedback
starbelly 24dd6fa
fix typo in comment
starbelly 5386a96
Update custom sigils docs in getting-stated
starbelly cb4ad3d
align terms
starbelly ed5b1bc
Update lib/elixir/pages/getting-started/sigils.md
starbelly d5e6db9
Update lib/elixir/test/elixir/kernel/parser_test.exs
starbelly 20430ed
Update lib/elixir/src/elixir_tokenizer.erl
josevalim ed78826
Update lib/elixir/src/elixir_tokenizer.erl
josevalim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1559,20 +1559,33 @@ tokenize_sigil([$~ | T], Line, Column, Scope, Tokens) -> | |
end. | ||
|
||
% A one-letter sigil is ok both as upcase as well as downcase. | ||
tokenize_sigil_name([S | T], [], Line, Column, Scope, Tokens) when ?is_upcase(S) orelse ?is_downcase(S) -> | ||
tokenize_sigil_name(T, [S], Line, Column + 1, Scope, Tokens); | ||
tokenize_sigil_name([S | T], [], Line, Column, Scope, Tokens) when ?is_downcase(S) -> | ||
tokenize_lower_sigil_name(T, [S], Line, Column + 1, Scope, Tokens); | ||
tokenize_sigil_name([S | T], [], Line, Column, Scope, Tokens) when ?is_upcase(S) -> | ||
tokenize_upper_sigil_name(T, [S], Line, Column + 1, Scope, Tokens). | ||
|
||
tokenize_lower_sigil_name([S | _T] = Original, [_ | _] = NameAcc, _Line, _Column, _Scope, _Tokens) when ?is_downcase(S) -> | ||
SigilName = lists:reverse(NameAcc) ++ Original, | ||
{error, sigil_name_error(), [$~] ++ SigilName}; | ||
tokenize_lower_sigil_name(T, NameAcc, Line, Column, Scope, Tokens) -> | ||
{ok, lists:reverse(NameAcc), T, Line, Column, Scope, Tokens}. | ||
|
||
% If we have an uppercase letter, we keep tokenizing the name. | ||
tokenize_sigil_name([S | T], NameAcc, Line, Column, Scope, Tokens) when ?is_upcase(S) -> | ||
tokenize_sigil_name(T, [S | NameAcc], Line, Column + 1, Scope, Tokens); | ||
% A digit is allowed but an uppercase letter or digit must proceed it. | ||
tokenize_upper_sigil_name([S | T], NameAcc, Line, Column, Scope, Tokens) when ?is_upcase(S) orelse ?is_digit(S) -> | ||
tokenize_upper_sigil_name(T, [S | NameAcc], Line, Column + 1, Scope, Tokens); | ||
% With a lowercase letter and a non-empty NameAcc we return an error. | ||
tokenize_sigil_name([S | _T] = Original, [_ | _] = NameAcc, _Line, _Column, _Scope, _Tokens) when ?is_downcase(S) -> | ||
Message = "invalid sigil name, it should be either a one-letter lowercase letter or a" ++ | ||
" sequence of uppercase letters only, got: ", | ||
{error, Message, [$~] ++ lists:reverse(NameAcc) ++ Original}; | ||
tokenize_upper_sigil_name([S | _T] = Original, [_ | _] = NameAcc, _Line, _Column, _Scope, _Tokens) when ?is_downcase(S) -> | ||
SigilName = lists:reverse(NameAcc) ++ Original, | ||
{error, sigil_name_error(), [$~] ++ SigilName}; | ||
% We finished the letters, so the name is over. | ||
tokenize_sigil_name(T, NameAcc, Line, Column, Scope, Tokens) -> | ||
tokenize_upper_sigil_name(T, NameAcc, Line, Column, Scope, Tokens) -> | ||
{ok, lists:reverse(NameAcc), T, Line, Column, Scope, Tokens}. | ||
|
||
sigil_name_error() -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be a macro, not sure what the preference here. Likewise, we could just place the error tuple here, but once again, not sure the preference (localization of such things can be valuable). |
||
"invalid sigil name, it should be either a one-letter lowercase letter or a" ++ | ||
" uppercase letter optionally followed by uppercase letters and digits, got: ". | ||
josevalim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tokenize_sigil_contents([H, H, H | T] = Original, [S | _] = SigilName, Line, Column, Scope, Tokens) | ||
when ?is_quote(H) -> | ||
case extract_heredoc_with_interpolation(Line, Column, Scope, ?is_downcase(S), T, H) of | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.