syntax

package
v0.0.0-...-cb985d4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBinaryOperatorPrecedence

func GetBinaryOperatorPrecedence(kind SyntaxKind) int

func GetUnaryOperatorPrecedence

func GetUnaryOperatorPrecedence(kind SyntaxKind) int

func PrintExpress

func PrintExpress(writer io.Writer, express Express, indent string, isLast bool) (err error)

func SyntaxNodeSpan

func SyntaxNodeSpan(n SyntaxNode) texts.TextSpan

Types

type AssignmentExpress

type AssignmentExpress struct {
	Identifier SyntaxToken
	Equal      SyntaxToken
	Express    Express
}

func NewAssignmentExpress

func NewAssignmentExpress(identifier SyntaxToken, equal SyntaxToken, express Express) *AssignmentExpress

func (*AssignmentExpress) GetChildren

func (e *AssignmentExpress) GetChildren() []SyntaxNode

func (*AssignmentExpress) Kind

func (e *AssignmentExpress) Kind() SyntaxKind

type BinaryExpress

type BinaryExpress struct {
	Operator SyntaxToken
	Left     Express
	Right    Express
}

func NewBinaryExpress

func NewBinaryExpress(left Express, operator SyntaxToken, right Express) *BinaryExpress

func (*BinaryExpress) GetChildren

func (e *BinaryExpress) GetChildren() []SyntaxNode

func (*BinaryExpress) Kind

func (e *BinaryExpress) Kind() SyntaxKind

type BlockStatement

type BlockStatement struct {
	OpenBraceToken  SyntaxToken
	Statements      []Statement
	CloseBraceToken SyntaxToken
}

func NewBlockStatement

func NewBlockStatement(open SyntaxToken, Statement []Statement, close SyntaxToken) *BlockStatement

func (*BlockStatement) GetChildren

func (e *BlockStatement) GetChildren() []SyntaxNode

func (*BlockStatement) Kind

func (e *BlockStatement) Kind() SyntaxKind

type BreakStatement

type BreakStatement struct {
	Keywords SyntaxToken
}

func NewBreakStatement

func NewBreakStatement(keywords SyntaxToken) *BreakStatement

func (*BreakStatement) GetChildren

func (e *BreakStatement) GetChildren() []SyntaxNode

func (*BreakStatement) Kind

func (e *BreakStatement) Kind() SyntaxKind

type CallExpress

type CallExpress struct {
	Identifier       SyntaxToken
	OpenParenthesis  SyntaxToken
	Params           SeparatedList
	CloseParenthesis SyntaxToken
}

func NewCallExpress

func NewCallExpress(identifier SyntaxToken, openParenthesis SyntaxToken, params SeparatedList, closeParenthises SyntaxToken) *CallExpress

func (*CallExpress) GetChildren

func (c *CallExpress) GetChildren() []SyntaxNode

func (*CallExpress) Kind

func (c *CallExpress) Kind() SyntaxKind

type CompliationUnit

type CompliationUnit struct {
	Statements []MemberSyntax
	EofToken   SyntaxToken
}

func NewCompliationUnit

func NewCompliationUnit(Statements []MemberSyntax, eofToken SyntaxToken) *CompliationUnit

func (*CompliationUnit) GetChildren

func (e *CompliationUnit) GetChildren() []SyntaxNode

func (*CompliationUnit) Kind

func (e *CompliationUnit) Kind() SyntaxKind

type ContinueStatement

type ContinueStatement struct {
	Keywords SyntaxToken
}

func NewContinueStatement

func NewContinueStatement(keywords SyntaxToken) *ContinueStatement

func (*ContinueStatement) GetChildren

func (e *ContinueStatement) GetChildren() []SyntaxNode

func (*ContinueStatement) Kind

func (e *ContinueStatement) Kind() SyntaxKind

type ElseClauseSyntax

type ElseClauseSyntax struct {
	ElseKeywords  SyntaxToken
	ElseStatement Statement
}

func NewElseClause

func NewElseClause(elseKeywords SyntaxToken, elsStatement Statement) *ElseClauseSyntax

func (*ElseClauseSyntax) GetChildren

func (e *ElseClauseSyntax) GetChildren() []SyntaxNode

func (*ElseClauseSyntax) Kind

