func (c *CodeBlock) String() string {
	return fmt.Sprintf("%s: %T{Val: %q}", c.p, c, c.Val)
}
String returns the textual representation of a node.
package ast
import (
	"bytes"
	"fmt"
	"strconv"
	"strings"
)
type Pos struct {
	Filename string
	Line     int
	Col      int
	Off      int
}
func (p Pos) String() string {
	if p.Filename != "" {
		return fmt.Sprintf("%s:%d:%d (%d)", p.Filename, p.Line, p.Col, p.Off)
	}
	return fmt.Sprintf("%d:%d (%d)", p.Line, p.Col, p.Off)
}
type Grammar struct {
	p     Pos
	Init  *CodeBlock
	Rules []*Rule
}
func NewGrammar(p Pos) *Grammar {
	return &Grammar{p: p}
}
func (g *Grammar) Pos() Pos { return g.p }
func (g *Grammar) String() string {
	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%s: %T{Init: %v, Rules: [\n",
		g.p, g, g.Init))
	for _, r := range g.Rules {
		buf.WriteString(fmt.Sprintf("%s,\n", r))
	}
	buf.WriteString("]}")
	return buf.String()
}
type Rule struct {
	p           Pos
	Name        *Identifier
	DisplayName *StringLit
	Expr        Expression
}
func NewRule(p Pos, name *Identifier) *Rule {
	return &Rule{p: p, Name: name}
}
func (r *Rule) Pos() Pos { return r.p }
func (r *Rule) String() string {
	return fmt.Sprintf("%s: %T{Name: %v, DisplayName: %v, Expr: %v}",
		r.p, r, r.Name, r.DisplayName, r.Expr)
}
type Expression interface {
	Pos() Pos
}
type ChoiceExpr struct {
	p            Pos
	Alternatives []Expression
}
func NewChoiceExpr(p Pos) *ChoiceExpr {
	return &ChoiceExpr{p: p}
}
func (c *ChoiceExpr) Pos() Pos { return c.p }
func (c *ChoiceExpr) String() string {
	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%s: %T{Alternatives: [\n", c.p, c))
	for _, e := range c.Alternatives {
		buf.WriteString(fmt.Sprintf("%s,\n", e))
	}
	buf.WriteString("]}")
	return buf.String()
}
type FailureLabel string
type RecoveryExpr struct {
	p           Pos
	Expr        Expression
	RecoverExpr Expression
	Labels      []FailureLabel
}
func NewRecoveryExpr(p Pos) *RecoveryExpr {
	return &RecoveryExpr{p: p}
}
func (r *RecoveryExpr) Pos() Pos { return r.p }
func (r *RecoveryExpr) String() string {
	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%s: %T{Expr: %v, RecoverExpr: %v", r.p, r, r.Expr, r.RecoverExpr))
	buf.WriteString(fmt.Sprintf(", Labels: [\n"))
	for _, e := range r.Labels {
		buf.WriteString(fmt.Sprintf("%s,\n", e))
	}
	buf.WriteString("]}")
	return buf.String()
}
type ActionExpr struct {
	p      Pos
	Expr   Expression
	Code   *CodeBlock
	FuncIx int
}
func NewActionExpr(p Pos) *ActionExpr {
	return &ActionExpr{p: p}
}
func (a *ActionExpr) Pos() Pos { return a.p }
func (a *ActionExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v, Code: %v}", a.p, a, a.Expr, a.Code)
}
type ThrowExpr struct {
	p     Pos
	Label string
}
func NewThrowExpr(p Pos) *ThrowExpr {
	return &ThrowExpr{p: p}
}
func (t *ThrowExpr) Pos() Pos { return t.p }
func (t *ThrowExpr) String() string {
	return fmt.Sprintf("%s: %T{Label: %v}", t.p, t, t.Label)
}
type SeqExpr struct {
	p     Pos
	Exprs []Expression
}
func NewSeqExpr(p Pos) *SeqExpr {
	return &SeqExpr{p: p}
}
func (s *SeqExpr) Pos() Pos { return s.p }
func (s *SeqExpr) String() string {
	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%s: %T{Exprs: [\n", s.p, s))
	for _, e := range s.Exprs {
		buf.WriteString(fmt.Sprintf("%s,\n", e))
	}
	buf.WriteString("]}")
	return buf.String()
}
type LabeledExpr struct {
	p     Pos
	Label *Identifier
	Expr  Expression
}
func NewLabeledExpr(p Pos) *LabeledExpr {
	return &LabeledExpr{p: p}
}
func (l *LabeledExpr) Pos() Pos { return l.p }
func (l *LabeledExpr) String() string {
	return fmt.Sprintf("%s: %T{Label: %v, Expr: %v}", l.p, l, l.Label, l.Expr)
}
type AndExpr struct {
	p    Pos
	Expr Expression
}
func NewAndExpr(p Pos) *AndExpr {
	return &AndExpr{p: p}
}
func (a *AndExpr) Pos() Pos { return a.p }
func (a *AndExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v}", a.p, a, a.Expr)
}
type NotExpr struct {
	p    Pos
	Expr Expression
}
func NewNotExpr(p Pos) *NotExpr {
	return &NotExpr{p: p}
}
func (n *NotExpr) Pos() Pos { return n.p }
func (n *NotExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v}", n.p, n, n.Expr)
}
type ZeroOrOneExpr struct {
	p    Pos
	Expr Expression
}
func NewZeroOrOneExpr(p Pos) *ZeroOrOneExpr {
	return &ZeroOrOneExpr{p: p}
}
func (z *ZeroOrOneExpr) Pos() Pos { return z.p }
func (z *ZeroOrOneExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v}", z.p, z, z.Expr)
}
type ZeroOrMoreExpr struct {
	p    Pos
	Expr Expression
}
func NewZeroOrMoreExpr(p Pos) *ZeroOrMoreExpr {
	return &ZeroOrMoreExpr{p: p}
}
func (z *ZeroOrMoreExpr) Pos() Pos { return z.p }
func (z *ZeroOrMoreExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v}", z.p, z, z.Expr)
}
type OneOrMoreExpr struct {
	p    Pos
	Expr Expression
}
func NewOneOrMoreExpr(p Pos) *OneOrMoreExpr {
	return &OneOrMoreExpr{p: p}
}
func (o *OneOrMoreExpr) Pos() Pos { return o.p }
func (o *OneOrMoreExpr) String() string {
	return fmt.Sprintf("%s: %T{Expr: %v}", o.p, o, o.Expr)
}
type RuleRefExpr struct {
	p    Pos
	Name *Identifier
}
func NewRuleRefExpr(p Pos) *RuleRefExpr {
	return &RuleRefExpr{p: p}
}
func (r *RuleRefExpr) Pos() Pos { return r.p }
func (r *RuleRefExpr) String() string {
	return fmt.Sprintf("%s: %T{Name: %v}", r.p, r, r.Name)
}
type StateCodeExpr struct {
	p      Pos
	Code   *CodeBlock
	FuncIx int
}
func NewStateCodeExpr(p Pos) *StateCodeExpr {
	return &StateCodeExpr{p: p}
}
func (s *StateCodeExpr) Pos() Pos { return s.p }
func (s *StateCodeExpr) String() string {
	return fmt.Sprintf("%s: %T{Code: %v}", s.p, s, s.Code)
}
type AndCodeExpr struct {
	p      Pos
	Code   *CodeBlock
	FuncIx int
}
func NewAndCodeExpr(p Pos) *AndCodeExpr {
	return &AndCodeExpr{p: p}
}
func (a *AndCodeExpr) Pos() Pos { return a.p }
func (a *AndCodeExpr) String() string {
	return fmt.Sprintf("%s: %T{Code: %v}", a.p, a, a.Code)
}
type NotCodeExpr struct {
	p      Pos
	Code   *CodeBlock
	FuncIx int
}
func NewNotCodeExpr(p Pos) *NotCodeExpr {
	return &NotCodeExpr{p: p}
}
func (n *NotCodeExpr) Pos() Pos { return n.p }
func (n *NotCodeExpr) String() string {
	return fmt.Sprintf("%s: %T{Code: %v}", n.p, n, n.Code)
}
type LitMatcher struct {
	posValue    
	IgnoreCase bool
}
func NewLitMatcher(p Pos, v string) *LitMatcher {
	return &LitMatcher{posValue: posValue{p: p, Val: v}}
}
func (l *LitMatcher) Pos() Pos { return l.p }
func (l *LitMatcher) String() string {
	return fmt.Sprintf("%s: %T{Val: %q, IgnoreCase: %t}", l.p, l, l.Val, l.IgnoreCase)
}
type CharClassMatcher struct {
	posValue
	IgnoreCase     bool
	Inverted       bool
	Chars          []rune
	Ranges         []rune  
	UnicodeClasses []string
}
func NewCharClassMatcher(p Pos, raw string) *CharClassMatcher {
	c := &CharClassMatcher{posValue: posValue{p: p, Val: raw}}
	c.parse()
	return c
}
func (c *CharClassMatcher) parse() {
	raw := c.Val
	c.IgnoreCase = strings.HasSuffix(raw, "i")
	if c.IgnoreCase {
		raw = raw[:len(raw)-1]
	}
	raw = raw[1 : len(raw)-1]
	if len(raw) == 0 {
		return
	}
	c.Inverted = raw[0] == '^'
	if c.Inverted {
		raw = raw[1:]
		if len(raw) == 0 {
			return
		}
	}
	r := strings.NewReader(raw)
	var chars []rune
	var buf bytes.Buffer
outer:
	for {
		rn, _, err := r.ReadRune()
		if err != nil {
			break outer
		}
		consumeN := 0
		switch rn {
		case '\\':
			rn, _, _ := r.ReadRune()
			switch rn {
			case ']':
				chars = append(chars, rn)
				continue
			case 'p':
				rn, _, _ := r.ReadRune()
				if rn == '{' {
					buf.Reset()
					for {
						rn, _, _ := r.ReadRune()
						if rn == '}' {
							break
						}
						buf.WriteRune(rn)
					}
					c.UnicodeClasses = append(c.UnicodeClasses, buf.String())
				} else {
					c.UnicodeClasses = append(c.UnicodeClasses, string(rn))
				}
				continue
			case 'x':
				consumeN = 2
			case 'u':
				consumeN = 4
			case 'U':
				consumeN = 8
			case '0', '1', '2', '3', '4', '5', '6', '7':
				consumeN = 2
			}
			buf.Reset()
			buf.WriteRune(rn)
			for i := 0; i < consumeN; i++ {
				rn, _, _ := r.ReadRune()
				buf.WriteRune(rn)
			}
			rn, _, _, _ = strconv.UnquoteChar("\\"+buf.String(), 0)
			chars = append(chars, rn)
		default:
			chars = append(chars, rn)
		}
	}
	inRange, wasRange := false, false
	for i, r := range chars {
		if inRange {
			c.Ranges = append(c.Ranges, r)
			inRange = false
			wasRange = true
			continue
		}
		if r == '-' && !wasRange && len(c.Chars) > 0 && i < len(chars)-1 {
			inRange = true
			wasRange = false
			c.Ranges = append(c.Ranges, c.Chars[len(c.Chars)-1])
			c.Chars = c.Chars[:len(c.Chars)-1]
			continue
		}
		wasRange = false
		c.Chars = append(c.Chars, r)
	}
}
func (c *CharClassMatcher) Pos() Pos { return c.p }
func (c *CharClassMatcher) String() string {
	return fmt.Sprintf("%s: %T{Val: %q, IgnoreCase: %t, Inverted: %t}",
		c.p, c, c.Val, c.IgnoreCase, c.Inverted)
}
type AnyMatcher struct {
	posValue
}
func NewAnyMatcher(p Pos, v string) *AnyMatcher {
	return &AnyMatcher{posValue{p, v}}
}
func (a *AnyMatcher) Pos() Pos { return a.p }
func (a *AnyMatcher) String() string {
	return fmt.Sprintf("%s: %T{Val: %q}", a.p, a, a.Val)
}
type CodeBlock struct {
	posValue
}
func NewCodeBlock(p Pos, code string) *CodeBlock {
	return &CodeBlock{posValue{p, code}}
}
func (c *CodeBlock) Pos() Pos { return c.p }