pyparsing / pyparsing

Python library for creating PEG parsers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with as_keyword in one_of

theroucken opened this issue · comments

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

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?

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 :)