Documentation
¶
Index ¶
- func PrintFragment(fragment Fragment, options FragPrintOptions) (bytesWritten int, err 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
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
HeadFmt func(*Token) []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
Fn func(Cursor) uint
}
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 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