bastikr / boolean.py

Implements boolean algebra in one module.
BSD 2-Clause "Simplified" License
78 stars 34 forks source link

Work with numbers as tokens? #77

Closed steveshi7 closed 4 years ago

steveshi7 commented 7 years ago

Is there a way to make this work with numbers as tokens? My use case for this is querying "ids", like 1234, 56, etc.

pombredanne commented 7 years ago

@steveshi7 sure, the standard tokenizer works on strings, but you can instead feed the parser with a sequence of your own tokens collected with your own tokenizer

jcohen28 commented 4 years ago

hi @pombredanne, i'm encountering an issue parsing tokens in which the first character is a number (for example "1abc"). The docstring appears to state that "a string even if starting with digits" is a valid token, but the code then only starts building a symbol when it encounters an alpha char. Can you please advise if I am missing something in my usage of the parser? https://github.com/bastikr/boolean.py/blob/master/boolean/boolean.py#L463

pombredanne commented 4 years ago

@jcohen28 that's a bug alright as it should be allowed as noted in the doc

jcohen28 commented 4 years ago

@pombredanne thank you for confirming. i'm not as familiar with the implementation logic, so might take me a bit to put together a pr for the fix with appropriate testing. any chance you have time to fix this more quickly?

pombredanne commented 4 years ago

Here is what I would do: I might try to replace on this line: https://github.com/bastikr/boolean.py/blob/0da6086c25d0ea3881d3947a3e06340f06868917/boolean/boolean.py#L463 this: sym = tok.isalpha() or tok == '_' by sym = tok.isalphanum() or tok == '_'

And then add a few tests?

jcohen28 commented 4 years ago

@pombredanne thanks. i have opened a pr. what do you think? https://github.com/bastikr/boolean.py/pull/96

pombredanne commented 4 years ago

@jcohen28 this is all good and merged then released at https://pypi.org/project/boolean.py/3.8/ Thank you ++ :heart: