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] Return token in Lezer parser only when it applies #4898

Merged
merged 11 commits into from
Dec 18, 2023

Conversation

jpelay
Copy link
Member

@jpelay jpelay commented Dec 12, 2023

Description

On Spanish, Bulgarian, and possibly other languages, there was an error when highlighting for commands, because in these languages the word for in and at is the same. This PR fixes that and also fixes it in other possible occurrences of the same problem by only returning the token if the parser can shift the state were the token be accepted, for example take into consideration the following code of level 10:

para animal en animales
    imprimir animal

The English version of this program is:

for animal in animales
    print animal

When the parser reaches the token en, the stack already has: [For, Text]. Then it iterates through every keyword relevant for this level in the highlighting.json dictionary and asks: Does en matches the regex for the current keyword? If it does, it then asks, can the parser shifts if I accept this token? If the answer is yes, it is accepted, if it ins't it continues to the next token, and finishes when it finds one that it can accept or it returns -1, in the case than none is accepted.

The problem was in this last step: we didn't ask if the parser would be in a good state if we accepted the token, resulting in accepting the first token that was found.

Fixes #4772

How to test

Go to level 12, set the language to Spanish and write:

para nombre en nombres
    imprimir nombre ' pertenece a ' casas en aleatorio
    imprimir nombre ' es mejor en ' asignaturas en aleatorio
    imprimir nombre ' su gran miedo es ' miedos en aleatorio

@jpelay jpelay requested a review from Felienne December 12, 2023 16:26
@jpelay jpelay changed the title [FIX] [FIX] Return token in Lezer parser only when it applies Dec 12, 2023
@jpelay
Copy link
Member Author

jpelay commented Dec 12, 2023

This break nested ifs :(

image

@jpelay
Copy link
Member Author

jpelay commented Dec 12, 2023

I think for this to move forward I need to fix the grammar a bit, and handle indentation properly.

@jpelay jpelay marked this pull request as draft December 12, 2023 22:09
@jpelay jpelay marked this pull request as ready for review December 15, 2023 20:32
@jpelay
Copy link
Member Author

jpelay commented Dec 16, 2023

@Felienne This PR is ready now! I also added some tests for levels 5, 6 and 7, please take a look whenever you want

Copy link
Member

@Felienne Felienne left a comment

Choose a reason for hiding this comment

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

Works!

image

Copy link
Contributor

mergify bot commented Dec 18, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 96e6890 into hedyorg:main Dec 18, 2023
9 checks passed
Copy link
Contributor

mergify bot commented Dec 18, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

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

Successfully merging this pull request may close these issues.

[BUG] to keyword not being highlighted correctly in Spanish
2 participants