parser

package
v0.0.0-...-8de7dcd Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HadErrors = fmt.Errorf("had errors, see Walker.Errors")

Functions

func Fmt

func Fmt(input string) (string, error)

func IsIdentifier

func IsIdentifier(name string) bool

IsIdentifier reports whether name is a Go identifier, that is, a non-empty string made up of letters, digits, and underscores, where the first character is not a digit. Keywords are not identifiers.

func IsKeyword

func IsKeyword(name string) bool

IsKeyword reports whether name is a Go keyword, such as "func" or "return".

Types

type ASTValue

type ASTValue interface {
	AsBool() (bool, error)
	AsString() (string, error)
	AsInt(bits int) (int64, error)
	AsUint(bits int) (uint64, error)
	AsFloat(bits int) (float64, error)

	Position() errpos.Position

	IsArray() bool
	IsScalar() bool
	AsArray() ([]ASTValue, bool)
}

func NewBoolValue

func NewBoolValue(val bool, pos Position) ASTValue

func NewIntValue

func NewIntValue(val int64, pos Position) ASTValue

func NewStringValue

func NewStringValue(val string, src SourceNode) ASTValue

type Assignment

type Assignment struct {
	Key   Reference
	Value Value
	SourceNode
	Append bool // If += was used, otherwise =
}

func (Assignment) GoString

func (a Assignment) GoString() string

func (Assignment) Kind

func (a Assignment) Kind() FragmentKind

func (*Assignment) StatementType

func (a *Assignment) StatementType() StatementType

type Block

type Block struct {
	BlockHeader
	Body Body
}

func (*Block) StatementType

func (b *Block) StatementType() StatementType

type BlockHeader

type BlockHeader struct {
	Type        Reference // all of the name tags, including the first 'type' tag
	Tags        []TagValue
	Qualifiers  []TagValue   // Any of the `:qualifier` tags at the end
	Description *Description // A single | description block
	Open        bool         // 'block' is opened with a {

	SourceNode
}

func (BlockHeader) DescriptionString

func (bh BlockHeader) DescriptionString() string

func (BlockHeader) GoString

func (bs BlockHeader) GoString() string

func (BlockHeader) Kind

func (bh BlockHeader) Kind() FragmentKind

func (BlockHeader) RootName

func (bs BlockHeader) RootName() string

type Body

type Body struct {
	IsRoot     bool
	Statements []Statement
}

type BoolValue

type BoolValue struct {
	SourceNode
	// contains filtered or unexported fields
}

func (BoolValue) AsArray

func (uv BoolValue) AsArray() ([]ASTValue, bool)

func (BoolValue) AsBool

func (iv BoolValue) AsBool() (bool, error)

func (BoolValue) AsFloat

func (uv BoolValue) AsFloat(size int) (float64, error)

func (BoolValue) AsInt

func (uv BoolValue) AsInt(size int) (int64, error)

func (BoolValue) AsString

func (uv BoolValue) AsString() (string, error)

func (BoolValue) AsUint

func (uv BoolValue) AsUint(size int) (uint64, error)

func (BoolValue) IsArray

func (uv BoolValue) IsArray() bool

func (BoolValue) IsScalar

func (iv BoolValue) IsScalar() bool

type CloseBlock

type CloseBlock struct {
	SourceNode
	Token Token
}

func (CloseBlock) GoString

func (cb CloseBlock) GoString() string

func (CloseBlock) Kind

func (cb CloseBlock) Kind() FragmentKind

type Comment

type Comment struct {
	Value string
	SourceNode
	Token Token
}

func (Comment) GoString

func (c Comment) GoString() string

func (Comment) Kind

func (c Comment) Kind() FragmentKind

func (*Comment) StatementType

func (c *Comment) StatementType() StatementType

type Declaration

type Declaration struct {
	BlockHeader
}

func (*Declaration) StatementType

func (d *Declaration) StatementType() StatementType

type Description

type Description struct {
	Value string
	SourceNode
	Tokens []Token
}

func (Description) GoString

func (d Description) GoString() string

func (Description) Kind

func (d Description) Kind() FragmentKind

func (*Description) StatementType

func (d *Description) StatementType() StatementType

type Error

type Error struct {
	Err error
	Pos errpos.Position
}

