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

Surprising whitespace handling #305

Closed
dnicolodi opened this issue Aug 27, 2023 · 4 comments · Fixed by #309
Closed

Surprising whitespace handling #305

dnicolodi opened this issue Aug 27, 2023 · 4 comments · Fixed by #309

Comments

@dnicolodi
Copy link
Contributor

Given this example

import tatsu

parser = tatsu.compile(r'''
statement = 'SELECT' 'FROM' table $ ;
table = name:id ;
id = /[a-z]+/ ;
''')

string = 'SELECT FROM   foo'
value = parser.parse(string, parseinfo=True)

table = value[2]
assert table['name'] == 'foo'

parseinfo = table['parseinfo']
print(parseinfo.tokenizer.text)
print(f'{parseinfo.pos * " "}^')

I find whitespace handling a surprising. The whitespace between FROM and the table name is not skipped over before matching the table rule. This results in correct parsing but the parseinfo for the table rule. I would have expected whitespace to be skipped before attempting to match the table rule.

@apalala
Copy link
Collaborator

apalala commented Aug 27, 2023

Could you tur these checks into a pytest unit test, @dnicolodi ?

@dnicolodi
Copy link
Contributor Author

Sure, I was just not sure that the behavior I expect it the intended one.

@apalala
Copy link
Collaborator

apalala commented Aug 27, 2023

A unit test will precisely state the intended outcome.

@dnicolodi
Copy link
Contributor Author

See #306.

apalala added a commit that referenced this issue Oct 13, 2023
fixes #305

* [test] Add test demonstrating expected white space skipping behavior (#306)
* [test] add unit test on advancing over whitespace
* [parsing] eat whitespace before memoizing
* [readme] update statement about Python version requirements

---------

Co-authored-by: Daniele Nicolodi <daniele@grinta.net>
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.

2 participants