Documentation ¶
Index ¶
- Constants
- Variables
- func ReadComment(rd *Reader, _ rune) (sxpf.Object, error)
- func UnmatchedDelimiter(rd *Reader, firstCh rune) (sxpf.Object, error)
- func WithDefaultSymbolFactory(rd *Reader)
- type Error
- type Macro
- type MacroMap
- type Option
- type Position
- type Reader
- func (rd *Reader) AnnotateError(err error, begin Position) error
- func (*Reader) IsSpace(ch rune) bool
- func (rd *Reader) IsTerminal(ch rune) bool
- func (rd *Reader) Name() string
- func (rd *Reader) NextRune() (rune, error)
- func (rd *Reader) Position() Position
- func (rd *Reader) Read() (sxpf.Object, error)
- func (rd *Reader) ReadAll() (objs []sxpf.Object, _ error)
- func (rd *Reader) ReadToken(firstCh rune, isTerminal func(rune) bool) (string, error)
- func (rd *Reader) SetMacro(initCh rune, macro Macro)
- func (rd *Reader) SkipSpace() (rune, error)
- func (rd *Reader) SymbolFactory() sxpf.SymbolFactory
- func (rd *Reader) Unread(chs ...rune)
Constants ¶
const DefaultListLimit = 10000
DefaultListLimit specifies the default valur for `WithListLimit`.
const DefaultNestingLimit = 1000
DefaultNestingLimit specifies the default value for `WithNestingLimit`.
Variables ¶
var ErrEOF = errors.New("unexpected EOF while reading")
ErrEOF is returned when reader ends prematurely to indicate that more data is needed to complete the current s-expression.
var ErrListTooLong = errors.New("list too long")
ErrListTooLong is returned, if the reader should read a list that is too long.
var ErrNumberFormat = errors.New("invalid number format")
ErrNumberFormat is returned when a reader macro encounters a invalid number.
var ErrPairFormat = errors.New("invalid pair format")
ErrPairFormat signals an invalid pair.
var ErrSkip = errors.New("skip s-expression")
ErrSkip signals a caller that the read value should be skipped. Typically, the read method is called again. Mostly used to implement comments at the lexical level.
var ErrTooDeeplyNested = errors.New("too deeply nested")
ErrTooDeeplyNested is returned, if the reader should read an object that is too deeply nested.
Functions ¶
func ReadComment ¶
ReadComment is a reader macro that ignores everything until EOL.
func UnmatchedDelimiter ¶
UnmatchedDelimiter is a reader macro that signals the error of an unmatched delimiter, e.g. a closing parenthesis.
func WithDefaultSymbolFactory ¶
func WithDefaultSymbolFactory(rd *Reader)
WithDefaultSymbolFactory sets a new symbol factory. Use this option, if following options need a defined symbol factory.
Types ¶
type Error ¶
Error is returned when reading fails due to some issue. Use errors.Is() with Cause to check for specific underlying errors.
type Option ¶
type Option func(*Reader)
Option is a function to modify the default reader when it is made.
func WithListLimit ¶
WithListLimit sets the maximum length of a list.
func WithNestingLimit ¶
WithNestingLimit sets the maximum nesting for a object.
func WithSymbolFactory ¶
func WithSymbolFactory(sf sxpf.SymbolFactory) Option
WithSymbolFactory sets the symbol factory to a defined value.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader consumes characters from a stream and parses them into s-expressions.
func MakeReader ¶
MakeReader creates a new reader.
func (*Reader) AnnotateError ¶
AnnotateError adds error information (reader.Name, position) to the given error.
func (*Reader) IsTerminal ¶
IsTerminal returns true, if rune terminates the current token, according to the given read macro map.
func (*Reader) ReadToken ¶
ReadToken reads a sequence of non-terminal runes from the reader. if initCh > ' ', it is included as the first char.
func (*Reader) SetMacro ¶
SetMacro sets the given read macro for the given initial character. If macro is nil, the initial character will not start a read macro.
func (*Reader) SkipSpace ¶
SkipSpace skips all space rune from the reader and return the first non-space rune.
func (*Reader) SymbolFactory ¶
func (rd *Reader) SymbolFactory() sxpf.SymbolFactory
SymbolFactory returns the symbol factory that is used in the reader.