展示HN:Strawk – 我实现了罗布·派克被遗忘的Awk
罗布·派克(Rob Pike)撰写了一篇论文《结构化正则表达式》(<a href="https://doc.cat-v.org/bell_labs/structural_regexps/se.pdf" rel="nofollow">https://doc.cat-v.org/bell_labs/structural_regexps/se.pdf</a>),批评了Unix工具集过于依赖行的结构。像awk和grep这样的工具假设记录结构是常规的,通常用换行符表示。Unix管道只是将文件从一个命令流向另一个命令,而强加换行结构限制了Unix shell的能力。
在论文中,派克先生提出了一种未来的awk,它使用结构化正则表达式来解析输入,而不是逐行处理。就我所知,这种想法从未被实现。因此,我决定实现它。我尽量模仿AWK及其标准库,但由于我在底层使用了Golang,有些地方有所不同。
在线演示:<a href="https://ahalbert.github.io/strawk/demo/strawk.html" rel="nofollow">https://ahalbert.github.io/strawk/demo/strawk.html</a>
Github:<a href="https://github.com/ahalbert/strawk" rel="nofollow">https://github.com/ahalbert/strawk</a>
查看原文
Rob Pike wrote a paper, Structural Regular Expressions (<a href="https://doc.cat-v.org/bell_labs/structural_regexps/se.pdf" rel="nofollow">https://doc.cat-v.org/bell_labs/structural_regexps/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'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://ahalbert.github.io/strawk/demo/strawk.html" rel="nofollow">https://ahalbert.github.io/strawk/demo/strawk.html</a><p>Github: <a href="https://github.com/ahalbert/strawk" rel="nofollow">https://github.com/ahalbert/strawk</a>