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

NotAny skips whitespace #434

Open
grv87 opened this issue Jul 18, 2022 · 0 comments
Open

NotAny skips whitespace #434

grv87 opened this issue Jul 18, 2022 · 0 comments

Comments

@grv87
Copy link

grv87 commented Jul 18, 2022

Documentation:

it only verifies that the specified parse expression does not match at the current position. Also, NotAny does not skip over leading whitespace

Tests show that NotAny actually skips whitespace and matches parse expression not just in current position, but after white space too.

Test cases:

from pyparsing import *
import unittest
class TestNotAny(unittest.TestCase, pyparsing_test.TestParseResultsAsserts):
    def test_not_any_chars(self):
        ast = Literal("FOO") + NotAny(Char(alphanums)) + Literal("BAR")
        self.assertParseAndCheckList(ast, "FOO BAR", ["FOO", "BAR"])
        # self.assertRaisesParseException(ast, "FOOBAR")
    def test_not_any_chars_with_string(self):
        ast = Literal("FOO") + NotAny("B") + Literal("BAR")
        self.assertParseAndCheckList(ast, "FOO BAR", ["FOO", "BAR"])
        # self.assertRaisesParseException(ast, "FOOBAR")
    def test_not_any_chars_worked_around(self):
        ast = Literal("FOO") + NotAny(Char(alphanums).leave_whitespace()) + Literal("BAR")
        self.assertParseAndCheckList(ast, "FOO BAR", ["FOO", "BAR"])
        self.assertRaisesParseException(ast, "FOOBAR")

The first 2 cases fail, with strange error message:

pyparsing.exceptions.ParseException: Found unwanted token, 'B', found ' '

IMO, NotAny should set skipWhitespace on the underlying expression, otherwise the whole idea doesn't work.
Maybe not setting it could be justified when ParserElement is used (changing skipWhitespace would require creating a copy of the element, and then it's better if the user does it by himself). But what's the reason not to set skipWhitespace when a string is passed?

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

1 participant