func (e *ElseClauseSyntax) Kind() SyntaxKind

type Express

type Express interface {
	SyntaxNode
}

type ExpressStatement

type ExpressStatement struct {
	Express Express
}

func NewExpressStatement

func NewExpressStatement(express Express) *ExpressStatement

func (*ExpressStatement) GetChildren

func (e *ExpressStatement) GetChildren() []SyntaxNode

func (*ExpressStatement) Kind

func (e *ExpressStatement) Kind() SyntaxKind

type ForStatement

type ForStatement struct {
	ForKeywords     SyntaxToken
	InitCondition   Express
	FirstSemicolon  SyntaxToken
	EndCondition    Express
	SecondSemicolon SyntaxToken
	UpdateCondition Express
	Body            Statement
}

func NewForStatement

func NewForStatement(forKeywords SyntaxToken,
	initCondition Statement,
	firstSemicolon SyntaxToken,
	endCondtion Express,
	secondSemicolon SyntaxToken,
	UpdateCondition Statement,
	body Statement) *ForStatement

func (*ForStatement) GetChildren

func (e *ForStatement) GetChildren() []SyntaxNode

func (*ForStatement) Kind

func (s *ForStatement) Kind() SyntaxKind

type FunctionDeclarationSyntax

type FunctionDeclarationSyntax struct {
	Keyword          SyntaxToken
	Identifier       SyntaxToken
	OpenParenthesis  SyntaxToken
	ParameterList    *SeparatedList
	CloseParenthesis SyntaxToken
	Type             *TypeClauseSyntax
	Body             *BlockStatement
}

func NewFunctionDeclaration

func NewFunctionDeclaration(keyword, identifier, openParenthesis SyntaxToken,
	parameterList *SeparatedList,
	closeParenthesis SyntaxToken, tp *TypeClauseSyntax, body *BlockStatement) *FunctionDeclarationSyntax

func (*FunctionDeclarationSyntax) GetChildren

func (e *FunctionDeclarationSyntax) GetChildren() []SyntaxNode

func (*FunctionDeclarationSyntax) Kind

type GlobalStatement

type GlobalStatement struct {
	Statement Statement
}

func NewGlobalStatement

func NewGlobalStatement(statement Statement) *GlobalStatement

func (*GlobalStatement) GetChildren

func (e *GlobalStatement) GetChildren() []SyntaxNode

func (*GlobalStatement) Kind

func (e *GlobalStatement) Kind() SyntaxKind

type IfStatement

type IfStatement struct {
	IfKeywords    SyntaxToken
	Condition     Express
	ThenStatement Statement
	ElseClause    *ElseClauseSyntax
}

func NewIfStatement

func NewIfStatement(ifKeywords SyntaxToken, condition Express, thenStatement Statement, elseClause *ElseClauseSyntax) *IfStatement

func (*IfStatement) GetChildren

func (e *IfStatement) GetChildren() []SyntaxNode

func (*IfStatement) Kind

func (s *IfStatement) Kind() SyntaxKind

type Lexer

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

func NewLexer

func NewLexer(text *texts.TextSource) *Lexer

func (*Lexer) Current

func (l *Lexer) Current() rune

func (*Lexer) Diagnostics

func (l *Lexer) Diagnostics() *diagnostic.DiagnosticBag

func (*Lexer) Lookahead

func (l *Lexer) Lookahead() rune

func (*Lexer) NextToken

func (l *Lexer) NextToken() SyntaxToken

func (*Lexer) Peek

func (l *Lexer) Peek(offset int) rune

type LiteralExpress

type LiteralExpress struct {
	Literal SyntaxToken
	Value   any
}

func NewLiteralExpress

func NewLiteralExpress(literal SyntaxToken) *LiteralExpress

func NewLiteralValueExpress

func NewLiteralValueExpress(literal SyntaxToken, value any) *LiteralExpress

func (*LiteralExpress) GetChildren

func (e *LiteralExpress) GetChildren() []SyntaxNode

func (*LiteralExpress) Kind

func (e *LiteralExpress) Kind() SyntaxKind

type MemberSyntax

type MemberSyntax interface {
	SyntaxNode
}

type NameExpress

type NameExpress struct {
	Identifier SyntaxToken
}

func NewNameExpress

