Show HN: An expression parser supporting multiple types

33 pointsposted 9 months ago
by torrentg

7 Comments

ufo

9 months 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

9 months 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...

breck

9 months ago

Ah, I should have read the description above to have more context! Anyway, I had fun exploring this and eventually I detected that it must be used to power something neat (as you explain above).

Here's my user test: https://news.pub/?try=https://www.youtube.com/embed/DS5MXJSG...

torrentg

9 months ago

Thank you very much for your review. I didn't know about https://news.pub/. It's a great place!

By default, expr's make compiles tests and examples. Among them is calc, a basic little tool that allows you to test expressions.

AlexErrant

9 months 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

9 months 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

9 months ago

[deleted]