Show HN: An expression parser supporting multiple types

29 pointsposted 7 hours ago
by torrentg

5 Comments

ufo

4 hours ago

I had a quick brain BSOD reading the code because lot's of things have yy_ prefixes but the code is actually written by hand, not generated by Yacc/Bison.

torrentg

3 hours ago

Yes, I used the 'yy_' prefix to indicate that they are parsing-related functions, and also as a tribute to Yacc/Bison. You're not the first person who finds this creepy. Maybe I should change the prefix...

AlexErrant

3 hours ago

Shameless self-plug of my own expression language supporting multiple types: https://github.com/AlexErrant/Pentive/blob/main/shared-dom/s...

It's a Lezer grammar using the Github search syntax style. Currently undocumented, but the autocomplete/syntax highlighting (thanks to Lezer) is pretty good. It can handle search strings like this:

    created<2024-09-24 foo -bar spider-man "wildcard*" ```literal"'`quotes``` (a b "quoted string") (c OR d OR `lit'eral`) -(x y OR z) (tag:mytag,'your tag') state:normal (arbitrary (nesting (edited<2024-09-23 OR created=2024-09-17))) /regex/si due=true tagCount=0 field:"user input field name":/lol regex/ui

torrentg

3 hours ago

Nice contribution! Seems that you are using Lezer for handling the parsing. Multi-type parsers are a fascinating subject but I haven’t encountered many references to them either. It would be interesting to explore more projects or approaches in that area. Contributions are welcome!

user

3 hours ago

[deleted]