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

Fix tokenize bug of #8590 #8591

Merged
merged 4 commits into from Jan 4, 2019

Conversation

LostKobrakai
Copy link
Contributor

No description provided.

# token and, if so, it is not followed by an "end"
# token. If this is the case, we are on a start expr.
case :elixir_tokenizer.tokenize(rest, 1, file: "eex", check_terminators: false) do
{:ok, tokens} ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LostKobrakai!

I have cleaned up your commit a bit and then I noticed that your implementation actually has a bug. It will match if the code starts with a variable named endgame, for example.

I think that instead of looking at the buffer, you should look if the first token is the end token. It will be the same result, except you will rely on the Elixir tokenizer to handle it properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'll take a look at it. I wasn't really sure how the elixir_tokenizer behaves, so I tried to stay clear of it :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone and replace the check with looking at the results of the tokenizer and added the same improvements to tokens ending in do %>

@@ -154,6 +158,13 @@ defmodule EEx.Tokenizer do
:expr
end

# Tokenize the remaining passing check_terminators as false,
# which relax the tokenizer to not error on unmatched pairs.
# If the tokens start with an "end" we have a middle expr.
Copy link
Member

@fertapric fertapric Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the last comment line (If the tokens start with an "end" we have a middle expr.) or move it before the pattern matching (although it's a bit redundant).

Suggested change
# If the tokens start with an "end" we have a middle expr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it is still relevant info for the callers of this function. :)

@josevalim josevalim merged commit 74ca2ac into elixir-lang:master Jan 4, 2019
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants