Documentation
¶
Index ¶
- func NewEofResult(expected []lex.TokenType) core.Result
- func NewUnexpectedTokenResult(expected []lex.TokenType, actual lex.Token) core.Result
- func ParseMany[Node any](p Parser[Node], v *TokenView) (nodes []Node)
- func ParseManyIgnoreSeparators[Node any](p Parser[Node], v *TokenView) (nodes []Node, err core.Result)
- func SortNodesBySourceOrder(nodes []Node)
- type ArgumentNode
- type ArgumentParser
- type BlockNode
- type BlockParser
- type ConstDeclarationNode
- type ConstDeclarationParser
- type ConstNode
- type ConstParser
- type FileNode
- type FileParser
- type FunctionNode
- type FunctionParser
- type FunctionSignatureNode
- type FunctionSignatureParser
- type GlobalDeclarationNode
- type GlobalDeclarationParser
- type GlobalNode
- type GlobalParser
- type ImmediateBlockNode
- type ImmediateBlockParser
- type ImmediateFieldNode
- type ImmediateFieldParser
- type ImmediateFinalValueNode
- type ImmediateFinalValueParser
- type ImmediateNode
- type ImmediateParser
- type ImmediateValueNode
- type ImmediateValueParser
- type InstructionNode
- type InstructionParser
- type LabelNode
- type LabelParser
- type Node
- type ParameterNode
- type ParameterParser
- type Parser
- func NewArgumentParser() Parser[ArgumentNode]
- func NewConstDeclarationParser() Parser[ConstDeclarationNode]
- func NewConstParser() Parser[ConstNode]
- func NewGlobalParser() Parser[GlobalNode]
- func NewLabelParser() Parser[LabelNode]
- func NewRegisterParser() Parser[RegisterNode]
- func NewTargetParser() Parser[TargetNode]
- func NewTypeFieldParser() Parser[TypeFieldNode]
- func NewVarDeclarationParser() Parser[VarDeclarationNode]
- func NewVarParser() Parser[VarNode]
- type RegisterNode
- type RegisterParser
- type StringContext
- type TargetNode
- type TargetParser
- type TokenNode
- type TokenParser
- type TokenView
- func (v *TokenView) ConsumeAtLeastTokens(atLeast int, expectedTypes ...lex.TokenType) (err core.Result)
- func (v *TokenView) ConsumeManyTokens(expectedTypes ...lex.TokenType) (count int, err core.Result)
- func (v *TokenView) ConsumeToken(expectedTypes ...lex.TokenType) (tkn lex.Token, result core.Result)
- func (v *TokenView) ConsumeTokenIgnoreSeparator(expectedTypes ...lex.TokenType) (lex.Token, core.Result)
- func (v *TokenView) PeekToken(expectedTypes ...lex.TokenType) (tkn lex.Token, result core.Result)
- type TypeDeclarationNode
- type TypeDeclarationParser
- type TypeDecoratorNode
- type TypeDecoratorParser
- type TypeDecoratorType
- type TypeFieldNode
- type TypeFieldParser
- type TypeNode
- type TypeParser
- type VarDeclarationNode
- type VarDeclarationParser
- type VarNode
- type VarParser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortNodesBySourceOrder ¶
func SortNodesBySourceOrder(nodes []Node)
This function sorts the nodes according to their source order.
Types ¶
type ArgumentNode ¶
type ArgumentNode Node
type ArgumentParser ¶
type ArgumentParser struct { RegisterParser Parser[RegisterNode] ImmediateParser *ImmediateParser LabelParser Parser[LabelNode] GlobalParser Parser[GlobalNode] }
func (ArgumentParser) Parse ¶
func (p ArgumentParser) Parse(v *TokenView) (node ArgumentNode, err core.Result)
type BlockNode ¶
type BlockNode[NodeT Node] struct { core.UnmanagedSourceView Nodes []NodeT }
func (BlockNode[NodeT]) String ¶
func (n BlockNode[NodeT]) String(ctx *StringContext) (s string)
func (BlockNode[NodeT]) View ¶
func (n BlockNode[NodeT]) View() core.UnmanagedSourceView
type BlockParser ¶
type ConstDeclarationNode ¶
type ConstDeclarationNode struct {
Declaration GlobalDeclarationNode
}
func (ConstDeclarationNode) String ¶
func (n ConstDeclarationNode) String(ctx *StringContext) string
func (ConstDeclarationNode) View ¶
func (n ConstDeclarationNode) View() core.UnmanagedSourceView
type ConstDeclarationParser ¶
type ConstDeclarationParser struct { ConstParser Parser[ConstNode] GlobalDeclarationParser GlobalDeclarationParser }
func (ConstDeclarationParser) Parse ¶
func (p ConstDeclarationParser) Parse(v *TokenView) ( node ConstDeclarationNode, err core.Result, )
type ConstParser ¶
type ConstParser struct{ TokenParser[ConstNode] }
type FileNode ¶
type FileNode struct { Functions []FunctionNode Types []TypeDeclarationNode Constants []ConstDeclarationNode Variables []VarDeclarationNode }
func (FileNode) String ¶
func (n FileNode) String(ctx *StringContext) (s string)
func (FileNode) View ¶
func (n FileNode) View() core.UnmanagedSourceView
type FileParser ¶
type FileParser struct { FunctionParser FunctionParser TypeDeclarationParser TypeDeclarationParser ConstDeclarationParser Parser[ConstDeclarationNode] VarDeclarationParser Parser[VarDeclarationNode] }
func NewFileParser ¶
func NewFileParser() FileParser
type FunctionNode ¶
type FunctionNode struct { core.UnmanagedSourceView Signature FunctionSignatureNode Instructions *BlockNode[InstructionNode] }
func (FunctionNode) String ¶
func (n FunctionNode) String(ctx *StringContext) string
func (FunctionNode) View ¶
func (n FunctionNode) View() core.UnmanagedSourceView
type FunctionParser ¶
type FunctionParser struct { FunctionSignatureParser FunctionSignatureParser InstructionBlockParser BlockParser[InstructionNode] }
func NewFunctionParser ¶
func NewFunctionParser() FunctionParser
func (FunctionParser) Parse ¶
func (p FunctionParser) Parse(v *TokenView) (node FunctionNode, err core.Result)
type FunctionSignatureNode ¶
type FunctionSignatureNode struct { core.UnmanagedSourceView Identifier core.UnmanagedSourceView Parameters []ParameterNode Returns []TypeNode }
func (FunctionSignatureNode) String ¶
func (n FunctionSignatureNode) String(ctx *StringContext) (s string)
func (FunctionSignatureNode) View ¶
func (n FunctionSignatureNode) View() core.UnmanagedSourceView
type FunctionSignatureParser ¶
type FunctionSignatureParser struct { ParameterParser ParameterParser TypeParser TypeParser }
func NewFunctionSignatureParser ¶
func NewFunctionSignatureParser() FunctionSignatureParser
func (FunctionSignatureParser) Parse ¶
func (p FunctionSignatureParser) Parse(v *TokenView) (node FunctionSignatureNode, err core.Result)
type GlobalDeclarationNode ¶
type GlobalDeclarationNode struct { Identifier GlobalNode Type TypeNode Immediate *ImmediateValueNode }
func (GlobalDeclarationNode) String ¶
func (n GlobalDeclarationNode) String(ctx *StringContext) string
func (GlobalDeclarationNode) View ¶
func (n GlobalDeclarationNode) View() core.UnmanagedSourceView
type GlobalDeclarationParser ¶
type GlobalDeclarationParser struct { GlobalParser Parser[GlobalNode] TypeParser TypeParser ImmediateValueParser *ImmediateValueParser }
func NewGlobalDeclarationParser ¶
func NewGlobalDeclarationParser() GlobalDeclarationParser
func (*GlobalDeclarationParser) Parse ¶
func (p *GlobalDeclarationParser) Parse(v *TokenView) ( node GlobalDeclarationNode, err core.Result, )
type GlobalNode ¶
type GlobalNode struct{ TokenNode }
func GlobalNodeCreator ¶
func GlobalNodeCreator(tkn lex.Token) GlobalNode
type GlobalParser ¶
type GlobalParser struct{ TokenParser[GlobalNode] }
type ImmediateBlockNode ¶
type ImmediateBlockNode = BlockNode[ImmediateFieldNode]
type ImmediateBlockParser ¶
type ImmediateBlockParser = BlockParser[ImmediateFieldNode]
func NewImmediateBlockParser ¶
func NewImmediateBlockParser(valueParser *ImmediateValueParser) *ImmediateBlockParser
type ImmediateFieldNode ¶
type ImmediateFieldNode struct { // At most one (possible, zero) field labels can be specified for each filed // Field is nil if a label is not specified. Label *LabelNode Value ImmediateValueNode }
ImmediateFieldNode represents a single field (entry) in the initialization of an immediate custom type (struct).
func (ImmediateFieldNode) String ¶
func (n ImmediateFieldNode) String(ctx *StringContext) string
func (ImmediateFieldNode) View ¶
func (n ImmediateFieldNode) View() core.UnmanagedSourceView
type ImmediateFieldParser ¶
type ImmediateFieldParser struct { LabelParser Parser[LabelNode] ImmediateValueParser *ImmediateValueParser }
func NewImmediateFieldParser ¶
func NewImmediateFieldParser(valueParser *ImmediateValueParser) *ImmediateFieldParser
func (ImmediateFieldParser) Parse ¶
func (p ImmediateFieldParser) Parse(v *TokenView) (node ImmediateFieldNode, err core.Result)
type ImmediateFinalValueNode ¶
type ImmediateFinalValueNode struct {
core.UnmanagedSourceView
}
func (ImmediateFinalValueNode) String ¶
func (n ImmediateFinalValueNode) String(ctx *StringContext) string
func (ImmediateFinalValueNode) View ¶
func (n ImmediateFinalValueNode) View() core.UnmanagedSourceView
type ImmediateFinalValueParser ¶
type ImmediateFinalValueParser struct{}
func (ImmediateFinalValueParser) Parse ¶
func (ImmediateFinalValueParser) Parse(v *TokenView) ( node ImmediateFinalValueNode, err core.Result, )
type ImmediateNode ¶
type ImmediateNode struct { Type TypeNode Value ImmediateValueNode }
func (ImmediateNode) String ¶
func (n ImmediateNode) String(ctx *StringContext) string
func (ImmediateNode) View ¶
func (n ImmediateNode) View() core.UnmanagedSourceView
type ImmediateParser ¶
type ImmediateParser struct { TypeParser ImmediateValueParser *ImmediateValueParser }
func NewImmediateParser ¶
func NewImmediateParser() *ImmediateParser
func (ImmediateParser) Parse ¶
func (p ImmediateParser) Parse(v *TokenView) (node ImmediateNode, err core.Result)
type ImmediateValueNode ¶
type ImmediateValueNode interface { Node }
This is an interface of the type that appear as a value in a field of a custom type initialization. It can be either (1.) an ImmediateFinalValueNode (#1234), or (2.) an ImmediateBlockNode ({ ... }).
type ImmediateValueParser ¶
type ImmediateValueParser struct { ImmediateFinalValueParser *ImmediateFinalValueParser ImmediateBlockParser *ImmediateBlockParser }
func NewImmediateValueParser ¶
func NewImmediateValueParser() *ImmediateValueParser
func (ImmediateValueParser) Parse ¶
func (p ImmediateValueParser) Parse(v *TokenView) ( node ImmediateValueNode, err core.Result, )
type InstructionNode ¶
type InstructionNode struct { Operator core.UnmanagedSourceView Arguments []ArgumentNode Targets []TargetNode Labels []LabelNode }
func (InstructionNode) String ¶
func (n InstructionNode) String(ctx *StringContext) string
func (InstructionNode) View ¶
func (n InstructionNode) View() (v core.UnmanagedSourceView)
type InstructionParser ¶
type InstructionParser struct { LabelParser Parser[LabelNode] TargetParser Parser[TargetNode] ArgumentParser Parser[ArgumentNode] }
func NewInstructionParser ¶
func NewInstructionParser() InstructionParser
func (InstructionParser) Parse ¶
func (p InstructionParser) Parse(v *TokenView) (node InstructionNode, err core.Result)
Parsing of the following regular expression:
> Lbl* ((Type? Reg)+ Eql)? Opr? Arg+ !Arg \n+
type LabelParser ¶
type LabelParser struct{ TokenParser[LabelNode] }
type Node ¶
type Node interface { // Return a reference to the node substring in the source code View() core.UnmanagedSourceView // Regenerate ("format") the code to a unique, single representation. String(ctx *StringContext) string }
type ParameterNode ¶
type ParameterNode struct { Type TypeNode Register RegisterNode }
func (ParameterNode) String ¶
func (n ParameterNode) String(ctx *StringContext) string
func (ParameterNode) View ¶
func (n ParameterNode) View() core.UnmanagedSourceView
type ParameterParser ¶
type ParameterParser struct { TypeParser TypeParser RegisterParser Parser[RegisterNode] }
func NewParameterParser ¶
func NewParameterParser() ParameterParser
func (ParameterParser) Parse ¶
func (p ParameterParser) Parse(v *TokenView) (node ParameterNode, err core.Result)
type Parser ¶
func NewArgumentParser ¶
func NewArgumentParser() Parser[ArgumentNode]
func NewConstDeclarationParser ¶
func NewConstDeclarationParser() Parser[ConstDeclarationNode]
func NewConstParser ¶
func NewGlobalParser ¶
func NewGlobalParser() Parser[GlobalNode]
func NewLabelParser ¶
func NewRegisterParser ¶
func NewRegisterParser() Parser[RegisterNode]
func NewTargetParser ¶
func NewTargetParser() Parser[TargetNode]
func NewTypeFieldParser ¶
func NewTypeFieldParser() Parser[TypeFieldNode]
func NewVarDeclarationParser ¶
func NewVarDeclarationParser() Parser[VarDeclarationNode]
func NewVarParser ¶
type RegisterNode ¶
type RegisterNode struct{ TokenNode }
func RegisterNodeCreator ¶
func RegisterNodeCreator(tkn lex.Token) RegisterNode
type RegisterParser ¶
type RegisterParser struct{ TokenParser[RegisterNode] }
type StringContext ¶
type StringContext struct { core.SourceContext Indent int }
type TargetNode ¶
type TargetNode struct { // Optional type declaration. Depending on the instruction, the type may be // inferred and does not need to be provided explicitly. Type *TypeNode Register RegisterNode }
func (TargetNode) String ¶
func (n TargetNode) String(ctx *StringContext) (s string)
func (TargetNode) View ¶
func (n TargetNode) View() core.UnmanagedSourceView
type TargetParser ¶
type TargetParser struct { TypeParser RegisterParser Parser[RegisterNode] }
func (TargetParser) Parse ¶
func (p TargetParser) Parse(v *TokenView) (node TargetNode, err core.Result)
type TokenNode ¶
type TokenNode struct {
core.UnmanagedSourceView
}
func (TokenNode) String ¶
func (n TokenNode) String(ctx *StringContext) string
func (TokenNode) View ¶
func (n TokenNode) View() core.UnmanagedSourceView
type TokenParser ¶
type TokenView ¶
func NewTokenView ¶
func (*TokenView) ConsumeAtLeastTokens ¶
func (v *TokenView) ConsumeAtLeastTokens( atLeast int, expectedTypes ...lex.TokenType, ) (err core.Result)
Consume as many tokens as possible greedily, until we receive an error.
If the number of tokens consumed is strictly less than the provided number, returns the underlying error. Otherwise, returns nil.
func (*TokenView) ConsumeManyTokens ¶
func (v *TokenView) ConsumeManyTokens( expectedTypes ...lex.TokenType, ) (count int, err core.Result)
Consume as many tokens as possible greedily, until we receive an error. The error and token count are returned.
func (*TokenView) ConsumeToken ¶
type TypeDeclarationNode ¶
type TypeDeclarationNode struct { core.UnmanagedSourceView Identifier core.UnmanagedSourceView Fields BlockNode[TypeFieldNode] }
func (TypeDeclarationNode) String ¶
func (n TypeDeclarationNode) String(ctx *StringContext) string
func (TypeDeclarationNode) View ¶
func (n TypeDeclarationNode) View() core.UnmanagedSourceView
type TypeDeclarationParser ¶
type TypeDeclarationParser struct {
FieldsParser BlockParser[TypeFieldNode]
}
func NewTypeDeclarationParser ¶
func NewTypeDeclarationParser() TypeDeclarationParser
func (TypeDeclarationParser) Parse ¶
func (p TypeDeclarationParser) Parse(v *TokenView) (node TypeDeclarationNode, err core.Result)
type TypeDecoratorNode ¶
type TypeDecoratorNode struct { core.UnmanagedSourceView Type TypeDecoratorType }
func (TypeDecoratorNode) String ¶
func (n TypeDecoratorNode) String(ctx *StringContext) string
func (TypeDecoratorNode) View ¶
func (n TypeDecoratorNode) View() core.UnmanagedSourceView
type TypeDecoratorParser ¶
type TypeDecoratorParser struct{}
func NewTypeDecoratorParser ¶
func NewTypeDecoratorParser() TypeDecoratorParser
func (TypeDecoratorParser) Parse ¶
func (p TypeDecoratorParser) Parse(v *TokenView) (node TypeDecoratorNode, err core.Result)
type TypeDecoratorType ¶
type TypeDecoratorType uint8
const ( PointerTypeDecorator TypeDecoratorType = iota RepeatTypeDecorator )
type TypeFieldNode ¶
func (TypeFieldNode) String ¶
func (n TypeFieldNode) String(ctx *StringContext) (s string)
func (TypeFieldNode) View ¶
func (n TypeFieldNode) View() core.UnmanagedSourceView
type TypeFieldParser ¶
type TypeFieldParser struct { LabelParser Parser[LabelNode] TypeParser TypeParser }
func (TypeFieldParser) Parse ¶
func (p TypeFieldParser) Parse(v *TokenView) (node TypeFieldNode, err core.Result)
type TypeNode ¶
type TypeNode struct { Identifier core.UnmanagedSourceView Decorators []TypeDecoratorNode }
func (TypeNode) String ¶
func (n TypeNode) String(ctx *StringContext) string
func (TypeNode) View ¶
func (n TypeNode) View() core.UnmanagedSourceView
type TypeParser ¶
type TypeParser struct {
TypeDecoratorParser
}
func NewTypeParser ¶
func NewTypeParser() TypeParser
type VarDeclarationNode ¶
type VarDeclarationNode struct {
Declaration GlobalDeclarationNode
}
func (VarDeclarationNode) String ¶
func (n VarDeclarationNode) String(ctx *StringContext) string
func (VarDeclarationNode) View ¶
func (n VarDeclarationNode) View() core.UnmanagedSourceView
type VarDeclarationParser ¶
type VarDeclarationParser struct { VarParser Parser[VarNode] GlobalDeclarationParser GlobalDeclarationParser }
func (VarDeclarationParser) Parse ¶
func (p VarDeclarationParser) Parse(v *TokenView) ( node VarDeclarationNode, err core.Result, )
type VarParser ¶
type VarParser struct{ TokenParser[VarNode] }