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

from_lark fails for grammars with complex regexps #1786

Closed
erezsh opened this issue Feb 1, 2019 · 1 comment
Closed

from_lark fails for grammars with complex regexps #1786

erezsh opened this issue Feb 1, 2019 · 1 comment
Assignees
Labels
bug something is clearly wrong here

Comments

@erezsh
Copy link
Contributor

erezsh commented Feb 1, 2019

I tried to generate an example of Python code, by loading Lark's builtin Python3 grammar, but I think it failed to generate one of the regexps.

import hypothesis.extra.lark

h = hypothesis.extra.lark.from_lark(Lark.open('lark/examples/python3.lark', start='file_input')) 

h.example()

Results in the exception:

  File ".local/lib/python3.6/site-packages/hypothesis/searchstrategy/regex.py", line 185, in add_char
    if self._ignorecase and re.match(c, c.swapcase(), re.IGNORECASE) is not None:
  File "/usr/lib64/python3.6/re.py", line 172, in match
    return _compile(pattern, flags).match(string)
  File "/usr/lib64/python3.6/re.py", line 301, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib64/python3.6/sre_compile.py", line 562, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib64/python3.6/sre_parse.py", line 855, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib64/python3.6/sre_parse.py", line 416, in _parse_sub
    not nested and not items))
  File "/usr/lib64/python3.6/sre_parse.py", line 616, in _parse
    source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 0
nothing to repeat at position 0

Btw, this isn't high-priority. I just found it while playing around, and thought you might want to know.

@Zac-HD Zac-HD added legibility make errors helpful and Hypothesis grokable bug something is clearly wrong here and removed legibility make errors helpful and Hypothesis grokable labels Feb 2, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Feb 2, 2019

Turns out that in a few places we're treating character literals as regular expressions, and of course there are some single characters that are not valid regex - here's the minimal example:

from_regex(re.compile('\\\\', flags=re.IGNORECASE)).example()

Thanks for reporting this - we definitely want to know about any bugs you find and will get a fix out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

No branches or pull requests

2 participants