type File

type File struct {
	Body Body

	Errors errpos.Errors
}

func ParseFile

func ParseFile(input string, failFast bool) (*File, error)

func Walk

func Walk(tokens []Token, failFast bool) (*File, error)

type FmtDiff

type FmtDiff struct {
	FromLine int // 0 based
	ToLine   int // 0 based, Exclusive
	NewText  string
}

func FmtDiffs

func FmtDiffs(input string) ([]FmtDiff, error)

type Fragment

type Fragment interface {
	fmt.GoStringer
	Source() SourceNode
	Kind() FragmentKind
}

type FragmentKind

type FragmentKind int
const (
	AssignmentFragment FragmentKind = iota
	BlockHeaderFragment
	BlockCloseFragment
	DescriptionFragment
)

type Ident

type Ident struct {
	Token Token
	Value string
	SourceNode
}

Ident is a simple name used when declaring a type, or as parts of a reference.

func (Ident) AsStringValue

func (i Ident) AsStringValue() Value

func (Ident) GoString

func (i Ident) GoString() string

func (Ident) String

func (i Ident) String() string

type IntValue

type IntValue struct {
	SourceNode
	// contains filtered or unexported fields
}

func (IntValue) AsArray

func (uv IntValue) AsArray() ([]ASTValue, bool)

func (IntValue) AsBool

func (uv IntValue) AsBool() (bool, error)

func (IntValue) AsFloat

func (uv IntValue) AsFloat(size int) (float64, error)

func (IntValue) AsInt

func (iv IntValue) AsInt(size int) (int64, error)

func (IntValue) AsString

func (uv IntValue) AsString() (string, error)

func (IntValue) AsUint

func (uv IntValue) AsUint(size int) (uint64, error)

func (IntValue) IsArray

func (uv IntValue) IsArray() bool

func (IntValue) IsScalar

func (iv IntValue) IsScalar() bool

type Lexer

