4 ms·
Swift's RegexBuilder DSL from a couple years ago gets away from the illegible subset of ASCII. Easy to explode into a lot lines, but I'd rather have a 50 line
by wlesieutre 3y ago
Swift's RegexBuilder DSL from a couple years ago gets away from the illegible subset of ASCII.
Easy to explode into a lot lines, but I'd rather have a 50 line RegexBuilder implementation than try to keep track of what the equivalent single-line version is doing. Especially if you ever have to come back to it later and understand it again.
And if you ever make revisions in RegexBuilder you have useful diffs instead of "the one line that does everything is different than before."
https://developer.apple.com/documentation/regexbuilder https://developer.apple.com/documentation/regexbuilder
Are there similar tools in any other languages?
- JonChesterfield 3y agoAn alternative to seeking better language APIs. Parsing regex then pretty-printing the parse tree as s-expressions is very legible. You can also print the parse tree as the original syntax. Postfix will work better for some people, I like the lispy look for parse trees. Most regex are similar syntax over a parse tree with different parts missing, if you keep track of roughly what features the current engine has in your head the sema checking a real compiler should do could be deferred or incomplete. Some coding standards will want redundant escapes because that is considered more readable, could put that logic in the pretty-printer. That's sort of suggesting using your IDE to translate the thing back and forth on the fly instead of persuading colleagues to stop writing in the obfuscated format.