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.

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

74 pointsby jasimalmost 4 years ago

12 comments

lgessleralmost 4 years ago
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 未加载
codeismathalmost 4 years ago
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.
archibaldJalmost 4 years ago
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>
dahartalmost 4 years ago
The link has an anchor &quot;#chevrotain&quot; that goes directly to near the bottom of the article, can it be removed?
评论 #27268856 未加载
dahartalmost 4 years ago
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 未加载
jchwalmost 4 years ago
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>
herokualmost 4 years ago
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>
fjfaasealmost 4 years ago
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>
FractalHQalmost 4 years ago
No Treesitter? I thought it was one of the most performant modern options with an amazing ecosystem around it.
评论 #27267472 未加载
sehuggalmost 4 years ago
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.
Zababaalmost 4 years ago
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
jevgenialmost 4 years ago
Although this is an interesting topic to me, I struggle to read the site behind all the cookie warnings and newsletter begging.