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

Incorrectly parsing escape char in raw string (eg: \{) #462

Closed
rodrigozhou opened this issue Mar 10, 2021 · 2 comments · Fixed by #466
Closed

Incorrectly parsing escape char in raw string (eg: \{) #462

rodrigozhou opened this issue Mar 10, 2021 · 2 comments · Fixed by #466

Comments

@rodrigozhou
Copy link
Contributor

LibCST v0.3.17 is raising an exception when parsing this valid code:

a = "'"
print(fr"\{a}")

Stack trace:

Traceback (most recent call last):
  File ".../libcst/_parser/base_parser.py", line 152, in _add_token
    plan = stack[-1].dfa.transitions[transition]
KeyError: ReservedString(})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../libcst/tool.py", line 832, in <module>
    main(os.environ.get("LIBCST_TOOL_COMMAND_NAME", "libcst.tool"), sys.argv[1:])
  File ".../libcst/tool.py", line 827, in main
    return lookup.get(args.action or None, _invalid_command)(proc_name, command_args)
  File ".../libcst/tool.py", line 272, in _print_tree_impl
    tree = parse_module(
  File ".../libcst/_parser/entrypoints.py", line 71, in parse_module
    result = _parse(
  File ".../libcst/_parser/entrypoints.py", line 51, in _parse
    result = parser.parse()
  File ".../libcst/_parser/base_parser.py", line 111, in parse
    self._add_token(token)
  File ".../libcst/_parser/base_parser.py", line 187, in _add_token
    raise ParserSyntaxError(
libcst._exceptions.ParserSyntaxError: Syntax Error @ 29:17.
Incomplete input. Encountered '}', but expected 'FSTRING_END', 'FSTRING_STRING', or '{'.

My guess is LibCST is escaping "\{", but it wasn't supposed to escape since it's a raw string.

@rodrigozhou rodrigozhou changed the title Raw string parsing escaping \{ Raw string parsing escape char (eg: \{) Mar 10, 2021
@rodrigozhou rodrigozhou changed the title Raw string parsing escape char (eg: \{) Incorrectly parting escape char in raw string (eg: \{) Mar 10, 2021
@rodrigozhou rodrigozhou changed the title Incorrectly parting escape char in raw string (eg: \{) Incorrectly parsing escape char in raw string (eg: \{) Mar 10, 2021
thatch added a commit to thatch/LibCST that referenced this issue Mar 13, 2021
@thatch
Copy link
Contributor

thatch commented Mar 13, 2021

Bisect says I introduced this in 02fc440 which probably means it's broken in parso as well. See #466

@zsol zsol linked a pull request Mar 29, 2021 that will close this issue
@zsol
Copy link
Member

zsol commented Mar 29, 2021

This should be fixed by #466.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants