Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 704 Bytes

README.md

File metadata and controls

41 lines (27 loc) · 704 Bytes

Go


Go version of SimplePEG. A very simple implementation of PEG parser generator.

import "github.com/SimplePEG/Go/SimplePeg"

func main() {
    var ast = simplepeg.Parse(`GRAMMAR test a->"A";`, 'A')
	
	println(ast.Match)
}

Or create parser function

import "github.com/SimplePEG/Go/SimplePeg/speg"

func main() {
    var spegParser = speg.NewSPEGParser()
    
    var gAst, gErr = spegParser.ParseGrammar(grammar)
    
    if !gErr {
            parser, grule := speg.GetParser(ast)
            
            result, err := parser(&rd.State{
                Text:     text,
                Position: 0,
                Rules:    grule.rules,
            })

			//...
	}
}