3 ms·
I've collected the different projects along with a nontrivial syntax example here: https://github.com/SonOfLilit/kleenexp#similar-works https://github.com/SonOf
by SonOfLilit 4y ago
I've collected the different projects along with a nontrivial syntax example here: https://github.com/SonOfLilit/kleenexp#similar-works https://github.com/SonOfLilit/kleenexp#similar-works
- Regular Expressions - very popular, occasionally reads like line noise, backslash for escape
(?:What is your (?:name|quest|favourite colour)\?\s?){1,3}
- https://github.com/SonOfLilit/kleenexp https://github.com/SonOfLilit/kleenexp - Terse, readable, almost never needs escaping. Python compiler, almost ready VSCode extension, online playground.
[1-3 'What is your ' ['name' | 'quest' | 'favourite colour'] '?' [0-1 #space]]
- https://github.com/yoav-lavi/melody https://github.com/yoav-lavi/melody - More verbose, supports macros, backslash escapes only for quotes. Rust compiler, babel plugin. Improves with time, getting quite impressive.
1 to 3 of match {
"What is your ";
either {
"name";
"quest";
"favorite color";
}
"?";
0 to 1 of " ";
}
- https://rulex-rs.github.io/ https://rulex-rs.github.io/ - Very similar to legacy regex syntax, supports macros and number ranges, supports unicode, _amazing_ error messages help convert legacy to new syntax, backslash escapes only for quotes. Rust compiler, as of today no built in way to use outside rust (but they seem to be planning it).
('What is your ' ('name'|'quest'|'favorite colour')'?' [s]){1,3}
- https://www.oilshell.org/release/latest/doc/eggex.html https://www.oilshell.org/release/latest/doc/eggex.html Part of a new Unix shell's syntax. Big on composition (macros in kleenexp). Uses backslash for character classes. Production-ready within the shell, not supported elsewhere yet.
/ 'What is your ' ('name' | 'quest' | 'favorite color') '?' ' '? /
- https://docs.raku.org/language/regexes https://docs.raku.org/language/regexes Similar to Eggex, part of Raku (the artist formerly known as Perl 6)
- http://verbalexpressions.github.io/ http://verbalexpressions.github.io/ - Embedded DSL, supports 14(!) languages (to some extent? I didn't verify), but don't seem to have syntax for `(a|b)` and `(?:...){3}`
const tester = VerEx()
.then('What is your ')
.either( // this doesn't seem to be implemented yet (?), so I'm proposing a possible syntax
VerEx().then('name'),
VerEx().then('quest'),
VerEx().then('favorite color'),
)
.then('?')
.maybe(' ')
.multiple(3); // not sure this is the correct syntax or how to use it in more complex scenarios, hard to tell from tests and discussions in Issues
- There are many more eDSLs, but I will not list them as they are less relevant in my opinion
- draegtun 4y agoAlso have a look at PARSE in Rebol & Red - http://www.rebol.com/docs/core23/rebolcore-15.html http://www.rebol.com/docs/core23/rebolcore-15.html This is how your example would look like in PARSE rule... 1 3 [{What is your } ["name" | "quest" | "favourite colour"] "?" opt space]
- lizmat 4y agoIf you don't care about the exact white spacing, you can simplify the Raku significantly using the :s adverb: m:s/ What is your (name | guest | favorite color) '?' / Especially in natural language parsing applications, this can be a very handy feature :-) See https://docs.raku.org/language/regexes#index-entry-regex_adverb_:sigspace-regex_adverb_:s-Sigspace https://docs.raku.org/language/regexes#index-entry-regex_adv...
- carapace 4y agoIf you want to see something really neat check out Prolog DCGs: > A Prolog definite clause grammar (DCG) describes a sequence. Operationally, DCGs can be used to parse, generate, complete and check sequences manifested as lists. https://www.metalevel.at/prolog/dcg https://www.metalevel.at/prolog/dcg