Show HN: Strawk – 我实现了 Rob Pike 被遗忘的 Awk

2作者: ahalbert27 个月前
Rob Pike 写了一篇论文,名为《结构化正则表达式》(<a href="https:&#x2F;&#x2F;doc.cat-v.org&#x2F;bell_labs&#x2F;structural_regexps&#x2F;se.pdf" rel="nofollow">https:&#x2F;&#x2F;doc.cat-v.org&#x2F;bell_labs&#x2F;structural_regexps&#x2F;se.pdf</a>),批评了 Unix 工具集过度依赖行。像 awk 和 grep 这样的工具假定记录结构是规则的,通常由换行符分隔。Unix 管道只是将文件从一个命令流向另一个命令,而强加换行符结构限制了 Unix shell 的能力。 在论文中,Pike 先生提出了一个未来的 awk,它使用结构化正则表达式来解析输入,而不是逐行处理。据我所知,它从未被实现。所以我实现了它。我试图尽可能地模仿 AWK 及其标准库,但由于我在底层使用了 Golang,所以有些东西有所不同。 在线演示:<a href="https:&#x2F;&#x2F;ahalbert.github.io&#x2F;strawk&#x2F;demo&#x2F;strawk.html" rel="nofollow">https:&#x2F;&#x2F;ahalbert.github.io&#x2F;strawk&#x2F;demo&#x2F;strawk.html</a> Github:<a href="https:&#x2F;&#x2F;github.com&#x2F;ahalbert&#x2F;strawk" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ahalbert&#x2F;strawk</a>
查看原文
Rob Pike wrote a paper, Structural Regular Expressions (<a href="https:&#x2F;&#x2F;doc.cat-v.org&#x2F;bell_labs&#x2F;structural_regexps&#x2F;se.pdf" rel="nofollow">https:&#x2F;&#x2F;doc.cat-v.org&#x2F;bell_labs&#x2F;structural_regexps&#x2F;se.pdf</a>), that criticized the Unix toolset for being excessively line oriented. Tools like awk and grep assume a regular record structure usually denoted by newlines. Unix pipes just stream the file from one command to another, and imposing the newline structure limits the power of the Unix shell.<p>In the paper, Mr. Pike proposed an awk of the future that used structural regular expressions to parse input instead of line by line processing. As far as I know, it was never implemented. So I implemented it. I attempted to imitate AWK and it&#x27;s standard library as much as possible, but some things are different because I used Golang under the hood.<p>Live Demo: <a href="https:&#x2F;&#x2F;ahalbert.github.io&#x2F;strawk&#x2F;demo&#x2F;strawk.html" rel="nofollow">https:&#x2F;&#x2F;ahalbert.github.io&#x2F;strawk&#x2F;demo&#x2F;strawk.html</a><p>Github: <a href="https:&#x2F;&#x2F;github.com&#x2F;ahalbert&#x2F;strawk" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ahalbert&#x2F;strawk</a>