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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Parsing in JavaScript: all the tools and libraries you can use

74 点作者 jasim将近 4 年前

12 条评论

lgessler将近 4 年前
It&#x27;s a Clojure(Script) library, but it&#x27;s still so good it&#x27;s worth mentioning: Instaparse[0] generates a parser for you from a BNF-y grammar specification. Sample from the readme:<p><pre><code> (def as-and-bs (insta&#x2F;parser &quot;S = AB* AB = A B A = &#x27;a&#x27;+ B = &#x27;b&#x27;+&quot;)) =&gt; (as-and-bs &quot;aaaaabbbaaaabb&quot;) [:S [:AB [:A &quot;a&quot; &quot;a&quot; &quot;a&quot; &quot;a&quot; &quot;a&quot;] [:B &quot;b&quot; &quot;b&quot; &quot;b&quot;]] [:AB [:A &quot;a&quot; &quot;a&quot; &quot;a&quot; &quot;a&quot;] [:B &quot;b&quot; &quot;b&quot;]]] </code></pre> [0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;Engelberg&#x2F;instaparse" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Engelberg&#x2F;instaparse</a>
评论 #27273599 未加载
codeismath将近 4 年前
I recently used &quot;Arcsecond&quot; JavaScript Parser Combinator library to output some abstract syntax based on John Reynold&#x27;s &quot;Definitional interpreters for higher-order programming languages&quot;.<p>It&#x27;s based on Haskell&#x27;s Parsec parser combinator library, and is zero-dependency.<p>I was convinced to give it a try based on watching the author&#x27;s YouTube videos &quot;Parser Combinators From Scratch&quot; on &quot;Low Level JavaScript&quot;. Enjoyable series - recommended.
archibaldJ将近 4 年前
hmm this article is a bit outdated; peg.js (mentioned in the article) has been abandoned by the maintainer for a few years now (and it never reached a stable 1.0 ); recently the project was picked up by another team under the name peggy.js <a href="https:&#x2F;&#x2F;github.com&#x2F;peggyjs&#x2F;peggy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;peggyjs&#x2F;peggy</a>
dahart将近 4 年前
The link has an anchor &quot;#chevrotain&quot; that goes directly to near the bottom of the article, can it be removed?
评论 #27268856 未加载
dahart将近 4 年前
Anyone have experience with Nearley? I recently did some reading on JS parsers and ended up feeling like it was easier to use than most of the others where you have to pay attention to and know some tricks for handling recursive grammar rules. What I don&#x27;t have a sense for yet is what the downsides of Nearley might be down the road once my grammar gets bigger and&#x2F;or goes into production, if the performance issues might pop up suddenly and be hard to fix.
评论 #27267692 未加载
评论 #27267097 未加载
jchw将近 4 年前
This is pretty cool and useful! I had been doing bootleg parser combinators in JavaScript up until now. This works, although being someone who doesn&#x27;t write Haskell I assume that the magic that makes parser combinators efficient is not easy to implement in most languages. (I&#x27;ve been using nom with Rust on the side too and it seems to do the same naive stuff that I do.)<p>If you ever want to parse <i>binary</i> data using JavaScript, I will always recommend the excellent Kaitai Struct project.<p><a href="https:&#x2F;&#x2F;kaitai.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;kaitai.io&#x2F;</a>
heroku将近 4 年前
See my library for parsing text: <a href="https:&#x2F;&#x2F;github.com&#x2F;eguneys&#x2F;tamcher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;eguneys&#x2F;tamcher</a>
fjfaase将近 4 年前
Earlier this year, I wrote a small interpreting parser in JavaScript, which takes a grammar from a string and parses some input from a string according to the grammar into an AST. It is embedded in the page <a href="https:&#x2F;&#x2F;fransfaase.github.io&#x2F;ParserWorkshop&#x2F;Online_inter_parser.html" rel="nofollow">https:&#x2F;&#x2F;fransfaase.github.io&#x2F;ParserWorkshop&#x2F;Online_inter_par...</a>
FractalHQ将近 4 年前
No Treesitter? I thought it was one of the most performant modern options with an amazing ecosystem around it.
评论 #27267472 未加载
sehugg将近 4 年前
I&#x27;d also suggest using jsfuzz to find sharp corners in your parser. I used it extensively for my recursive-descent BASIC interpreter (along with a test suite) and it found tons of issues.
Zababa将近 4 年前
Another thing that you can use if you&#x27;re doing JS: any language that compile to JavaScript. Here are a few options:<p>- Clojure with ClojureScript<p>- F# with Fable<p>- Haskell with ghcjs<p>- OCaml with js_of_ocaml and ReScript<p>- Racket with RacketScript<p>- Scala with Scala.js
jevgeni将近 4 年前
Although this is an interesting topic to me, I struggle to read the site behind all the cookie warnings and newsletter begging.