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

The expression /=/ does not get parsed as a regexp #2148

Closed
lxhom opened this issue Jun 28, 2022 · 1 comment
Closed

The expression /=/ does not get parsed as a regexp #2148

lxhom opened this issue Jun 28, 2022 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Good for newcomers lexer Issues surrounding the lexer parser Issues surrounding the parser
Milestone

Comments

@lxhom
Copy link

lxhom commented Jun 28, 2022

Describe the bug
The expression /=/ does not get parsed as a regexp

To Reproduce

let myRegex = /=/;

That throws this: "unexpected token '/=', primary expression at line 1, col 15"

Expected behavior
It should give me the regular expression for a single =. A workaround I used is just using /.{0}=/, but this should work without it.

Build environment (please complete the following information):

(tested it on my machine and on the playground)

  • OS: Windows & Boa Playground
  • Version: 0.15.0 & the playground doesn't tell me
  • Target triple: x86_64-pc-windows-msvc & idk
  • Rustc version: rustc 1.63.0-nightly (7466d5492 2022-06-08)
@lxhom lxhom added the bug Something isn't working label Jun 28, 2022
@Razican Razican added the lexer Issues surrounding the lexer label Jun 29, 2022
@Razican Razican added this to the v0.16.0 milestone Jun 29, 2022
@Razican Razican added the parser Issues surrounding the parser label Jun 29, 2022
@Razican
Copy link
Member

Razican commented Jun 29, 2022

For anyone willing to tackle this, the / token lexing happens here: https://github.com/boa-dev/boa/blob/main/boa_engine/src/syntax/lexer/mod.rs#L128-L187

This checks if the / token is the beginning of a comment (when it's followed by / or *), and if not, it will check the current lexer goal symbol. This is set by the parser, depending on what we're trying to parse.

There are some places where a / will only mean a division element, and others when it can only be a regular expression start. In this case, it seems it goes through the first branch (InputElement::Div | InputElement::TemplateTail), since it will check if the next character is an equal sign (which it is), and then say that we are getting a Punctuator::AssignDiv symbol.

The parser then is surprised, since the assign punctuator already appeared, and therefore, you cannot use the /= symbol.

It seems, that the issue here is that the parser is not properly setting the goal symbol. Once the let myRegex = has been consumed, the goal symbol should not accept the division operation, only the regular expression.

You should be able to follow the documentation in our debugging section to track the issue down, but feel free to ask questions on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers lexer Issues surrounding the lexer parser Issues surrounding the parser
Projects
Status: Done
2 participants