-
-
Notifications
You must be signed in to change notification settings - Fork 406
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
Hashbang lexer support #1631
Hashbang lexer support #1631
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I went and had a look at the remaining failing 262 tests for this.
Some of them are failing because of other missing features. But I think I found three that should work. Maybe you could take a look at those and see why they are still failing? It may be another reason, just to be sure we are not missing anything.
https://github.com/tc39/test262/blob/10ad4c159328d12ad8d12b95a8f8aefa0e4fd49b/test/language/comments/hashbang/line-terminator-line-separator.js
https://github.com/tc39/test262/blob/10ad4c159328d12ad8d12b95a8f8aefa0e4fd49b/test/language/comments/hashbang/line-terminator-paragraph-separator.js
https://github.com/tc39/test262/blob/10ad4c159328d12ad8d12b95a8f8aefa0e4fd49b/test/language/comments/hashbang/use-strict.js
I think the failing tests are because the lexer is considering only '\n' and '\r' as EOL, but the spec considers a lot more characters as EOL (https://tc39.es/ecma262/#prod-LineTerminator). We should probably implement a new |
A LineTerminator tokenizer seemed to be what I was seeing in ECMAScript when I was looking through. Just wasn't sure how big of a change that was though. I can try to push forward adding something like that if you want. In the meantime, I readjusted the existing Hashbang.lex to catch the Paragraph Separator (u2029) and Line Separator (u2028) that it was missing before. |
Great! This PR is okay as it is, we can change it when we have a |
Test262 conformance changes:
Fixed tests (2):
|
We should try to fix all the possible tests in the hashbang suite, I think |
Sorry if I'm missing something (still new to the test262 running and not sure where to see the results on the pull request). What tests are we still missing in the hashbang suite? If I'm reading this right, not-empty.js was fixed but not the other tests, correct? |
You can check https://github.com/boa-dev/boa/blob/master/CONTRIBUTING.md#testing to see how to run specific tests. In you case, the suit you would want to run is |
Test262 conformance changes:
Fixed tests (8):
|
Looks like the consuming of the LineTerminator character was the issue. This was passing 46 tests and failed 10 for conformance of 79, when I was running the tests. The rest of the failed tests seem to be linked to hashbangs in function evaluator contexts and eval calls, which I may need some direction on where to look for that if I should be trying to close those out. Is that still in the lexer? |
We currently do not have |
I think that leaves most of the tests. Of the last tests left, the only one that should work that seems to not be is use-strict. I don't know what's causing this one to not pass though since anything that is inside the hashbang is considered a comment, so it shouldn't generate the DirectivePrologues as stated. Does anybody happen to have suggestions on where I should look. |
I think a good method to check whats going on would be to write a test for the parser here: https://github.com/boa-dev/boa/blob/main/boa/src/syntax/parser/tests.rs We have some methods for checking if the expected AST nodes are parsed. For example this test passes: #[test]
fn empty_comment() {
check_parser(
r"
// Some Comment;
",
vec![],
);
} You could write a test that mirrors the 262 test and see if the AST is expected (no AST because it should be a comment). |
So I put together and ran some tests. This hashbang implementation does successfully lex the "use strict" portion of the hashbang test as far as I can tell, but it fails to parse the with statement. It looks like Keyword::With is hitting the last arm of PrimaryExpression, and throwing a ParsingError. |
Ah that's right we don't have With that I would say this feature is complete as all others tests depend on unimplemented features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
You can run |
Thanks! I've been trying to figure it out for a minute. There's so many features of Rust I've been using on these PRs that I hadn't on my personal projects. |
@jedel1043. Question for you. I just realized something that could pass more of the comment tests in the MultiLineComment lexer. I tried out the change and it increases the conformance from 75% to 80% in the comments test. Should I add that change to this Pull Request or would it be better to make another Pull Request? |
If the change is relatively small, you can add it here :) |
Changes went from: To: |
Test262 conformance changes:
Fixed tests (14):
Broken tests (4):
|
return Err(Error::syntax( | ||
"unterminated multiline comment", | ||
cursor.pos(), | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests now fail because this error is missing on the new commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah shoot, I'll work that back in.
Test262 conformance changes:
Fixed tests (14):
|
No regressing tests :) |
This Pull Request fixes/closes #1555.
Please see the below. There's definitely a couple ways and might needs some revisions/further functionality, but I thought it might be best to get feedback. I initially went to implement the Hashbang support in new. But it made less sense as I was dealing with Result returns, and it felt like the better approach was to implement Hashbang similar to single line and multiline comments.
It changes the following: