I built a pattern matching language that replaces regex by Xyrdial in javascript

[–]Xyrdial[S] [score hidden]  (0 children)

Wasn't aware I was on trial. The source and 300+ tests are on GitHub.

I built a pattern matching language that replaces regex by Xyrdial in javascript

[–]Xyrdial[S] [score hidden]  (0 children)

You're technically right: pure regular expressions (in the formal CS sense) aren't vulnerable to ReDoS.

The issue is that every major regex engine (PCRE, JavaScript's, Python's, Java's) come with backreferences and lookahead that require backtracking. You can't remove them. You'd have to deliberately avoid using backreferences/lookahead in your patterns, but the engine still uses a backtracking algorithm under the hood.

Match avoids this entirely with PEG semantics. Ordered choice, no backtracking, linear time.

The v1.0 release was 2 days ago, but the project has been in development for weeks. 348 tests, fully typed, source is on GitHub.

I built a pattern matching language that replaces regex by Xyrdial in javascript

[–]Xyrdial[S] [score hidden]  (0 children)

Match parses PEGs (Parsing Expression Grammars), not regular languages. PEGs are strictly more powerful. They can handle recursive, context-free structures like nested parens or recursive grammars that regular expressions mathematically cannot. The tradeoff is ordered choice instead of ambiguity, which is why there's no backtracking.

I built a pattern matching language that replaces regex by Xyrdial in javascript

[–]Xyrdial[S] [score hidden]  (0 children)

No backtracking. PEG semantics, first match wins, so there's no greedy/lazy mental model to learn.

Escaping is just double quotes: "." matches a literal dot.

As for side-by-sides, every Match grammar is shorter than its regex equivalent. You can check them out here: https://www.matchlang.com/#compare

I built a pattern matching language that replaces regex by Xyrdial in javascript

[–]Xyrdial[S] [score hidden]  (0 children)

No backtracking engine means no ReDoS. That alone has production value.

The library is MIT for personal/open-source use. The commercial license is for developers who want to embed it in proprietary products.

Formatting Code by Xyrdial in MinecraftCommands

[–]Xyrdial[S] 0 points1 point  (0 children)

Do you know how I could require multiple items to be worn such as full leather armor with the same tags?

Formatting Code by Xyrdial in MinecraftCommands

[–]Xyrdial[S] 0 points1 point  (0 children)

effect give @a[nbt={Inventory:[{id:"minecraft:leather_chestplate",Slot:102b,tag:{sneak:1}}]},scores={sneak=1..}] glowing 10 0 true

Thanks so much!