Documentation ¶
Index ¶
- func PrintFragment(fragment Fragment, options FragPrintOptions) (bytesWritten int, err error)
- func ValidatePattern(ptr Pattern) error
- type Action
- type Construct
- type Cursor
- type Either
- type Err
- type ErrUnexpectedToken
- type Exact
- type FragPrintOptions
- type Fragment
- type FragmentKind
- type Lexed
- type Not
- type Parser
- type Pattern
- type Repeated
- type Rule
- type Sequence
- type SourceFile
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintFragment ¶
func PrintFragment( fragment Fragment, options FragPrintOptions, ) (bytesWritten int, err error)
PrintFragment prints the fragment structure recursively
func ValidatePattern ¶ added in v0.7.0
ValidatePattern recursively validates the given pattern
Types ¶
type Action ¶
Action represents a callback function that's called when a certain fragment is matched
type Cursor ¶
type Cursor struct { Index uint Column uint Line uint File *SourceFile }
Cursor represents a source-code location
func NewCursor ¶
func NewCursor(file *SourceFile) Cursor
NewCursor creates a new cursor location based on the given source file
type Either ¶
type Either []Pattern
Either represents either of the arbitrary patterns
func (Either) TerminalPattern ¶
TerminalPattern implements the Pattern interface
type ErrUnexpectedToken ¶
ErrUnexpectedToken represents a parser error
func (*ErrUnexpectedToken) Error ¶
func (err *ErrUnexpectedToken) Error() string
type Exact ¶ added in v0.3.0
type Exact struct { Kind FragmentKind Expectation []rune }
Exact represents an exact terminal token pattern
func (*Exact) TerminalPattern ¶ added in v0.3.0
TerminalPattern implements the Pattern interface
type FragPrintOptions ¶ added in v0.5.0
type FragPrintOptions struct { Out io.Writer Indentation []byte Prefix []byte LineBreak []byte Format func(Fragment) (head, body []byte) }
FragPrintOptions defines the AST printing options
type Fragment ¶
type Fragment interface { Kind() FragmentKind Begin() Cursor End() Cursor Src() []rune Elements() []Fragment }
Fragment represents an abstract fragment
type Lexed ¶ added in v0.2.0
type Lexed struct { Kind FragmentKind Designation string MinLen uint Fn func(index uint, cursor Cursor) bool }
Lexed represents a lexed pattern
func (*Lexed) TerminalPattern ¶ added in v0.2.0
TerminalPattern implements the Pattern interface
type Not ¶ added in v0.6.0
type Not struct {
Pattern Pattern
}
Not represents a pattern that's expected to not be matched
func (Not) TerminalPattern ¶ added in v0.6.0
TerminalPattern implements the Pattern interface
type Parser ¶
type Parser struct { // MaxRecursionLevel defines the maximum tolerated recursion level. // The limitation is disabled when MaxRecursionLevel is set to 0 MaxRecursionLevel uint // contains filtered or unexported fields }
Parser represents a parser
type Pattern ¶
type Pattern interface { // Container returns true for container patterns Container() bool // TerminalPattern returns the terminal pattern for composite patterns // and nil for non-terminal patterns TerminalPattern() Pattern // Desig returns the textual designation of the pattern Desig() string }
Pattern represents an abstract pattern
type Repeated ¶ added in v0.4.0
Repeated represents at least one arbitrary patterns
func (*Repeated) TerminalPattern ¶ added in v0.4.0
TerminalPattern implements the Pattern interface
type Rule ¶
type Rule struct { Designation string Pattern Pattern Kind FragmentKind Action Action }
Rule represents a grammatic rule
func (*Rule) TerminalPattern ¶
TerminalPattern implements the Pattern interface
type Sequence ¶
type Sequence []Pattern
Sequence represents an exact sequence of arbitrary patterns
func (Sequence) TerminalPattern ¶
TerminalPattern implements the Pattern interface
type SourceFile ¶
SourceFile represents a source file
type Token ¶
type Token struct { VBegin Cursor VEnd Cursor VKind FragmentKind }
Token represents a terminal fragment
func (*Token) Kind ¶
func (tk *Token) Kind() FragmentKind
Kind returns the kind of the token fragment