rfcparser

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToInt

func ByteToInt(b byte) int

func ByteToLower

func ByteToLower(b byte) byte

func IsAStringChar

func IsAStringChar(tokenType TokenType) bool

func IsAtomChar

func IsAtomChar(tokenType TokenType) bool

func IsCTL

func IsCTL(tokenType TokenType) bool

func IsError

func IsError(err error) bool

func IsQuotedChar

func IsQuotedChar(tokenType TokenType) bool

func IsQuotedSpecial

func IsQuotedSpecial(tokenType TokenType) bool

func IsRespSpecial

func IsRespSpecial(tokenType TokenType) bool

Types

type Bytes

type Bytes struct {
	Value  []byte
	Offset int
}

func (Bytes) IntoString

func (c Bytes) IntoString() String

type Error

type Error struct {
	Token   Token
	Message string
}

func (*Error) Error

func (p *Error) Error() string

func (*Error) IsEOF

func (p *Error) IsEOF() bool

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser provide facilities to consumes tokens from a given scanner. Advance should be called at least once before any checks in order to initialize the previousToken.

func NewParser

func NewParser(s *Scanner) *Parser

func NewParserWithLiteralContinuationCb

func NewParserWithLiteralContinuationCb(s *Scanner, f func() error) *Parser

func (*Parser) Advance

func (p *Parser) Advance() error

Advance advances the scanner to the next token.

func (*Parser) Check

func (p *Parser) Check(tokenType TokenType) bool

Check if the next token matches the given input.

func (*Parser) CheckWith

func (p *Parser) CheckWith(f func(tokenType TokenType) bool) bool

CheckWith checks if the next token matches the given condition.

func (*Parser) CollectBytesWhileMatches

func (p *Parser) CollectBytesWhileMatches(tokenType TokenType) (Bytes, error)

CollectBytesWhileMatches collects bytes from the token scanner while tokens match the given token type. This function DOES NOT INCLUDE the previous token consumed before this call.

func (*Parser) CollectBytesWhileMatchesWith

func (p *Parser) CollectBytesWhileMatchesWith(f func(tokenType TokenType) bool) (Bytes, error)

CollectBytesWhileMatchesWith collects bytes from the token scanner while tokens match the given condition. This function DOES NOT INCLUDE the previous token consumed before this call.

func (*Parser) CollectBytesWhileMatchesWithPrev

func (p *Parser) CollectBytesWhileMatchesWithPrev(tokenType TokenType) (Bytes, error)

CollectBytesWhileMatchesWithPrev collects bytes from the token scanner while tokens match the given token type. This function INCLUDES the previous token consumed before this call.

func (*Parser) CollectBytesWhileMatchesWithPrevWith

func (p *Parser) CollectBytesWhileMatchesWithPrevWith(f func(tokenType TokenType) bool) (Bytes, error)

CollectBytesWhileMatchesWithPrevWith collects bytes from the token scanner while tokens match the given condition. This function INCLUDES the previous token consumed before this call.

func (*Parser) Consume

func (p *Parser) Consume(tokenType TokenType, message string) error

Consume will advance the scanner to the next token if the current token matches the given token. If current token does not match, an error with given message will be returned.

func (*Parser) ConsumeBytes

func (p *Parser) ConsumeBytes(chars ...byte) error

ConsumeBytes will advance if the next token value matches the given sequence.

func (*Parser) ConsumeBytesFold

func (p *Parser) ConsumeBytesFold(chars ...byte) error

ConsumeBytesFold behaves the same as ConsumeBytes, but case insensitive for characters.

func (*Parser) ConsumeNewLine

func (p *Parser) ConsumeNewLine() error

ConsumeNewLine issues two Consume calls for the `CRLF` token sequence.

func (*Parser) ConsumeWith

func (p *Parser) ConsumeWith(f func(token TokenType) bool, message string) error

ConsumeWith will advance the scanner to the next token if the current token matches the given condition. If current token does not match, an error with given message will be returned.

func (*Parser) CurrentToken

func (p *Parser) CurrentToken() Token

func (*Parser) MakeError

func (p *Parser) MakeError(err string) error

func (*Parser) MakeErrorAtOffset

func (p *Parser) MakeErrorAtOffset(err string, offset int) error

func (*Parser) Matches

