text

package
v0.0.0-...-d3a9360 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringRunes           = "\"\""
	RecordRunes           = "<>"
	SequenceRunes         = "[]"
	SetRunes              = "#{}"
	DictionaryRunes       = "{}"
	AnnotationRunes       = "@"
	EmbeddedRunes         = "#:"
	QuotedSymbolRunes     = "||"
	BooleanTrueRunes      = "#t"
	BooleanFalseRunes     = "#f"
	BinByteStringRunes    = "#\"\""
	HexByteStringRunes    = "#x\"\""
	Base64ByteStringRunes = "#[]"
	HexDoubleRunes        = "#xd\"\""
	CommentRunes          = "#"
	WhiteSpaceRunes       = " \t\r\n"
	ShebangRunes          = "#!"
)

Variables

View Source
var (
	WhiteSpaceRegexp     = regexp.MustCompile("[ \t\r\n]")
	CommasRegexp         = regexp.MustCompile("([ \t\r\n]*,)*[ \t\r\n]*")
	SymbolOrNumberRegexp = regexp.MustCompile(`^[-a-zA-Z0-9~!$%^&*?_=+/.]+$`)
	NumberRegexp         = regexp.MustCompile(`^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$`)
	DoubleRegexp         = regexp.MustCompile(`^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))$`)
	SignedIntegerRegexp  = regexp.MustCompile(`^([-+]?\d+)$`)
	Base64Regexp         = regexp.MustCompile(`[a-zA-Z0-9+/_=']`)
)
MazePath{
	Maze: NewMaze(map[rune]MazePath{
		rune(QuotedSymbolRunes[0]): {ReadFrom: new(QuotedSymbol)},
		rune(StringRunes[0]):       {ReadFrom: new(String)},
		rune(RecordRunes[0]):       {ReadFrom: new(Record)},
		rune(DictionaryRunes[0]):   {ReadFrom: new(Dictionary)},
		rune(SequenceRunes[0]):     {ReadFrom: new(Sequence)},
		rune(AnnotationRunes[0]):   {ReadFrom: new(Annotation)},
		rune(CommentRunes[0]): {
			ReadFrom: new(Comment),
			Maze: NewMaze(map[rune]MazePath{
				rune(ShebangRunes[1]):          {ReadFrom: new(Shebang)},
				rune(BinByteStringRunes[1]):    {ReadFrom: new(BinByteString)},
				rune(Base64ByteStringRunes[1]): {ReadFrom: new(Base64ByteString)},
				rune(BooleanTrueRunes[1]):      {ReadFrom: new(Boolean)},
				rune(BooleanFalseRunes[1]):     {ReadFrom: new(Boolean)},
				rune(EmbeddedRunes[1]):         {ReadFrom: new(Embedded)},
				rune(SetRunes[1]):              {ReadFrom: new(Set)},
				rune(HexDoubleRunes[1]): {
					Maze: NewMaze(map[rune]MazePath{
						rune(HexByteStringRunes[2]): {ReadFrom: new(HexByteString)},
						rune(HexDoubleRunes[2]): {
							Maze: NewMaze(map[rune]MazePath{
								rune(HexDoubleRunes[3]): {ReadFrom: new(HexDouble)},
							}),
						},
					}),
				},
			}),
		},
	}),
}
View Source
var RuneMaze = (&MazePath{}).
	AddPath("", new(Bare)).
	AddPath(string(QuotedSymbolRunes[0]), new(QuotedSymbol)).
	AddPath(string(StringRunes[0]), new(String)).
	AddPath(BinByteStringRunes[0:2], new(BinByteString)).
	AddPath(Base64ByteStringRunes[0:2], new(Base64ByteString)).
	AddPath(BooleanTrueRunes, new(Boolean)).
	AddPath(BooleanFalseRunes, new(Boolean)).
	AddPath(HexDoubleRunes[0:4], new(HexDouble)).
	AddPath(HexByteStringRunes[0:3], new(HexByteString)).
	AddPath(SetRunes[0:2], new(Set)).
	AddPath(string(RecordRunes[0]), new(Record)).
	AddPath(string(DictionaryRunes[0]), new(Dictionary)).
	AddPath(string(SequenceRunes[0]), new(Sequence)).
	AddPath(AnnotationRunes, new(Annotation)).
	AddPath(CommentRunes, new(Comment)).
	AddPath(ShebangRunes, new(Shebang)).
	AddPath(EmbeddedRunes, new(Embedded))

