5 ms·
Some thoughts I had for the developer: Does it (or are the plans to) reverse compile? If I could input my regex and output melody script one could create an ex
by parksy 5y ago
Some thoughts I had for the developer:
Does it (or are the plans to) reverse compile? If I could input my regex and output melody script one could create an excellent interactive learning tool, and also more selfishly help with adoption in teams with crusty old devs like me who like our magic rituals and prefer typing our regex by hand.
Also are there plans to support runtime compiling in JS? Something like...
someMelodyObject = <initialise and configure melody>
String.replace(someMelodyObject.toRegexp(), someString)
This I think would make it a compelling library for inclusion into projects assuming it were fairly efficient and lightweight. Not sure how or if you'd have to deal with performance and caching but it would probably go a ways to improving adoption among web developers at least.
Anyways good luck with the project. Regex is often considered a dark art when it's actually fairly concise and expressive, opening it up to more people at a higher level could lead to greater understanding of regex in general. Also what an interesting and challenging project to undertake, definitely a nontrivial challenge all told.
- yoav_lavi 5y agoAuthor here, 1. A reverse compiler is one of the 'maybe' features (see the table in the README), it's something I'd like but would essentially be an entire compiler so it's non trivial 2. The plan is to make Melody available as a compile step (like e.g. SASS) with no runtime overhead or as a Rust crate. You could do the compilation at runtime but other than including variables in the pattern I'm not sure if it'd have a benefit over compile time transforming, + it'd have a performance impact. Thank you!
- parksy 5y agoNo dramas, understood re 1 it's no doubt beyond trivial to create a bidirectional transpiler. I wouldn't even know where to begin so good work on what you've managed so far. Re 2, shouldn't be a problem as we already have build processes in place. Most projects I work on have npm build steps, I'm not sure how that figures in with rust (I really need to get off my butt and check it out sometime), but if it could be pulled in as an npm dependency that would work. If it could be done inline even better (e.g. inline melody within a JS file, compiles to the expression inline...) Anyway good job again so far, have followed the repo, all the best once more!
- yoav_lavi 5y agoThank you! >If it could be done inline even better I've been thinking of using a tagged template based mechanism (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...) so no special editor support is needed and then transpile to a normal regex (similar to how htm handles it's syntax with no runtime, https://www.npmjs.com/package/babel-plugin-htm https://www.npmjs.com/package/babel-plugin-htm) but I'm not working on that part of the process yet so it may change. If Melody does end up using the tagged template mechanism it may end up looking something like this: import melody from "melody"; const batmanRegex = melody` 16 of "na"; 2 of match { <space>; "batman"; } `; That would transpile to: const batmanRegex = /(?:na){16}(?:\sbatman){2}/; Backticks would need escaping but otherwise it'd be normal Melody syntax