parser

package
v2.0.0-...-d9f0f44 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string) (Expression, []ParseError)

Parse parses an expression and returns its AST representation.

Types

type ArithmeticExpression

type ArithmeticExpression struct {
	LHS      Expression
	Operator Operator
	RHS      Expression
	Position lexer.Position
}

ArithmeticExpression is an expression that contains a +, * operator.

type DataType

type DataType int

DataType represents the primitive data types.

const (
	// Unknown primitive data type.
	Unknown DataType = iota
	// Float means the data type is a float.
	Float DataType = 1
	// Integer means the data type is an integer.
	Integer DataType = 2
)

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression is a combination of numbers, variables and operators that can be evaluated to a value.

type IntLiteral

type IntLiteral struct {
	Value    int64
	Position lexer.Position
}

IntLiteral is an expression that contains a single constant integer number.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node represents a node in the abstract syntax tree.

type Operator

type Operator int

Operator represents an arithmatic operator.

const (
	Add      Operator = iota // +
	Multiply                 // *
)

Types of operators

type ParseError

type ParseError struct {
	Message  string
	Found    string
	Expected []string
	Pos      lexer.Position
}

ParseError represents an error that occurred during parsing.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the string representation of the error.

type Parser

type Parser struct {
	Errors []ParseError
	// contains filtered or unexported fields
}

func NewParser

func NewParser(scanner *lexer.Scanner) *Parser

NewParser returns a new instance of Parser.

func (*Parser) ParseExpression

func (p *Parser) ParseExpression() Expression

ParseExpression parses expressions that might contain any arthimatic operator.

func (*Parser) ParseFactor

func (p *Parser) ParseFactor() Expression

ParseFactor parses a single variable, single constant number or (...some expr...).

func (*Parser) ParseInteger

func (p *Parser) ParseInteger() Expression

func (*Parser) ParsePod

func (p *Parser) ParsePod() Expression

func (*Parser) ParseString

func (p *Parser) ParseString() Expression

func (*Parser) ParseStringOrInteger

func (p *Parser) ParseStringOrInteger() Expression

func (*Parser) ParseTerm

func (p *Parser) ParseTerm() Expression

ParseTerm parses expressions that might contain multipications.

type PodExpression

type PodExpression struct {
	CPU      Expression
	Memory   Expression
	GPU      Expression
	Position lexer.Position
}

PodExpression is an expression that represents a pod.

type StringLiteral

type StringLiteral struct {
	Value    string
	Position lexer.Position
}

String is an expression that contains a string.

Jump to

Keyboard shortcuts

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