TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Melody – a language that compiles to regular expressions

143 pointsby losfairover 3 years ago

14 comments

draegtunabout 3 years ago
I like using `parse` in Rebol &#x2F; Red - <a href="http:&#x2F;&#x2F;www.rebol.com&#x2F;r3&#x2F;docs&#x2F;functions&#x2F;parse.html" rel="nofollow">http:&#x2F;&#x2F;www.rebol.com&#x2F;r3&#x2F;docs&#x2F;functions&#x2F;parse.html</a><p>Here&#x27;s the parse rule for Batman:<p><pre><code> [ 16 &quot;na&quot; 2 [space &quot;batman&quot;] ] </code></pre> And complete example for the Semantic version:<p><pre><code> digit: charset &quot;1234567890&quot; if parse &quot;0.2.5&quot; [ opt &quot;v&quot; copy major [some digit] &quot;.&quot; copy minor [some digit] &quot;.&quot; copy patch [some digit] ][ print [major minor patch] ]</code></pre>
chubotover 3 years ago
I made a wiki page for similar alternative regex syntax projects:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;oilshell&#x2F;oil&#x2F;wiki&#x2F;Alternative-Regex-Syntax" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;oilshell&#x2F;oil&#x2F;wiki&#x2F;Alternative-Regex-Synta...</a><p>(including my own <a href="https:&#x2F;&#x2F;www.oilshell.org&#x2F;release&#x2F;latest&#x2F;doc&#x2F;eggex.html" rel="nofollow">https:&#x2F;&#x2F;www.oilshell.org&#x2F;release&#x2F;latest&#x2F;doc&#x2F;eggex.html</a> which is built into Oil)
评论 #30368771 未加载
评论 #30367671 未加载
blahgeekover 3 years ago
Emacs lisp provides a similar tool (with better syntax IMO): <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Rx-Notation.html" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Rx...</a>
yoav_laviover 3 years ago
Author here, thanks for posting Melody! This is my first attempt at a language and I&#x27;m learning Rust, so any input would be appreciated
评论 #30368982 未加载
评论 #30372159 未加载
评论 #30363542 未加载
评论 #30367547 未加载
maximilianroosover 3 years ago
A bit orthogonal but something I would love to see:<p>A library which takes a regex and shows some examples that pass and some that fail. I would find that the easiest way of understanding a regex, rather than changing the language itself. (Though Melody looks v promising and I&#x27;m keen to see it develop).<p>It wouldn&#x27;t be trivial to build — particularly for the &quot;fail&quot; examples, you&#x27;d want them fairly close to passing. For example, with `(&#x2F;*\.csv\.gz)` you&#x27;d want `foo.csv.gz` rather than `aoseutn` as an example of a failure.
评论 #30370302 未加载
评论 #30370314 未加载
评论 #30369345 未加载
parksyover 3 years ago
Some thoughts I had for the developer:<p>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.<p>Also are there plans to support runtime compiling in JS? Something like...<p>someMelodyObject = &lt;initialise and configure melody&gt; String.replace(someMelodyObject.toRegexp(), someString)<p>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&#x27;d have to deal with performance and caching but it would probably go a ways to improving adoption among web developers at least.<p>Anyways good luck with the project. Regex is often considered a dark art when it&#x27;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.
评论 #30371200 未加载
ZeroGravitasover 3 years ago
I always liked the Perl style commented regexes, would be nice if this could generate those, though I guess that needs language support.<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;15463257&#x2F;commenting-regular-expression" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;15463257&#x2F;commenting-regu...</a><p>Some interesting workarounds mentioned here that might pair well with melody type languages.<p>A way to specify example strings that match or don&#x27;t as a mini unit test would be cool too.
kdtopover 3 years ago
I have never taken the time to learn RegEx stuff. It seems like it would be great if I could keep all the syntax in my head. So the idea of Melody seems great. I don&#x27;t like that the github description claims it to be unstable currently. I hope this project continues and flourishes.
评论 #30361573 未加载
评论 #30359747 未加载
评论 #30367990 未加载
评论 #30367368 未加载
SonOfLilitover 3 years ago
Shameless plug: I&#x27;m working on a similar project, with a strong focus on providing a painless migration path. Author: let&#x27;s chat and perhaps join forces?<p>Please don&#x27;t submit to HN until I release the vscode plugin :-)<p><a href="https:&#x2F;&#x2F;github.com&#x2F;sonoflilit&#x2F;kleenexp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sonoflilit&#x2F;kleenexp</a>
siviziusover 3 years ago
So, a RegEx (melody syntax) to RegEx (unspecified syntax) compiler? I mean, the syntax is nice, but 1. please specify which kind of regular expression it compiles to, 2. are those really regular expressions or a language higher in the chomsky hierarchy? 3. I suggest to add a graphical output of the state machine, e.g. with graphviz.
评论 #30370853 未加载
makachover 3 years ago
Excellent, now we need a language that compiles into Melody. Can I have a GUI with that?
d--bover 3 years ago
“And now you have 3 problems”.<p>Sorry I had to make the joke! This is fine. Regex are a pain.
asicspover 3 years ago
See also: <a href="https:&#x2F;&#x2F;github.com&#x2F;VerbalExpressions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;VerbalExpressions</a>
politicianover 3 years ago
I wouldn’t write regex in this, but it would be interesting to use it to debug&#x2F;read complex expressions.