TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Melody – a language that compiles to regular expressions

143 点作者 losfair超过 3 年前

14 条评论

draegtun大约 3 年前
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>
chubot超过 3 年前
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 未加载
blahgeek超过 3 年前
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_lavi超过 3 年前
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 未加载
maximilianroos超过 3 年前
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 未加载
parksy超过 3 年前
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 未加载
ZeroGravitas超过 3 年前
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.
kdtop超过 3 年前
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 未加载
SonOfLilit超过 3 年前
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>
sivizius超过 3 年前
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 未加载
makach超过 3 年前
Excellent, now we need a language that compiles into Melody. Can I have a GUI with that?
d--b超过 3 年前
“And now you have 3 problems”.<p>Sorry I had to make the joke! This is fine. Regex are a pain.
asicsp超过 3 年前
See also: <a href="https:&#x2F;&#x2F;github.com&#x2F;VerbalExpressions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;VerbalExpressions</a>
politician超过 3 年前
I wouldn’t write regex in this, but it would be interesting to use it to debug&#x2F;read complex expressions.