News for hackers. Stuff that matters.
Re:Parsing in JavaScript: all the tools and libraries you ca... by lgessler on Monday May 24, 2021 @04:31PM (#27269345)
It's a Clojure(Script) library, but it's still so good it's worth mentioning: Instaparse[0] generates a parser for you from a BNF-y grammar specification. Sample from the readme:

    (def as-and-bs
      (insta/parser
        "S = AB*
         AB = A B
         A = 'a'+
         B = 'b'+"))

    => (as-and-bs "aaaaabbbaaaabb")
    [:S
     [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
     [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
[0]: https://github.com/Engelberg/instaparse
Re:Parsing in JavaScript: all the tools and libraries you ca... by fjfaase on Tuesday May 25, 2021 @02:42AM (#27273599)
I wrote something similar in JavaScript. You need something like:

function as_and_bs() { return parse_text("aaaaabbbaaaabb", make_grammar( parse_text("root : (\"a\" SEQ \"b\" SEQ)SEQ OPT", iparse_grammar))) }

The code can be found at https://github.com/FransFaase/ParserWorkshop/