Functions

func EndRune

func EndRune(er rune, ir io.Reader) (ok bool, n int, err error)

func FromPreserves

func FromPreserves(v preserves.Value) preserves.Value

func NewBareSymbol

func NewBareSymbol(s string) preserves.Value

func SkipCommas

func SkipCommas(ir io.Reader) (n int64, err error)

func SkipWhitespace

func SkipWhitespace(ir io.Reader) (n int64, err error)

func ToPreserves

func ToPreserves(v preserves.Value) preserves.Value

Types

type Annotation

type Annotation struct {
	preserves.Annotation
}

func (*Annotation) MarshalText

func (a *Annotation) MarshalText() (data []byte, err error)

func (*Annotation) New

func (a *Annotation) New() preserves.Value

func (*Annotation) ReadFrom

func (a *Annotation) ReadFrom(ir io.Reader) (n int64, err error)

func (*Annotation) String

func (a *Annotation) String() string

func (*Annotation) WriteTo

func (a *Annotation) WriteTo(w io.Writer) (n int64, err error)

type Bare

type Bare struct {
	*bufio.Reader
	Error error
}

func (*Bare) New

func (b *Bare) New() preserves.Value

func (*Bare) ReadFrom

func (b *Bare) ReadFrom(_ io.Reader) (n int64, err error)

type BareDouble

type BareDouble struct {
	preserves.Double
}

func (*BareDouble) Equal

func (b *BareDouble) Equal(y preserves.Value) bool

func (*BareDouble) MarshalText

func (b *BareDouble) MarshalText() (data []byte, err error)

func (*BareDouble) New

func (b *BareDouble) New() preserves.Value

func (*BareDouble) ReadFrom

func (b *BareDouble) ReadFrom(r io.Reader) (n int64, err error)

func (*BareDouble) String

func (b *BareDouble) String() string

func (*BareDouble) WriteTo

func (b *BareDouble) WriteTo(w io.Writer) (n int64, err error)

type BareSymbol

type BareSymbol struct {
	preserves.Symbol
}

func (*BareSymbol) Equal

func (bs *BareSymbol) Equal(y preserves.Value) bool

func (*BareSymbol) MarshalText

func (bs *BareSymbol) MarshalText() (data []byte, err error)

func (*BareSymbol) New

func (bs *BareSymbol) New() preserves.Value

func (*BareSymbol) ReadFrom

func (bs *BareSymbol) ReadFrom(ir io.Reader) (n int64, err error)

func (*BareSymbol) String

func (bs *BareSymbol) String() string

func (*BareSymbol) WriteTo

func (bs *BareSymbol) WriteTo(w io.Writer) (n int64, err error)

type Base64ByteString

type Base64ByteString struct {
	preserves.ByteString
}

func (*Base64ByteString) Equal

func (bs *Base64ByteString) Equal(v preserves.Value) bool

func (*Base64ByteString) MarshalText

func (bs *Base64ByteString) MarshalText() (data []byte, err error)

func (*Base64ByteString) New

func (bs *Base64ByteString) New() preserves.Value

func (*Base64ByteString) ReadFrom

func (bs *Base64ByteString) ReadFrom(r io.Reader) (n int64, err error)

func (*Base64ByteString) String

func (bs *Base64ByteString) String() string

func (*Base64ByteString) WriteTo

func (bs *Base64ByteString) WriteTo(w io.Writer) (n int64, err error)

type BinByteString

type BinByteString struct {
	preserves.ByteString
}

func (*BinByteString) Equal

func (bbs *BinByteString) Equal(v preserves.Value) bool

func (*BinByteString) MarshalText

func (bbs *BinByteString) MarshalText() (data []byte, err error)

func (*BinByteString) New

func (bbs *BinByteString) New() preserves.Value

func (*BinByteString) ReadFrom

func (bbs *BinByteString) ReadFrom(r io.Reader) (n int64, err error)

func (*BinByteString) String

func (bbs *BinByteString) String() string

func (*BinByteString) WriteTo

func (bbs *BinByteString) WriteTo(w io.Writer) (n int64, err error)

