maekawatoshiki / rapidus

ECMAScript implementation in Rust
MIT License
519 stars 21 forks source link

Parsing problem for an arrow function. #40

Closed sisshiki1969 closed 5 years ago

sisshiki1969 commented 5 years ago

In ECMA spec, an ArrowFunction is a variant of an AssignmentExpression. But in rapidus, an arrow function is parsed as a variant of a primary expression. Thus, the parser can not detect a syntax error in such a code as follows.

let i = 1 + (x) => x   // no error
let j = (x) => { return x } + 1   // no error
maekawatoshiki commented 5 years ago

Since https://github.com/maekawatoshiki/rapidus/commit/6092927c3b6e979cfb646f745cf68a5580e5c769,

let i = 1 + (x) => x 

causes error. The other one doesn't, though.

maekawatoshiki commented 5 years ago

Since https://github.com/maekawatoshiki/rapidus/commit/ae3ef536659533a1a4bba99e7fdb3d7f35b77454, all the examples you show cause syntax error. In addition: since 747e4e43357568d5293da533659170468902e0ea, test error fixed.

maekawatoshiki commented 5 years ago

However my code looks so horrible. Do you have any idea to simplify my code?

LuoZijun commented 5 years ago

Maybe u can use my parser, but not finished yet:D https://github.com/LuoZijun/es/tree/master/src/parser

maekawatoshiki commented 5 years ago

@LuoZijun It seems I can get some hints from your code. Thank you.

LuoZijun commented 5 years ago

@maekawatoshiki

It's not easy to implement a complete ECMAScript language parser, and there's too much work to do:)

sisshiki1969 commented 5 years ago

The syntax of arrow function "(a, b, c) => {}" is very similar to that of ParenthesizedExpression with comma operator "(a, b, c)", which is a variant of PrimaryExpression. Thus, a backtracking in parser is inevitable. I am trying to modify the lexer to suit backtracking.

https://tc39.github.io/ecma262/#prod-CoverParenthesizedExpressionAndArrowParameterList https://tc39.github.io/ecma262/#prod-ArrowParameters