Documentation
¶
Index ¶
- func PrintFragment(fragment Fragment, out io.Writer, indent string) (bytesWritten int, err error)
- type Action
- type Checked
- type Construct
- type Cursor
- type Either
- type Err
- type ErrUnexpectedToken
- type Fragment
- type FragmentKind
- type Lexer
- type OneOrMore
- type Optional
- type Parser
- type Pattern
- type Rule
- type Scanner
- func (sc *Scanner) Append(pattern Pattern, fragment Fragment)
- func (sc *Scanner) Fragment(kind FragmentKind) Fragment
- func (sc *Scanner) New() *Scanner
- func (sc *Scanner) Read() (*Token, error)
- func (sc *Scanner) ReadExact(expectation string, kind FragmentKind) (*Token, bool, error)
- func (sc *Scanner) Set(cursor Cursor)
- func (sc *Scanner) TidyUp() int
- type Sequence
- type SourceFile
- type Term
- type TermExact
- type Token
- type ZeroOrMore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
Action represents a callback function that's called when a certain fragment is matched
type Checked ¶
Checked represents an arbitrary terminal token pattern matched by a function
func (Checked) TerminalPattern ¶
TerminalPattern implements the Pattern interface
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 Fragment ¶
type Fragment interface {
Kind() FragmentKind
Begin() Cursor
End() Cursor
Src() string
Elements() []Fragment
}
Fragment represents an abstract fragment
type Lexer ¶
type Lexer interface {
Read() (*Token, error)
ReadExact(
expectation string,
kind FragmentKind,
) (
token *Token,
matched bool,
err error,
)
Position() Cursor
Set(Cursor)
}
Lexer defines the interface of an abstract lexer implementation
type OneOrMore ¶
type OneOrMore struct{ Pattern }
OneOrMore represents at least one arbitrary patterns
func (OneOrMore) TerminalPattern ¶
TerminalPattern implements the Pattern interface
type Optional ¶
type Optional struct{ Pattern }
Optional represents an arbitrary optional pattern
func (Optional) TerminalPattern ¶
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 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 Scanner ¶
Scanner represents a sequence-recording lexing source-code scanner
func (*Scanner) Fragment ¶
func (sc *Scanner) Fragment(kind FragmentKind) Fragment
Fragment returns a typed composite fragment
func (*Scanner) New ¶
New creates a new scanner succeeding the original one dropping its record history
func (*Scanner) Read ¶
Read advances the scanner by 1 token returning either the read fragment or an error if the lexer failed
func (*Scanner) ReadExact ¶
ReadExact advances the scanner by 1 exact token returning either the read fragment or nil if the expectation didn't match
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 Term ¶
type Term FragmentKind
Term represents a concrete terminal token pattern
func (Term) TerminalPattern ¶
TerminalPattern implements the Pattern interface
type TermExact ¶
type TermExact struct {
Kind FragmentKind
Expectation string
}
TermExact represents an exact terminal token pattern
func (TermExact) TerminalPattern ¶
TerminalPattern implements the Pattern interface
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
type ZeroOrMore ¶
type ZeroOrMore struct{ Pattern }
ZeroOrMore represents zero or more arbitrary patterns
func (ZeroOrMore) Container ¶
func (ZeroOrMore) Container() bool
Container implements the Pattern interface
func (ZeroOrMore) Desig ¶
func (zom ZeroOrMore) Desig() string
Desig implements the Pattern interface
func (ZeroOrMore) TerminalPattern ¶
func (zom ZeroOrMore) TerminalPattern() Pattern
TerminalPattern implements the Pattern interface