type Boolean

type Boolean struct {
	preserves.Boolean
}

func (*Boolean) Equal

func (b *Boolean) Equal(y preserves.Value) bool

func (*Boolean) MarshalText

func (b *Boolean) MarshalText() (data []byte, err error)

func (*Boolean) New

func (b *Boolean) New() preserves.Value

func (*Boolean) ReadFrom

func (b *Boolean) ReadFrom(ir io.Reader) (n int64, err error)

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) WriteTo

func (b *Boolean) WriteTo(w io.Writer) (n int64, err error)

type Comment

type Comment struct {
	preserves.Annotation
}

func (*Comment) MarshalText

func (c *Comment) MarshalText() (data []byte, err error)

func (*Comment) New

func (c *Comment) New() preserves.Value

func (*Comment) ReadFrom

func (c *Comment) ReadFrom(ir io.Reader) (n int64, err error)

func (*Comment) String

func (c *Comment) String() string

func (*Comment) WriteTo

func (c *Comment) WriteTo(w io.Writer) (n int64, err error)

type Dictionary

type Dictionary struct {
	preserves.Dictionary
}

func (*Dictionary) MarshalText

func (d *Dictionary) MarshalText() (data []byte, err error)

encoding.TextMarshaler interface

func (*Dictionary) New

func (d *Dictionary) New() preserves.Value

func (*Dictionary) ReadFrom

func (d *Dictionary) ReadFrom(ir io.Reader) (n int64, err error)

io.ReaderTo interface

func (*Dictionary) String

func (d *Dictionary) String() string

fmt.Stringer interface

func (*Dictionary) WriteTo

func (d *Dictionary) WriteTo(w io.Writer) (n int64, err error)

io.WriterTo interface

type Embedded

type Embedded struct {
	preserves.Embedded
}

func (*Embedded) MarshalText

func (e *Embedded) MarshalText() (data []byte, err error)

func (*Embedded) New

func (e *Embedded) New() preserves.Value

func (*Embedded) ReadFrom

func (e *Embedded) ReadFrom(ir io.Reader) (n int64, err error)

func (*Embedded) String

func (e *Embedded) String() string

func (*Embedded) WriteTo

func (e *Embedded) WriteTo(w io.Writer) (n int64, err error)

type HexByteString

type HexByteString struct {
	preserves.ByteString
}

func (*HexByteString) Equal

func (hbs *HexByteString) Equal(v preserves.Value) bool

func (*HexByteString) MarshalText

func (hbs *HexByteString) MarshalText() (data []byte, err error)

func (*HexByteString) New

func (hbs *HexByteString) New() preserves.Value

func (*HexByteString) ReadFrom

func (hbs *HexByteString) ReadFrom(r io.Reader) (n int64, err error)

func (*HexByteString) String

func (hbs *HexByteString) String() string

func (*HexByteString) WriteTo

func (hbs *HexByteString) WriteTo(w io.Writer) (n int64, err error)

type HexDouble

type HexDouble struct {
	preserves.Double
}

func (*HexDouble) Equal

func (h *HexDouble) Equal(y preserves.Value) bool

func (*HexDouble) MarshalText

func (h *HexDouble) MarshalText() (data []byte, err error)

func (*HexDouble) New

func (h *HexDouble) New() preserves.Value

func (*HexDouble) ReadFrom

func (h *HexDouble) ReadFrom(r io.Reader) (n int64, err error)

func (*HexDouble) String

func (h *HexDouble) String() string

func (*HexDouble) WriteTo

func (h *HexDouble) WriteTo(w io.Writer) (n int64, err error)

type Maze

type Maze map[rune]*MazePath

func NewMaze

func NewMaze(m map[rune]*MazePath) *Maze

func (*Maze) Get

func (rm *Maze) Get(r rune) (mp *MazePath, ok bool)

type MazePath

type MazePath struct {
	ReadFrom io.ReaderFrom
	Maze     *Maze
}

func (*MazePath) AddPath

func (mp *MazePath) AddPath(path string, rf io.ReaderFrom) *MazePath

type QuotedSymbol

type QuotedSymbol struct {
	preserves.Pstring
}

func (*QuotedSymbol) Equal

func (bs *QuotedSymbol) Equal(y preserves.Value) bool