func NewNameExpress(Identifier SyntaxToken) *NameExpress

func (*NameExpress) GetChildren

func (e *NameExpress) GetChildren() []SyntaxNode

func (*NameExpress) Kind

func (e *NameExpress) Kind() SyntaxKind

type ParameterSyntax

type ParameterSyntax struct {
	Identifier SyntaxToken
	Type       *TypeClauseSyntax
}

func NewParameterSyntax

func NewParameterSyntax(identifier SyntaxToken, tp *TypeClauseSyntax) *ParameterSyntax

func (*ParameterSyntax) GetChildren

func (e *ParameterSyntax) GetChildren() []SyntaxNode

func (*ParameterSyntax) Kind

func (e *ParameterSyntax) Kind() SyntaxKind

type ParenthesisExpress

type ParenthesisExpress struct {
	Open  SyntaxToken
	Close SyntaxToken
	Expr  Express
}

func NewParenthesisExpress

func NewParenthesisExpress(open SyntaxToken, expr Express, close SyntaxToken) *ParenthesisExpress

func (*ParenthesisExpress) GetChildren

func (e *ParenthesisExpress) GetChildren() []SyntaxNode

func (*ParenthesisExpress) Kind

func (e *ParenthesisExpress) Kind() SyntaxKind

func (*ParenthesisExpress) String

func (e *ParenthesisExpress) String() string

type Parser

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

func NewParser

func NewParser(text *texts.TextSource) *Parser

func (*Parser) Current

func (p *Parser) Current() SyntaxToken

func (*Parser) MatchToken

func (p *Parser) MatchToken(kind SyntaxKind) SyntaxToken

func (*Parser) NextToken

func (p *Parser) NextToken() SyntaxToken

func (*Parser) ParseBlockStatement

func (p *Parser) ParseBlockStatement() *BlockStatement

func (*Parser) ParseBreakStatement

func (p *Parser) ParseBreakStatement() Statement

func (*Parser) ParseCallExpress

func (p *Parser) ParseCallExpress() Express

func (*Parser) ParseComplitionUnit

func (p *Parser) ParseComplitionUnit() *CompliationUnit

func (*Parser) ParseContinueStatement

func (p *Parser) ParseContinueStatement() Statement

func (*Parser) ParseElseClause

func (p *Parser) ParseElseClause() *ElseClauseSyntax

func (*Parser) ParseExpressStatement

func (p *Parser) ParseExpressStatement() *ExpressStatement

func (*Parser) ParseForStatement

func (p *Parser) ParseForStatement() Statement

func (*Parser) ParseFunctionDeclaration

func (p *Parser) ParseFunctionDeclaration() MemberSyntax

func (*Parser) ParseGlobalStatement

func (p *Parser) ParseGlobalStatement() MemberSyntax

func (*Parser) ParseIfStatement

func (p *Parser) ParseIfStatement() Statement

func (*Parser) ParseMember

func (p *Parser) ParseMember() MemberSyntax

func (*Parser) ParseMembers

func (p *Parser) ParseMembers() []MemberSyntax

func (*Parser) ParseOptionTypeClause

func (p *Parser) ParseOptionTypeClause() *TypeClauseSyntax

func (*Parser) ParseParameter

func (p *Parser) ParseParameter() *ParameterSyntax

func (*Parser) ParseParameterList

func (p *Parser) ParseParameterList() *SeparatedList

func (*Parser) ParseParams

func (p *Parser) ParseParams() *SeparatedList

func (*Parser) ParseReturnStatement

func (p *Parser) ParseReturnStatement() Statement

func (*Parser) ParseStatement

func (p *Parser) ParseStatement() Statement

func (*Parser) ParseTypeClause

func (p *Parser) ParseTypeClause() *TypeClauseSyntax

func (*Parser) ParseVariableDeclaration

func (p *Parser) ParseVariableDeclaration() Statement

func (*Parser) ParseWhileStatement

func (p *Parser) ParseWhileStatement() Statement

func (*Parser) ParserAssignmentExpress

func (p *Parser) ParserAssignmentExpress() Express

func (*Parser) ParserBinaryExpress

func (p *Parser) ParserBinaryExpress(parentPrecedence int) Express

func (*Parser) ParserExpress

