FAQ
I have attempted to build a parser combinator in golang inspired from
Haskell.

https://github.com/prataprc/goparsec

Requesting For Comments.

The gist of the idea is,

a. forward declaration.
b. pointer reference to mutually referencing parsers.

Normally it is easy to construct Terminal parsers and simple
NonTerminal parsers.

To construct NonTerminal parsers, whose descendants backreference
to itself or to its ancestors, we can forward
declare such non-terminals and pass them as pointer reference
while combining them with other parsers. Subsequently we can
initialize them under init() function.

EG combinators for parsing JSON:

     // Forward declaration of single JSON value
     var value parsec.Parser

     // Combine them with reference
     // values -> value | values "," value
     var values = parsec.Kleene(valuesNode, &value, comma())
     // array -> "[" values "]"
     var array = parsec.And(arrayNode, openSqrt(), values, closeSqrt())
     ....

     func init() {
         // deferred initialization of parsers.
         value = parsec.OrdChoice(
            valueNode, parsec.Parser(tokenTerm), &array, &object)
         ....
     }

Thanks,


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 6, '15 at 6:44a
activeJan 6, '15 at 6:44a
posts1
users1
websitegolang.org

1 user in discussion

Pratap Chakravarthy: 1 post

People

Translate

site design / logo © 2022 Grokbase