func (*QuotedSymbol) MarshalText

func (qs *QuotedSymbol) MarshalText() (data []byte, err error)

func (*QuotedSymbol) New

func (qs *QuotedSymbol) New() preserves.Value

func (*QuotedSymbol) ReadFrom

func (qs *QuotedSymbol) ReadFrom(ir io.Reader) (n int64, err error)

func (*QuotedSymbol) String

func (qs *QuotedSymbol) String() string

func (*QuotedSymbol) WriteTo

func (qs *QuotedSymbol) WriteTo(w io.Writer) (n int64, err error)

type Record

type Record struct {
	preserves.Record
}

func (Record) MarshalText

func (re Record) MarshalText() (data []byte, err error)

encoding.TextMarshaler interface

func (*Record) New

func (re *Record) New() preserves.Value

func (*Record) ReadFrom

func (re *Record) ReadFrom(ir io.Reader) (n int64, err error)

func (Record) String

func (re Record) String() string

fmt.Stringer interface

func (*Record) WriteTo

func (re *Record) WriteTo(w io.Writer) (n int64, err error)

type Sequence

type Sequence struct {
	preserves.Sequence
}

func (*Sequence) MarshalText

func (s *Sequence) MarshalText() (data []byte, err error)

func (*Sequence) New

func (s *Sequence) New() preserves.Value

func (*Sequence) ReadFrom

func (s *Sequence) ReadFrom(ir io.Reader) (n int64, err error)

func (*Sequence) String

func (s *Sequence) String() string

func (*Sequence) WriteTo

func (s *Sequence) WriteTo(w io.Writer) (n int64, err error)

type Set

type Set struct {
	preserves.Set
}

func (*Set) MarshalText

func (s *Set) MarshalText() (data []byte, err error)

func (*Set) New

func (s *Set) New() preserves.Value

func (*Set) ReadFrom

func (s *Set) ReadFrom(ir io.Reader) (n int64, err error)

func (*Set) String

func (s *Set) String() string

func (*Set) WriteTo

func (s *Set) WriteTo(w io.Writer) (n int64, err error)

type Shebang

type Shebang struct {
	preserves.Annotation
}

func (*Shebang) MarshalText

func (s *Shebang) MarshalText() (data []byte, err error)

func (*Shebang) New

func (s *Shebang) New() preserves.Value

func (*Shebang) ReadFrom

func (s *Shebang) ReadFrom(ir io.Reader) (n int64, err error)

func (*Shebang) String

func (s *Shebang) String() string

func (*Shebang) WriteTo

func (s *Shebang) WriteTo(w io.Writer) (n int64, err error)

type SignedInteger

type SignedInteger struct {
	preserves.SignedInteger
}

func NewSignedInteger

func NewSignedInteger(i int64) *SignedInteger

func (*SignedInteger) Equal

func (s *SignedInteger) Equal(y preserves.Value) bool

func (*SignedInteger) MarshalText

func (s *SignedInteger) MarshalText() (data []byte, err error)

func (*SignedInteger) New

func (s *SignedInteger) New() preserves.Value

func (*SignedInteger) ReadFrom

func (s *SignedInteger) ReadFrom(r io.Reader) (n int64, err error)

func (*SignedInteger) String

func (s *SignedInteger) String() string

func (*SignedInteger) WriteTo

func (s *SignedInteger) WriteTo(w io.Writer) (n int64, err error)

type String

type String struct {
	preserves.Pstring
}

func (*String) Equal

func (s *String) Equal(y preserves.Value) bool

func (*String) MarshalText

func (s *String) MarshalText() (data []byte, err error)

func (*String) New

func (s *String) New() preserves.Value

func (*String) ReadFrom

func (s *String) ReadFrom(r io.Reader) (n int64, err error)

func (*String) String

func (s *String) String() string

func (*String) WriteTo

func (s *String) WriteTo(w io.Writer) (n int64, err error)

type TextParser

type TextParser struct {
	Result     preserves.Value
	SkipCommas bool
	RuneMaze   *MazePath
}

func (*TextParser) GetValue

func (tp *TextParser) GetValue() preserves.Value

func (*TextParser) ReadFrom

func (tp *TextParser) ReadFrom(ir io.Reader) (n int64, err error)

Jump to

Keyboard shortcuts

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