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

ParserSyntaxError on from foo import (bar \n as baz) #530

Open
Zac-HD opened this issue Oct 11, 2021 · 4 comments
Open

ParserSyntaxError on from foo import (bar \n as baz) #530

Zac-HD opened this issue Oct 11, 2021 · 4 comments
Labels
bug Something isn't working parsing Converting source code into CST nodes

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Oct 11, 2021

import libcst as cst

code = """
from math import (nan
  as NaN)
"""
compile(code, "<string>", "exec")  # (no error)

cst.parse_module(code)             # ParserSyntaxError: Syntax Error @ 4:9.
                                   # Internal error: There must be at least one space before 'as'.

While this is really weird code, it does actually happen in the wild, e.g. here in the regex package.

@zsol zsol added the bug Something isn't working label Oct 11, 2021
@zsol
Copy link
Member

zsol commented Oct 11, 2021

Looks like this works with the new rust-based parser, so I likely won't fix it in the current one:

git checkout parser
cd native
printf 'from foo import (bar\n  as baaaar)' | cargo run

@zsol
Copy link
Member

zsol commented Dec 20, 2021

#566 contains the new parser that works with this input. After merging that, you'll need to set the following environment variable LIBCST_PARSER_TYPE=native in whatever process that runs libcst to turn on the new parser (this will be the default in a future release)

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Feb 3, 2022

Any indication of when the native parser will be enabled by default?

@zsol
Copy link
Member

zsol commented Feb 4, 2022

I'm aiming for a month or two. The parser is fairly stable at this point, and it's used to parse hundreds of millions of lines of Python at Meta. It's mostly a question of feature-completeness, the biggest gap being support for different versions of the Python grammar (these fields).

@zsol zsol added the parsing Converting source code into CST nodes label Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parsing Converting source code into CST nodes
Projects
None yet
Development

No branches or pull requests

2 participants