func (p *Parser) Matches(tokenType TokenType) (bool, error)

Matches will advance the scanner to the next token and return true if the current token matches the given tokenType.

func (*Parser) MatchesWith

func (p *Parser) MatchesWith(f func(tokenType TokenType) bool) (bool, error)

MatchesWith will advance the scanner to the next token and return true if the current token matches the given condition.

func (*Parser) ParseAString

func (p *Parser) ParseAString() (String, error)

ParseAString parses an astring according to RFC3501.

func (*Parser) ParseAtom

func (p *Parser) ParseAtom() (string, error)

func (*Parser) ParseLiteral

func (p *Parser) ParseLiteral() ([]byte, error)

ParseLiteral parses a literal as defined in RFC3501.

func (*Parser) ParseNumber

func (p *Parser) ParseNumber() (int, error)

ParseNumber parses a non decimal number without any signs.

func (*Parser) ParseNumberN

func (p *Parser) ParseNumberN(n int) (int, error)

ParseNumberN parses a non decimal with N digits.

func (*Parser) ParseQuoted

func (p *Parser) ParseQuoted() (String, error)

ParseQuoted parses a quoted string.

func (*Parser) ParseString

func (p *Parser) ParseString() (String, error)

ParseString parses a string according to RFC3501.

func (*Parser) PreviousToken

func (p *Parser) PreviousToken() Token

func (*Parser) ResetOffsetCounter

func (p *Parser) ResetOffsetCounter()

ResetOffsetCounter resets the token offset back to 0.

func (*Parser) RestoreState

func (p *Parser) RestoreState(state ParserState)

RestoreState restores the previous and current tokens from the given state. NOTE: If this is called without adjusting the scanner input to the location where these were recorded you can break your parsing.

func (*Parser) SaveState

func (p *Parser) SaveState() ParserState

SaveState saves the current and previous token state so it can potentially be restored later with RestoreState.

func (*Parser) TryParseString

func (p *Parser) TryParseString() (String, bool, error)

type ParserState

type ParserState struct {
	// contains filtered or unexported fields
}

type Reader

type Reader interface {
	io.Reader
	ReadByte() (byte, error)
	ReadBytes(byte) ([]byte, error)
}

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(source io.Reader) *Scanner

func NewScannerWithReader

func NewScannerWithReader(source Reader) *Scanner

func (*Scanner) ConsumeBytes

func (s *Scanner) ConsumeBytes(dst []byte) error

func (*Scanner) ConsumeUntilNewLine

func (s *Scanner) ConsumeUntilNewLine() ([]byte, error)

func (*Scanner) ResetOffsetCounter

func (s *Scanner) ResetOffsetCounter()

func (*Scanner) ScanToken

func (s *Scanner) ScanToken() (Token, error)

type String

type String struct {
	Value  string
	Offset int
}

func (String) ToLower

func (c String) ToLower() String

type Token

type Token struct {
	TType  TokenType
	Value  byte
	Offset int
}

type TokenType

type TokenType int
const (
	TokenTypeEOF TokenType = iota
	TokenTypeError
	TokenTypeSP
	TokenTypeExclamation
	TokenTypeDQuote
	TokenTypeHash
	TokenTypeDollar
	TokenTypePercent
	TokenTypeAmpersand
	TokenTypeSQuote
	TokenTypeLParen
	TokenTypeRParen
	TokenTypeAsterisk
	TokenTypePlus
	TokenTypeComma
	TokenTypeMinus
	TokenTypePeriod
	TokenTypeSlash
	TokenTypeSemicolon
	TokenTypeColon
	TokenTypeLess
	TokenTypeEqual
	TokenTypeGreater
	TokenTypeQuestion
	TokenTypeAt
	TokenTypeLBracket
	TokenTypeRBracket
	TokenTypeCaret
	TokenTypeUnderscore
	TokenTyeBacktick
	TokenTypeLCurly
	TokenTypePipe
	TokenTypeRCurly
	TokenTypeTilde
	TokenTypeBackslash
	TokenTypeDigit
	TokenTypeChar
	TokenTypeExtendedChar
	TokenTypeCR
	TokenTypeLF
	TokenTypeCTL
	TokenTypeTab
	TokenTypeDelete
	TokenTypeZero
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL