Documentation
¶
Overview ¶
Package parser implements R7RS Scheme syntax parsing.
The parser converts a token stream into syntax values with source location:
Features ¶
- All Scheme datums: literals, symbols, lists, vectors, bytevectors
- Full numeric tower: integers, floats, rationals, complex, big numbers
- Quote forms: ', `, ,, ,@ and syntax variants #', #`, #,, #,@
- Datum labels: #n= and #n# for shared/circular structures (R7RS 2.4)
- Case folding: #!fold-case and #!no-fold-case directives
- Symbol interning at parse time
Usage ¶
p := parser.NewParserWithFile(env, true, reader, "example.scm")
for {
stx, err := p.ReadSyntax(ctx)
if err == io.EOF {
break
}
// process stx
}
Error Handling ¶
Parse errors are wrapped in ParserError with source location from the offending token. The parser accumulates no state across expressions.
Index ¶
- Constants
- Variables
- func TrimPrefixFolded(s, prefix string) string
- func TrimSuffixFolded(s, suffix string) string
- type Parser
- type ParserError
- func NewParserError(tok tokenizer.Token, mess string) *ParserError
- func NewParserErrorWithWrap(err error, tok tokenizer.Token, mess string) *ParserError
- func NewParserErrorWithWrapf(err error, tok tokenizer.Token, mess string, vs ...any) *ParserError
- func NewParserErrorf(tok tokenizer.Token, mess string, vs ...any) *ParserError
Constants ¶
const ( ConstQuote = "quote" ConstQuasiquote = "quasiquote" ConstUnquote = "unquote" ConstUnquoteSplicing = "unquote-splicing" ConstSyntax = "syntax" ConstQuasisyntax = "quasisyntax" ConstUnsyntax = "unsyntax" ConstUnsyntaxSplicing = "unsyntax-splicing" )
Quote form identifiers.
const ( RuneAlarm = rune('\a') RuneSpace = rune(' ') RuneBackspace = rune('\b') RuneFormFeed = rune('\f') RuneRubout = rune(127) RuneEscape = rune(27) RuneNewline = rune('\n') RuneNull = rune(0) RuneReturn = rune('\r') RuneTab = rune('\t') RuneVerticalTab = rune('\v') )
Character mnemonic runes.
const (
ParserNumberDefaultBase = 10
)
Variables ¶
var ( // ErrUnknownTokenType is returned when the parser encounters an unrecognized token. ErrUnknownTokenType = values.NewStaticError("unknown token type") ErrAlreadyClosed = values.NewStaticError("parser already closed") )
Functions ¶
func TrimPrefixFolded ¶
TrimPrefixFolded performs a case-insensitive trim of the specified prefix from the string s. If s does not start with the prefix (case-insensitive), s is returned unchanged. functionally,its identical to strings.TrimPrefix but case-insensitive.
func TrimSuffixFolded ¶
TrimSuffixFolded performs a case-insensitive trim of the specified suffix from the string s. If s does not end with the suffix (case-insensitive), s is returned unchanged. functionally,its identical to strings.TrimSuffix but case-insensitive.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a R7RS compliant Scheme syntax parser.
func NewParser ¶
func NewParser(env *environment.EnvironmentFrame, skipComments bool, rdr io.RuneReader) *Parser
NewParser creates a new parser for the given reader and environment.
func NewParserWithFile ¶
func NewParserWithFile(env *environment.EnvironmentFrame, skipComments bool, rdr io.RuneReader, file string) *Parser
NewParserWithFile creates a new parser with a specified source filename.
func (*Parser) ReadSyntax ¶
ReadSyntax reads and returns the next syntax value from the input.
type ParserError ¶
type ParserError struct {
// contains filtered or unexported fields
}
ParserError represents an error that occurred during parsing.
func NewParserError ¶
func NewParserError(tok tokenizer.Token, mess string) *ParserError
NewParserError creates a new parser error for the given token.
func NewParserErrorWithWrap ¶
func NewParserErrorWithWrap(err error, tok tokenizer.Token, mess string) *ParserError
NewParserErrorWithWrap creates a new parser error wrapping another error.
func NewParserErrorWithWrapf ¶
NewParserErrorWithWrapf creates a new parser error wrapping another error.
func NewParserErrorf ¶
func NewParserErrorf(tok tokenizer.Token, mess string, vs ...any) *ParserError
NewParserErrorf creates a new parser error for the given token.
func (*ParserError) Error ¶
func (p *ParserError) Error() string
func (*ParserError) Is ¶
func (p *ParserError) Is(err error) bool
Is implements errors.Is for ParserError.
func (*ParserError) IsVoid ¶
func (p *ParserError) IsVoid() bool
func (*ParserError) SchemeString ¶
func (p *ParserError) SchemeString() string
func (*ParserError) Unwrap ¶
func (p *ParserError) Unwrap() error