parser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BASICLIT = 57353
View Source
const BOOL = 57355
View Source
const COMMA = 57354
View Source
const COMMENT = 57360
View Source
const EOF = 0

The parser expects the lexer to return 0 on EOF. Give it a name for clarity.

View Source
const FLOAT = 57358
View Source
const IDENT = 57346
View Source
const ILLEGAL = 57361
View Source
const IMAG = 57359
View Source
const INT = 57357
View Source
const LAND = 57347
View Source
const LOR = 57348
View Source
const LPAREN = 57349
View Source
const NOT = 57351
View Source
const RPAREN = 57350
View Source
const SEMICOLON = 57352
View Source
const STRING = 57356

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f for all the non-nil children of node, recursively.

func Parse

func Parse(condStr string) (Node, []*Ident, error)

Parse parse given condition string.

condStr: input condition expression err : err is not nil if parse error(including scan, lexer, prototype check) idents: if err is nil, all conditionVariable is list in idents ([]*Ident) node: if err is nil, parsed ast is returned by node

func Walk

func Walk(v Visitor, node Node)

Types

type BasicLit

type BasicLit struct {
	Kind     Token
	Value    string
	ValuePos token.Pos
}

func (*BasicLit) End

func (b *BasicLit) End() token.Pos

func (*BasicLit) Pos

func (b *BasicLit) Pos() token.Pos

func (*BasicLit) ToBool

func (b *BasicLit) ToBool() bool

type BasicLitList

type BasicLitList []*BasicLit

func (BasicLitList) End

func (b BasicLitList) End() token.Pos

func (BasicLitList) Pos

func (b BasicLitList) Pos() token.Pos

type BinaryExpr

type BinaryExpr struct {
	X  Expr
	Op Token
	Y  Expr
}

func (*BinaryExpr) End

func (b *BinaryExpr) End() token.Pos

func (*BinaryExpr) Pos

func (b *BinaryExpr) Pos() token.Pos

type CallExpr

type CallExpr struct {
	Fun    *Ident
	Args   BasicLitList
	Rparen token.Pos
}

func (*CallExpr) End

func (c *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (c *CallExpr) Pos() token.Pos

func (CallExpr) String

func (c CallExpr) String() string

type Error

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

func (Error) Error

func (e Error) Error() string

type ErrorHandler

type ErrorHandler func(pos token.Pos, msg string)

ErrorHandler is error handler for scanner and lexer

type Expr

type Expr interface {
	Node
}

type Ident

type Ident struct {
	Name    string
	NamePos token.Pos
}

func (*Ident) End

func (id *Ident) End() token.Pos

func (*Ident) Pos

func (id *Ident) Pos() token.Pos

type Node

type Node interface {
	Pos() token.Pos
	End() token.Pos
}

type ParenExpr

type ParenExpr struct {
	X Expr
}

func (ParenExpr) End

func (p ParenExpr) End() token.Pos

func (ParenExpr) Pos

func (p ParenExpr) Pos() token.Pos

type Parser

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

func (*Parser) Error

func (p *Parser) Error() error

Error return first error.

func (*Parser) Init

func (p *Parser) Init(src []byte)

func (*Parser) Parse

func (p *Parser) Parse()

func (Parser) String

func (p Parser) String() string

String returns string representation of parsed variables and errors.

type Scanner

type Scanner struct {
	ErrorCount int
	// contains filtered or unexported fields
}

func (*Scanner) Init

func (s *Scanner) Init(file *token.File, src []byte, err ErrorHandler)

Init prepares the scanner s to tokenize the text src by setting the scanner at the beginning of src. The scanner uses the file set file for position information and it adds line information for each line. It is ok to re-use the same file when re-scanning the same file as line information which is already present is ignored. Init causes a panic if the file size does not match the src size.

Calls to Scan will invoke the error handler err if they encounter a syntax error and err is not nil. Also, for each error encountered, the Scanner field ErrorCount is incremented by one. The mode parameter determines how comments are handled.

Note that Init may call err if there is an error in the first character of the file.

func (*Scanner) Scan

func (s *Scanner) Scan() (pos token.Pos, tok Token, lit string)

type Token

type Token int

func Lookup

func Lookup(ident string) Token

func (Token) String

func (t Token) String() string

func (Token) Symbol

func (t Token) Symbol() string

type UnaryExpr

type UnaryExpr struct {
	X     Expr
	Op    Token
	OpPos token.Pos
}

func (*UnaryExpr) End

func (u *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (u *UnaryExpr) Pos() token.Pos

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

Visitor wraps the Visit method which is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

Jump to

Keyboard shortcuts

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