type Lexer struct {
	Errors errpos.Errors
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(data string) *Lexer

func (*Lexer) AllTokens

func (l *Lexer) AllTokens(failFast bool) ([]Token, bool, error)

func (*Lexer) NextToken

func (l *Lexer) NextToken() (Token, error)

NextToken scans the input for the next token. It returns the position of the token, the token's type, and the literal value.

type Position

type Position = errpos.Point

type Reference

type Reference struct {
	Idents []Ident
	SourceNode
	// contains filtered or unexported fields
}

Reference is a dot separates set of Idents

func NewReference

func NewReference(idents []Ident) Reference

func (Reference) AsArray

func (uv Reference) AsArray() ([]ASTValue, bool)

func (Reference) AsBool

func (uv Reference) AsBool() (bool, error)

func (Reference) AsFloat

func (uv Reference) AsFloat(size int) (float64, error)

func (Reference) AsInt

func (uv Reference) AsInt(size int) (int64, error)

func (Reference) AsString

func (r Reference) AsString() (string, error)

func (Reference) AsUint

func (uv Reference) AsUint(size int) (uint64, error)

func (Reference) GoString

func (r Reference) GoString() string

func (Reference) IsArray

func (uv Reference) IsArray() bool

func (Reference) IsScalar

func (uv Reference) IsScalar() bool

func (Reference) String

func (r Reference) String() string

func (Reference) Strings

func (r Reference) Strings() []string

type SourceNode

type SourceNode struct {
	Start   Position
	End     Position
	Comment *Comment
}

func (SourceNode) Position

func (sn SourceNode) Position() errpos.Position

func (SourceNode) Source

func (sn SourceNode) Source() SourceNode

type Statement

type Statement interface {
	StatementType() StatementType
	Source() SourceNode
}

type StatementType

type StatementType string
const (
	// Compound Statements, consist of multiple fragments
	BlockStatement       StatementType = "block"
	DeclarationStatement StatementType = "declaration"

	// Fragments which are also Statements
	AssignmentStatement  StatementType = "assignment"
	CommentStatement     StatementType = "comment"
	DescriptionStatement StatementType = "description"
)

type StringValue

type StringValue struct {
	SourceNode
	// contains filtered or unexported fields
}

func (StringValue) AsArray

func (uv StringValue) AsArray() ([]ASTValue, bool)

func (StringValue) AsBool

func (uv StringValue) AsBool() (bool, error)

func (StringValue) AsFloat

func (uv StringValue) AsFloat(size int) (float64, error)

func (StringValue) AsInt

func (uv StringValue) AsInt(size int) (int64, error)

func (StringValue) AsString

func (sv StringValue) AsString() (string, error)

func (StringValue) AsUint

func (uv StringValue) AsUint(size int) (uint64, error)

func (StringValue) IsArray

func (uv StringValue) IsArray() bool

func (StringValue) IsScalar

func (sv StringValue) IsScalar() bool

type TagMark

type TagMark int
const (
	TagMarkNone TagMark = iota
	TagMarkBang
	TagMarkQuestion
)

type TagValue

type TagValue struct {
	Mark      TagMark
	MarkToken Token
	Reference *Reference
	Value     *Value

	SourceNode
	// contains filtered or unexported fields
}

func (TagValue) AsArray

func (uv TagValue) AsArray() ([]ASTValue, bool)

func (TagValue) AsBool

func (uv TagValue) AsBool() (bool, error)

func (TagValue) AsFloat

func (uv TagValue) AsFloat(size int) (float64, error)

func (TagValue) AsInt

func (uv TagValue) AsInt(size int) (int64, error)

func (TagValue) AsString

func (tv TagValue) AsString() (string, error)

func (TagValue) AsUint

func (uv TagValue) AsUint(size int) (uint64, error)

func (TagValue) GoString

func (tv TagValue) GoString() string

func (TagValue) IsArray

func (uv TagValue) IsArray() bool

func (TagValue) IsScalar

func (tv TagValue) IsScalar() bool

type Token

type Token struct {
	Type       TokenType
	Lit        string
	Start, End Position
}

func (Token) AsIdent

func (tok Token) AsIdent() (Token, bool)

func (Token) Clone

func (tok Token) Clone() Token

func (Token) String

func (tok Token) String() string

type TokenType

type TokenType int
const (
	INVALID TokenType = iota
	EOF
	EOL
	SPACE

	IDENT
	STRING        // "abc"
	REGEX         // /abc/
	INT           // 123
	DECIMAL       // 123.45
	BOOL          // true or false
	COMMENT       // // ...
	BLOCK_COMMENT // /* ... */
	DESCRIPTION   // | ...

	ASSIGN   // =
	LBRACE   // {
	RBRACE   // }
	LBRACK   // [
	RBRACK   // ]
	DOT      // .
	COMMA    // ,
	COLON    // :
	PLUS     // +
	BANG     // !
	QUESTION // ?

	AnyLiteral
)

func (TokenType) CanStartTag

func (tok TokenType) CanStartTag() bool

func (TokenType) IsKeyword

func (tok TokenType) IsKeyword() bool

IsKeyword returns true for tokens corresponding to keywords; it returns false otherwise.

func (TokenType) IsLiteral

func (tok TokenType) IsLiteral() bool

IsLiteral returns true for tokens corresponding to identifiers, basic type literals; it returns false otherwise.

func (TokenType) IsOperator

func (tok TokenType) IsOperator() bool

IsOperator returns true for tokens corresponding to operators; it returns false otherwise.

func (TokenType) String

func (tok TokenType) String() string

type TypeError

type TypeError struct {
	Expected string
	Got      string
}

func (*TypeError) Error

func (te *TypeError) Error() string

type Value

type Value struct {
	SourceNode
	// contains filtered or unexported fields
}

func (Value) AsArray

func (v Value) AsArray() ([]ASTValue, bool)

func (Value) AsBool

func (v Value) AsBool() (bool, error)

func (Value) AsFloat

func (v Value) AsFloat(size int) (float64, error)

func (Value) AsInt

func (v Value) AsInt(size int) (int64, error)

func (Value) AsString

func (v Value) AsString() (string, error)

func (Value) AsUint

func (v Value) AsUint(size int) (uint64, error)

func (Value) GoString

func (v Value) GoString() string

func (Value) IsArray

func (v Value) IsArray() bool

func (Value) IsScalar

func (v Value) IsScalar() bool

func (Value) Position

func (v Value) Position() errpos.Position

type Walker

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

Jump to

Keyboard shortcuts

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