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

Different behavior for single and double quotes #66

Open
jakevdp opened this issue Oct 4, 2016 · 1 comment
Open

Different behavior for single and double quotes #66

jakevdp opened this issue Oct 4, 2016 · 1 comment

Comments

@jakevdp
Copy link

jakevdp commented Oct 4, 2016

I came across a bug that was rooted in what seems to be a curious feature of Parsley: changing from single to double quotes leads to a parsing error:

import sys
print(sys.version_info)
# sys.version_info(major=3, minor=5, micro=1, releaselevel='final', serial=0)

import parsley
print(parsley.__version__)
#1.3

grammar = parsley.makeGrammar("""
add = <digit+>:left sp "+" sp add:right -> ('add', left, right)
      | <digit+>:child                  -> child

sp = ' '*
""", {})

grammar('4 + 3').add()
# ('add', '4', '3')

But if we change sp = ' '* to sp = " "* and keep everything else constant, we get an error:

grammar = parsley.makeGrammar("""
add = <digit+>:left sp "+" sp add:right -> ('add', left, right)
      | <digit+>:child                  -> child

sp = " "*
""", {})

grammar('4 + 3').add()
---------------------------------------------------------------------------
ParseError                                Traceback (most recent call last)
<ipython-input-20-5d4b7ce9eeba> in <module>()
      6 """, {})
      7 
----> 8 grammar('4 + 3').add()

/Users/jakevdp/anaconda/envs/python3.5/lib/python3.5/site-packages/parsley.py in invokeRule(*args, **kwargs)
     96                     err = ParseError(err.input, err.position + 1,
     97                                      [["message", "expected EOF"]], err.trail)
---> 98             raise err
     99         return invokeRule
    100 

ParseError: 
4 + 3
^
Parse error at line 2, column 0: expected EOF. trail: []

Is the semantic difference between " " and ' ' intended? I couldn't find any discussion of this in the documentation. Thank you!

@kurtbrose
Copy link

I ran into this same issue recently.

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

No branches or pull requests

2 participants