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

Error when parse lego.parse('[\S]') or similar regex #35

Closed
uynil opened this issue Jan 25, 2018 · 1 comment · Fixed by #67
Closed

Error when parse lego.parse('[\S]') or similar regex #35

uynil opened this issue Jan 25, 2018 · 1 comment · Fixed by #67
Assignees

Comments

@uynil
Copy link

uynil commented Jan 25, 2018

When I parse regex like [\S], it will give error like

>>> lego.parse('[\S\s]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yyy/.pyenv/versions/xx/lib/python3.6/site-packages/greenery/lego.py", line 68, in parse
    return pattern.parse(string)
  File "/Users/yy/.pyenv/versions/xx/lib/python3.6/site-packages/greenery/lego.py", line 244, in parse
    raise Exception("Could not parse '" + string + "' beyond index " + str(i))
Exception: Could not parse '[\S\s]' beyond index 0
@qntm
Copy link
Owner

qntm commented Jan 25, 2018

Yeah, negated shorthands \D, \W and \S are not recognised inside a charclass. This would have been fiddly but maybe I'll implement it sometime. Fortunately there is a trivial workaround, instead of writing [\S] just write [^\s] or \S, and instead of writing [\S\s] just write .. If you have something more complex like [\Wdef], render it as \W|[def] and then do what greenery is designed to do:

>>> from greenery import lego
>>> str(lego.parse('\\W|[def]').reduce())
'[^0-9A-Z_abcg-z]'

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

Successfully merging a pull request may close this issue.

2 participants