Documentation ¶
Overview ¶
This package implements a static parser generator for parsing expression grammars (PEG) that is compatible with dynamic parser.
go:generate go run cmd/generator/generator-main.go --grammar=peg.peg --output=peg.peg.go --package=generator
Index ¶
- func CaptureEndHandler(r *Result, pos int) (int, error)
- func CaptureHandler(r *Result, pos int) (int, error)
- func CaptureStartHandler(r *Result, pos int) (int, error)
- func Capture_1(r *Result, pos int) (int, error)
- func Capture_1_1(r *Result, pos int) (int, error)
- func Capture_1_2(r *Result, pos int) (int, error)
- func Capture_1_3(r *Result, pos int) (int, error)
- func Capture_1_4(r *Result, pos int) (int, error)
- func Capture_1_5(r *Result, pos int) (int, error)
- func CharClassHandler(r *Result, pos int) (int, error)
- func CharClass_1(r *Result, pos int) (int, error)
- func CharClass_1_1(r *Result, pos int) (int, error)
- func CharClass_1_2(r *Result, pos int) (int, error)
- func CharClass_1_3(r *Result, pos int) (int, error)
- func CharClass_1_3_capture(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_1_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_1_2(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_1_2_plus(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_1_3(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1_star(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1_star_paren_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1_star_paren_1_1(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1_star_paren_1_1_neg(r *Result, pos int) (int, error)
- func CharClass_1_3_capture_1_1_paren_2_1_star_paren_1_2(r *Result, pos int) (int, error)
- func CharClass_1_4(r *Result, pos int) (int, error)
- func Construct(n *parser.Node, callback func(string, Accessor) (interface{}, error), ...) (interface{}, error)
- func EndOfLineHandler(r *Result, pos int) (int, error)
- func EndOfLine_1(r *Result, pos int) (int, error)
- func EndOfLine_1_1(r *Result, pos int) (int, error)
- func EndOfLine_1_1_star(r *Result, pos int) (int, error)
- func EndOfLine_1_2(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_1(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_1_1(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_2(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_2_1(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_3(r *Result, pos int) (int, error)
- func EndOfLine_1_2_paren_3_1(r *Result, pos int) (int, error)
- func GrammarHandler(r *Result, pos int) (int, error)
- func Grammar_1(r *Result, pos int) (int, error)
- func Grammar_1_1(r *Result, pos int) (int, error)
- func Grammar_1_1_plus(r *Result, pos int) (int, error)
- func Grammar_1_2(r *Result, pos int) (int, error)
- func IdentHandler(r *Result, pos int) (int, error)
- func Ident_1(r *Result, pos int) (int, error)
- func Ident_1_1(r *Result, pos int) (int, error)
- func Ident_1_1_star(r *Result, pos int) (int, error)
- func Ident_1_2(r *Result, pos int) (int, error)
- func Ident_1_2_capture(r *Result, pos int) (int, error)
- func Ident_1_2_capture_1(r *Result, pos int) (int, error)
- func Ident_1_2_capture_1_1(r *Result, pos int) (int, error)
- func Ident_1_2_capture_1_2(r *Result, pos int) (int, error)
- func Ident_1_2_capture_1_2_star(r *Result, pos int) (int, error)
- func LiteralHandler(r *Result, pos int) (int, error)
- func Literal_1(r *Result, pos int) (int, error)
- func Literal_1_1(r *Result, pos int) (int, error)
- func Literal_1_2(r *Result, pos int) (int, error)
- func Literal_1_2_capture(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_1(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2_star(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2_star_paren_1(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2_star_paren_1_1(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2_star_paren_1_1_neg(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_2_star_paren_1_2(r *Result, pos int) (int, error)
- func Literal_1_2_capture_1_3(r *Result, pos int) (int, error)
- func Literal_2(r *Result, pos int) (int, error)
- func Literal_2_1(r *Result, pos int) (int, error)
- func Literal_2_2(r *Result, pos int) (int, error)
- func Literal_2_2_capture(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_1(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2_star(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2_star_paren_1(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2_star_paren_1_1(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2_star_paren_1_1_neg(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_2_star_paren_1_2(r *Result, pos int) (int, error)
- func Literal_2_2_capture_1_3(r *Result, pos int) (int, error)
- func MakeCharClassHandler(cc *charclass.CharClass, handlerName string) []ast.Decl
- func MakeChoiceHandler(group []string, handlerName string) []ast.Decl
- func MakeDotHandler(handlerName string) []ast.Decl
- func MakeGroupHandler(group []string, handlerName string) []ast.Decl
- func MakeLiteralHandler(val, handlerName string) []ast.Decl
- func MakePlusHandler(handlerName, subHandler string) []ast.Decl
- func MakePredicateHandler(handlerName, subHandler string, positive bool) []ast.Decl
- func MakeQuestionHandler(handlerName, subHandler string) []ast.Decl
- func MakeRHSHandler(handlerName, ruleName string, rhs *RHS) []ast.Decl
- func MakeStarHandler(handlerName, subHandler string) []ast.Decl
- func MakeTermHandler(term *Term, handlerName string) []ast.Decl
- func MakeTermsHandler(terms []*Term, handlerName string) []ast.Decl
- func NegPredHandler(r *Result, pos int) (int, error)
- func NegPred_1(r *Result, pos int) (int, error)
- func NegPred_1_1(r *Result, pos int) (int, error)
- func NegPred_1_2(r *Result, pos int) (int, error)
- func NegPred_1_3(r *Result, pos int) (int, error)
- func New(source string) (*generator, error)
- func ParensHandler(r *Result, pos int) (int, error)
- func Parens_1(r *Result, pos int) (int, error)
- func Parens_1_1(r *Result, pos int) (int, error)
- func Parens_1_2(r *Result, pos int) (int, error)
- func Parens_1_3(r *Result, pos int) (int, error)
- func Parens_1_4(r *Result, pos int) (int, error)
- func Parens_1_5(r *Result, pos int) (int, error)
- func PredHandler(r *Result, pos int) (int, error)
- func Pred_1(r *Result, pos int) (int, error)
- func Pred_1_1(r *Result, pos int) (int, error)
- func Pred_1_2(r *Result, pos int) (int, error)
- func Pred_1_3(r *Result, pos int) (int, error)
- func RHSHandler(r *Result, pos int) (int, error)
- func RHS_1(r *Result, pos int) (int, error)
- func RHS_1_1(r *Result, pos int) (int, error)
- func RHS_1_2(r *Result, pos int) (int, error)
- func RHS_1_2_star(r *Result, pos int) (int, error)
- func RHS_1_2_star_paren_1(r *Result, pos int) (int, error)
- func RHS_1_2_star_paren_1_1(r *Result, pos int) (int, error)
- func RHS_1_2_star_paren_1_2(r *Result, pos int) (int, error)
- func RHS_1_2_star_paren_1_3(r *Result, pos int) (int, error)
- func RuleHandler(r *Result, pos int) (int, error)
- func Rule_1(r *Result, pos int) (int, error)
- func Rule_1_1(r *Result, pos int) (int, error)
- func Rule_1_2(r *Result, pos int) (int, error)
- func Rule_1_3(r *Result, pos int) (int, error)
- func Rule_1_4(r *Result, pos int) (int, error)
- func Rule_1_5(r *Result, pos int) (int, error)
- func Rule_1_6(r *Result, pos int) (int, error)
- func Rule_1_7(r *Result, pos int) (int, error)
- func Rule_1_7_question(r *Result, pos int) (int, error)
- func SpecialHandler(r *Result, pos int) (int, error)
- func Special_1(r *Result, pos int) (int, error)
- func Special_1_1(r *Result, pos int) (int, error)
- func Special_1_2(r *Result, pos int) (int, error)
- func Special_1_2_capture(r *Result, pos int) (int, error)
- func Special_1_2_capture_1(r *Result, pos int) (int, error)
- func Special_1_2_capture_1_1(r *Result, pos int) (int, error)
- func TermHandler(r *Result, pos int) (int, error)
- func Term_1(r *Result, pos int) (int, error)
- func Term_1_1(r *Result, pos int) (int, error)
- func Term_2(r *Result, pos int) (int, error)
- func Term_2_1(r *Result, pos int) (int, error)
- func Term_3(r *Result, pos int) (int, error)
- func Term_3_1(r *Result, pos int) (int, error)
- func Term_4(r *Result, pos int) (int, error)
- func Term_4_1(r *Result, pos int) (int, error)
- func Term_5(r *Result, pos int) (int, error)
- func Term_5_1(r *Result, pos int) (int, error)
- func Term_6(r *Result, pos int) (int, error)
- func Term_6_1(r *Result, pos int) (int, error)
- func Term_7(r *Result, pos int) (int, error)
- func Term_7_1(r *Result, pos int) (int, error)
- func Term_8(r *Result, pos int) (int, error)
- func Term_8_1(r *Result, pos int) (int, error)
- func TermsHandler(r *Result, pos int) (int, error)
- func Terms_1(r *Result, pos int) (int, error)
- func Terms_1_1(r *Result, pos int) (int, error)
- func Terms_1_1_plus(r *Result, pos int) (int, error)
- type Accessor
- type AccessorOptions
- type Grammar
- type NodeStack
- type RHS
- type Result
- type Rule
- type Special
- type Term
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeCharClassHandler ¶
func MakeDotHandler ¶
func MakeLiteralHandler ¶
func MakePlusHandler ¶
func MakePredicateHandler ¶
func MakeQuestionHandler ¶
func MakeStarHandler ¶
Types ¶
type Accessor ¶
type Accessor interface { // Node returns the parse tree node that is currently being converted // (so technically this is not about child access). Node() *parser.Node // String returns the string value associated with a child node. // In case of error it records the error and returns empty string. String(name string) string // GetString returns the string value associated with a child node. // It returns an error if the requested child node does not exist // or has different type. GetString(name string) (string, error) // Get returns the interface type matching the given type instance. // In case of error it records the error and returns nil. Get(name string, ty interface{}) interface{} // GetTyped returns the interface type matching the given type instance. // If the requested child does not exist or has different type, it returns // an error. If the requested type is a slice, and only one child instance // exists, it is returned as an 1-element slice. GetTyped(name string, ty interface{}) (interface{}, error) // Returns the node label of the ith child in the parse tree. If the index // is out of bounds, it records an error and Child(i int) string }
Accessor is the interface given to the callback during the semantic tree construction.
type AccessorOptions ¶
type AccessorOptions struct { // If true, the Check() method will return error if it detects that some // of children node were converted to non-trivial semantic subtrees, // but were not used during semantic tree construction of this node. ErrorOnUnusedChild bool }
AccessorOptions configures the behavior of error checking of Accessor.
type Grammar ¶
type Grammar struct { // Rule is a dictionary of rules. Rules map[string]*Rule // RuleNames keeps the list of rule name in the original definition order. RuleNames []string Source string }
Grammar represents the complete PEG grammar.
func ConvertGrammar2 ¶
ConvertGrammar2 is a reimplementation of the semantic tree reconstruction using callbacks.
type RHS ¶
type RHS struct { // Terms is the RHS, top iteration over choices, and inside // iteration over concatenation of terms. Terms [][]*Term }
RHS is the right-hand side of one rule or the contents of parenthesized expression.
type Result ¶
type Rule ¶
type Rule struct { // Ident is the name of the rule, defined in LHS. Ident string // RHS is the rule's right-hand side. *RHS }
Rule represent one PEG rule (Rule <- RHS).
type Term ¶
type Term struct { Parens *RHS NegPred *Term Pred *Term *Special Capture *RHS *charclass.CharClass Literal string Ident string }
Term is one term. Note: Special characters in the grammar are handled specially and are not mapped to Term one-to-one. Instead, *?+ combine with the previous Term, and . is converted to a special CharClass.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
parse-grammar
Binary parse-grammar-main is a utility binary to read parse and print PEG grammars.
|
Binary parse-grammar-main is a utility binary to read parse and print PEG grammars. |
Binary main shows an example of using the parser that was generated from parser expression grammar (PEG).
|
Binary main shows an example of using the parser that was generated from parser expression grammar (PEG). |
Package gogen contains a few functions for ad-hoc generation of Go source snippets.
|
Package gogen contains a few functions for ad-hoc generation of Go source snippets. |
Package template provides the code templates that are emitted to generate the parser.
|
Package template provides the code templates that are emitted to generate the parser. |
Binary gentests is used to generated the test sources from the tests package.
|
Binary gentests is used to generated the test sources from the tests package. |