func (p *Parser) ParserExpress() Express

func (*Parser) ParserNameExpress

func (p *Parser) ParserNameExpress() Express

func (*Parser) Peek

func (p *Parser) Peek(offset int) SyntaxToken

type ReturnStatement

type ReturnStatement struct {
	ReturnKeywords SyntaxToken
	Express        Express
}

func NewReturnStatement

func NewReturnStatement(returnKeywords SyntaxToken,
	express Express) *ReturnStatement

func (*ReturnStatement) GetChildren

func (e *ReturnStatement) GetChildren() []SyntaxNode

func (*ReturnStatement) Kind

func (s *ReturnStatement) Kind() SyntaxKind

type SeparatedList

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

func NewSeptartedList

func NewSeptartedList(list []SyntaxNode) *SeparatedList

func (*SeparatedList) Count

func (s *SeparatedList) Count() int

func (*SeparatedList) Get

func (s *SeparatedList) Get(x int) SyntaxNode

func (*SeparatedList) GetSeparator

func (s *SeparatedList) GetSeparator(i int) *SyntaxToken

func (*SeparatedList) List

func (s *SeparatedList) List() []SyntaxNode

func (*SeparatedList) ListWithSpearated

func (s *SeparatedList) ListWithSpearated() []SyntaxNode

type Statement

type Statement interface {
	SyntaxNode
}

type SyntaxKind

type SyntaxKind uint8
const (
	SyntaxKindBadToken SyntaxKind = iota
	SyntaxKindEofToken
	SyntaxKindWhiteSpaceToken
	SyntaxKindNumberToken             // 12
	SyntaxKindStringToken             //"abc"
	SyntaxKindPlusToken               //+
	SyntaxKindMinusToken              //-
	SyntaxKindStarToken               //*
	SyntaxKindSlashToken              // /
	SyntaxKindBangToken               //!
	SyntaxKindEqualToken              //=
	SyntaxKindAmpersandAmpersandToken //&&
	SyntaxKindPipePileToken           // ||
	SyntaxKindEqualEqualToken         // ==
	SyntaxKindBangEqualToken          // !=
	SyntaxKindLessToken               // <
	SyntaxKindLessEqualToken          // <=
	SyntaxKindGreatToken              // >
	SyntaxKindGreatEqualToken         //>=
	SyntaxKindOpenParenthesisToken    //(
	SyntaxKindCloseParenthesisToken   //)
	SyntaxKindOpenBraceToken          //{
	SyntaxKindCloseBraceToken         //}
	SyntaxKindSemicolon               // ;
	SyntaxKindColon                   // :
	SyntaxKindCommaToken              //,
	SyntaxKindIdentifierToken

	//bitwise operators
	SyntaxKindTildeToken     // ~
	SyntaxKindHatToken       // ^
	SyntaxKindAmpersandToken // &
	SyntaxKindPipeToken      // |

	SyntaxKindTrueKeywords  // True
	SyntaxKindFalseKeywords //False
	SyntaxKindLetKeywords
	SyntaxKindVarKeywords
	SyntaxKindIfKeywords
	SyntaxKindElseKeywords
	SyntaxKindWhileKeywords
	SyntaxKindBreakKeywords
	SyntaxKindContinueKeywords
	SyntaxkindForKeywords
	SyntaxkindFunctionKeywords
	SyntaxKindReturnKeywords

	//Nodes
	SyntaxKindCompilationUnit
	SyntaxKindGlobalStatement
	SyntaxKindFunctionDeclaration
	SyntaxKindTypeClause
	SyntaxKindParameter

	//Statement
	SyntaxKindBlockStatement
	SyntaxKindVariableDeclaration
	SyntaxKindIfStatement
	SyntaxKindWhileStatement
	SyntaxkindForStatement
	SyntaxKindBreakStatement
	SyntaxKindContinueStatement
	SyntaxKindReturnStatement
	SyntaxKindExpressStatement

	SyntaxKindLiteralExpress
	SyntaxKindNameExpress
	SyntaxKindUnaryExpress
	SyntaxKindBinaryExpress
	SyntaxKindParenthesizedExpress
	SyntaxKindAssignmentExpress
	SyntaxKindCallExpress
	SyntaxKindUnitExpress
)

