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

Problem with as_keyword in one_of #554

Open
theroucken opened this issue May 14, 2024 · 2 comments
Open

Problem with as_keyword in one_of #554

theroucken opened this issue May 14, 2024 · 2 comments

Comments

@theroucken
Copy link

The problem occurs if you insert special characters

In the first case everything works as expected, the output is “+case2”

CASE = "+case2"
A = Or([CaselessKeyword("+case1"), CaselessKeyword("+case2")])
print(A.parse_string(CASE))

But in the second one, when the as_keyword parameter in one_of is used, an error occurs

CASE = "+case2"
B = one_of(["+case1", "+case2"], caseless=True, as_keyword=True)
print(B.parse_string(CASE))
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected +case1 | +case2, found '+'  (at char 0), (line:1, col:1)

I'm using pyparsing version 3.1.2

@ptmcg
Copy link
Member

ptmcg commented May 14, 2024

one_of by default takes the input strings and creates a regex out of them. Have you tried adding the use_regex=False argument to one_of?

@theroucken
Copy link
Author

one_of by default takes the input strings and creates a regex out of them. Have you tried adding the use_regex=False argument to one_of?

Yes, that fixed the problem, I missed that point for some reason. Thank you :)

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