sdlang

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 7 Imported by: 0

README

Overview

This library is used to parse and (eventually) emit SDLang files.

todo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SaxParser

type SaxParser struct {
	// Input is the input to parse.
	Input string

	// FileName is used for debug messages.
	FileName string
	// contains filtered or unexported fields
}

SaxParser provides a SAX-style of parsing. This is more efficient than constructing an AST, but involves more effort on the user's side.

func (*SaxParser) AdditionalText

func (s *SaxParser) AdditionalText() string

Additional text is some additional text to compliment the main text. For tag/attribute names, this is the namespace value.

func (*SaxParser) Bool

func (s *SaxParser) Bool() bool

Bool is the value for the Bool literal.

func (*SaxParser) IsAttributeName

func (s *SaxParser) IsAttributeName() bool

func (*SaxParser) IsBinary

func (s *SaxParser) IsBinary() bool

func (*SaxParser) IsBool

func (s *SaxParser) IsBool() bool

func (*SaxParser) IsChar

func (s *SaxParser) IsChar() bool

func (*SaxParser) IsCloseTag

func (s *SaxParser) IsCloseTag() bool

func (*SaxParser) IsDate

func (s *SaxParser) IsDate() bool

func (*SaxParser) IsDateTime

func (s *SaxParser) IsDateTime() bool

func (*SaxParser) IsDecimal

func (s *SaxParser) IsDecimal() bool

func (*SaxParser) IsDouble

func (s *SaxParser) IsDouble() bool

func (*SaxParser) IsEof

func (s *SaxParser) IsEof() bool

func (*SaxParser) IsFloat

func (s *SaxParser) IsFloat() bool

func (*SaxParser) IsInteger

func (s *SaxParser) IsInteger() bool

func (*SaxParser) IsLong

func (s *SaxParser) IsLong() bool

func (*SaxParser) IsNewLine

func (s *SaxParser) IsNewLine() bool

func (*SaxParser) IsNull

func (s *SaxParser) IsNull() bool

func (*SaxParser) IsOpenTag

func (s *SaxParser) IsOpenTag() bool

func (*SaxParser) IsString

func (s *SaxParser) IsString() bool

func (*SaxParser) IsTagName

func (s *SaxParser) IsTagName() bool

func (*SaxParser) IsTimeSpan

func (s *SaxParser) IsTimeSpan() bool

func (*SaxParser) NewError

func (s *SaxParser) NewError(offset int, msg string) error

Generates a fancy error message.

func (*SaxParser) Next

func (s *SaxParser) Next() error

Next parses the next token. You can query which token was parsed via the `IsBool`, `IsString`, `Is..` etc. functions. You can use the likes of `Text`, `DateTime`, and so on to retrieve the parsed values. You should keep calling this function until either an error is returned, or `IsEof` returns true. Error messages are already formatted for a user-friendly experience.

func (SaxParser) ParseIntoAst

func (p SaxParser) ParseIntoAst() (SdlTag, error)

Using the given SaxParser, an AST is constructed. The returned value contains the root tag, which is nameless and only contains children.

func (*SaxParser) Text

func (s *SaxParser) Text() string

Text is the parsed text. For tag/attribute names, this is the non-namespace value.

func (*SaxParser) Time

func (s *SaxParser) Time() time.Time

Time is the value for DateTime and Date literals.

func (*SaxParser) TimeSpan

func (s *SaxParser) TimeSpan() time.Duration

TimeSpan is the value for the TimeSpan literal.

type SdlAttribute

type SdlAttribute struct {
	// Namespace is the namespace of this attribute.
	Namespace string

	// Name is the name of this attribute.
	Name string

	// QualifiedName is the fully qualified ("namespace:name") name of this attribute.
	QualifiedName string

	// Value is the value.
	Value         SdlValue
	DebugLocation SdlDebugLocation
}

SdlAttribute is a Key-Value pair between a string and an SdlValue

type SdlDebugLocation added in v0.1.2

type SdlDebugLocation struct {
	File       string
	Line       string
	Loc        int
	LineNumber int
}

type SdlTag

type SdlTag struct {
	// Namespace is the namespace of this tag.
	Namespace string

	// Name is the name of this tag.
	Name string

	// QualifiedName is the fully qualified ("namespace:name") name of this tag.
	QualifiedName string

	// Children contains the children of this tag. It is safe (and expected) to modify this value.
	Children []SdlTag

	// Children contains the attribtues of this tag. It is safe (and expected) to modify this value.
	Attributes map[string]SdlAttribute

	// Children contains the values of this tag. It is safe (and expected) to modify this value.
	Values        []SdlValue
	DebugLocation SdlDebugLocation
}

SdlTag is a container consisting of a name; child tags; attributes, and values.

func (SdlTag) ForEachChild

func (t SdlTag) ForEachChild(f func(child *SdlTag))

ForEachChild applies the function `f` onto each child of the tag.

func (SdlTag) ForEachChildByName

func (t SdlTag) ForEachChildByName(name string, f func(child *SdlTag))

ForEachChildByName applies the function `f` onto each child of the tag that has the specified `name`.

func (SdlTag) ForEachChildByNamespace

func (t SdlTag) ForEachChildByNamespace(namespace string, f func(child *SdlTag))

ForEachChildByName applies the function `f` onto each child of the tag that has the specified `namespace`.

func (SdlTag) ForEachChildFiltered

func (t SdlTag) ForEachChildFiltered(filter func(child *SdlTag) bool, f func(child *SdlTag))

ForEachChildFiltered applies the function `f` onto each child of the tag that passes the `filter` predicate.

type SdlValue

type SdlValue struct {
	DebugLocation SdlDebugLocation
	// contains filtered or unexported fields
}

SdlValue is a tagged union for every possible type representable in SDLang.

func Binary

func Binary(value []byte) SdlValue

Binary creates a binary SdlValue

func Bool

func Bool(value bool) SdlValue

Bool creates a bool SdlValue

func DateTime

func DateTime(value time.Time) SdlValue

DateTime creates a datetime SdlValue

func Float

func Float(value float64) SdlValue

Float creates a float SdlValue

func Int

func Int(value int64) SdlValue

Int creates an int SdlValue

func Null

func Null() SdlValue

Null creates a null SdlValue

func String

func String(value string) SdlValue

String creates a string SdlValue

func TimeSpan

func TimeSpan(value time.Duration) SdlValue

TimeSpan creates a timespan SdlValue

func (SdlValue) Binary

func (v SdlValue) Binary() ([]byte, error)

func (SdlValue) Bool

func (v SdlValue) Bool() (bool, error)

func (SdlValue) DateTime

func (v SdlValue) DateTime() (time.Time, error)

func (SdlValue) Float

func (v SdlValue) Float() (float64, error)

func (SdlValue) Int

func (v SdlValue) Int() (int64, error)

func (SdlValue) IsBinary

func (v SdlValue) IsBinary() bool

func (SdlValue) IsBool

func (v SdlValue) IsBool() bool

func (SdlValue) IsDateTime

func (v SdlValue) IsDateTime() bool

func (SdlValue) IsFloat

func (v SdlValue) IsFloat() bool

func (SdlValue) IsInt

func (v SdlValue) IsInt() bool

func (SdlValue) IsNull

func (v SdlValue) IsNull() bool

func (SdlValue) IsString

func (v SdlValue) IsString() bool

func (SdlValue) IsTimeSpan

func (v SdlValue) IsTimeSpan() bool

func (SdlValue) String

func (v SdlValue) String() (string, error)

func (SdlValue) TimeSpan

func (v SdlValue) TimeSpan() (time.Duration, error)

Jump to

Keyboard shortcuts

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