func GetKeyWordsKind

func GetKeyWordsKind(text string) SyntaxKind

func ListTextSyntaxKind

func ListTextSyntaxKind() []SyntaxKind

func (SyntaxKind) String

func (k SyntaxKind) String() string

func (SyntaxKind) Text

func (k SyntaxKind) Text() string

func (SyntaxKind) TextMust

func (k SyntaxKind) TextMust() string

type SyntaxNode

type SyntaxNode interface {
	GetChildren() []SyntaxNode
	Kind() SyntaxKind
}

type SyntaxToken

type SyntaxToken struct {
	Position int
	Text     string
	Value    any
	Missing  bool
	// contains filtered or unexported fields
}

func GetLastToken

func GetLastToken(n SyntaxNode) *SyntaxToken

func ParseTokens

func ParseTokens(text string) (res []SyntaxToken)

func (SyntaxToken) GetChildren

func (s SyntaxToken) GetChildren() []SyntaxNode

func (SyntaxToken) Kind

func (e SyntaxToken) Kind() SyntaxKind

func (SyntaxToken) Span

func (e SyntaxToken) Span() texts.TextSpan

type SyntaxTree

type SyntaxTree struct {
	Text        *texts.TextSource
	Root        *CompliationUnit
	Diagnostics *diagnostic.DiagnosticBag
}

func ParseToTree

func ParseToTree(sourceText *texts.TextSource) *SyntaxTree

func ParseToTreeRaw

func ParseToTreeRaw(text string) *SyntaxTree

func (*SyntaxTree) Print

func (s *SyntaxTree) Print(w io.Writer) (err error)

type TypeClauseSyntax

type TypeClauseSyntax struct {
	ColonToken SyntaxToken
	Identifier SyntaxToken
}

func NewTypeClauseSyntax

func NewTypeClauseSyntax(colonToken, Identifier SyntaxToken) *TypeClauseSyntax

func (*TypeClauseSyntax) GetChildren

func (e *TypeClauseSyntax) GetChildren() []SyntaxNode

func (*TypeClauseSyntax) Kind

func (e *TypeClauseSyntax) Kind() SyntaxKind

type UnaryExpress

type UnaryExpress struct {
	Operator SyntaxToken
	Operand  Express
}

func NewUnaryExpress

func NewUnaryExpress(operator SyntaxToken, operand Express) *UnaryExpress

func (*UnaryExpress) GetChildren

func (e *UnaryExpress) GetChildren() []SyntaxNode

func (*UnaryExpress) Kind

func (e *UnaryExpress) Kind() SyntaxKind

type UnitExpress

type UnitExpress struct {
	Open  SyntaxToken
	Close SyntaxToken
}

func NewUnitExpress

func NewUnitExpress(open SyntaxToken, close SyntaxToken) *UnitExpress

func (*UnitExpress) GetChildren

func (e *UnitExpress) GetChildren() []SyntaxNode

func (*UnitExpress) Kind

func (e *UnitExpress) Kind() SyntaxKind

func (*UnitExpress) String

func (e *UnitExpress) String() string

type VariableDeclarationSyntax

type VariableDeclarationSyntax struct {
	Keyword     SyntaxToken
	Identifier  SyntaxToken
	TypeClause  *TypeClauseSyntax
	Equals      SyntaxToken
	Initializer Express
}

func NewVariableDeclarationSyntax

func NewVariableDeclarationSyntax(keyword, Identifier SyntaxToken, typeClause *TypeClauseSyntax, equal SyntaxToken, initializer Express) *VariableDeclarationSyntax

func (*VariableDeclarationSyntax) GetChildren

func (e *VariableDeclarationSyntax) GetChildren() []SyntaxNode

func (*VariableDeclarationSyntax) Kind

type WhileStatement

type WhileStatement struct {
	WhileKeywords SyntaxToken
	Condition     Express
	Body          Statement
}

func NewWhileStatement

func NewWhileStatement(whileKeywords SyntaxToken, condition Express, statement Statement) *WhileStatement

func (*WhileStatement) GetChildren

func (e *WhileStatement) GetChildren() []SyntaxNode

func (*WhileStatement) Kind

func (s *WhileStatement) Kind() SyntaxKind

Jump to

Keyboard shortcuts

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