-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
New parser fixes tests failing against #281 #283
Conversation
Let me know if there’s anyway I can help, not picked up anything yet. |
I fixed this particular error. It turns out that it was reading new lines and not skipping them, so it didn't understand that this was a variable declaration. But I found a new one:
|
Interesting, I’m already getting the feeling this parser is easier to reason with than before. Hope I haven’t spoke too soon. Update this thread if you sort it, if not I’ll take a look |
Also, update documentation. Co-Authored-By: HalidOdat <halidodat@gmail.com>
Cool, this seems to fix this one too. I got a new one with this code: function comp(a) {
return a == "a";
}
var many = ["a", "b", "c"]; It gives:
You can try it by running I'm also getting a panic when running another test, so I'm guessing there is something else wrong here:
I think we are messing things too much with so much "peek" or "next_if" and so on. Maybe this could be simplified? It seems to give a lot of of-by-one issues, among others. Maybe one options is to implement or to at least mimic the For many of our needs, we could use the |
I do want to do this, and was attempting to do this previously but ran into some issues, so i put it on the back burner for now (i think because some methods want to go backwards etc). You can see that i made a start by abstracting over This should make it easy to migrate to an iterator in future |
Yeah we need to be on the same mental model for this. |
There is a bug when parsing function declarations in function: self.expect(
TokenKind::Punctuator(Punctuator::OpenBracket),
"expected '{'",
)?; It should be: self.expect(
TokenKind::Punctuator(Punctuator::OpenBlock),
"expected '{'",
)?; |
I added the fix by @HalidOdat and now that seems to work. Still, it seems that it gets stuck in some kind of infinite loop. So I will put this as ready for review, but we need to check that. |
Looks good to me. Edit: im guessing the function comp(a) {
return a == "a";
}
var many = ["a", "b", "c"]; plus some tests. |
Its from the var empty = [];
var array = [11, 23, 45];
function callback(element) {
return element > 10;
}
function callback2(element) {
return element < 10;
}
var appendArray = [1, 2, 3, 4];
function appendingCallback(elem, index, arr) {
arr.push('new');
return elem !== "new";
} I'm not sure exactly what part of this code causes the infinite loop. |
Would be nice if there's some way of logging each state it ends up in without affecting production builds at all. |
This code also goes in an infinite loop. var empty = [ ];
var one = ["a"];
var many = ["a", "b", "c"];
var duplicates = ["a", "b", "c", "a", "b"]; I am confused were the origin of the bug is. 😕 |
For Call Stack
Im stepping through using lldb Edit: It might be quicker to just change the implementation of |
If we merged this back into the main parser branch i can fix peek and that should fix quite a few errors |
Sure, let's merge this and keep working on the other branch :) |
The bug that causes the infinite looping is in the function fn variable_declaration_continuation(&mut self) -> Result<bool, ParseError> {
let mut newline_found = false;
loop {
match self.get_current_token() { // <----
Ok(tok) => match tok.kind {
TokenKind::LineTerminator => newline_found = true,
TokenKind::Punctuator(Punctuator::Semicolon) => {
return Ok(false);
}
TokenKind::Punctuator(Punctuator::Comma) => {
return Ok(true);
}
_ if newline_found => return Ok(false),
_ => break,
},
Err(_) => return Ok(false),
}
self.pos += 1; // <-----
}
Err(ParseError::Expected(
vec![
TokenKind::Punctuator(Punctuator::Semicolon),
TokenKind::LineTerminator,
],
self.get_current_token()?,
"variable declaration",
))
} Now it does not cause an infinite loop.
WERE HALF WAY THERE!!! 😀 |
I have ported #261 to the new parser (#281) (this should close #261). And I'm working on fixing the tests that don't pass. I'm getting this error:
When parsing:
So, I'll try to fix that variable creation tomorrow if possible. Feel free to add suggestions.