Documentation
¶
Index ¶
- Constants
- Variables
- func RemoveSpaces(t Token) bool
- func StripCR(b []byte, comment bool) []byte
- func TrimSpace(left, right bool, s string) string
- func Unquote(s string) (string, error)
- type BlockEnd
- type BlockWrap
- type Error
- type ErrorList
- func (p *ErrorList) Add(pos source.SourceFilePos, msg string)
- func (p ErrorList) Err() error
- func (p ErrorList) Error() string
- func (p ErrorList) Format(f fmt.State, verb rune)
- func (p ErrorList) Len() int
- func (p ErrorList) Less(i, j int) bool
- func (p ErrorList) Sort()
- func (p ErrorList) Swap(i, j int)
- type File
- type Handlers
- type MixedDelimiter
- type Mode
- type ParseListHandler
- type Parser
- func (p *Parser) AtComma(context string, follow token.Token) bool
- func (p *Parser) CallArgsOf(lparen, rparen source.Pos, exprs ...node.Expr) (params *node.CallArgs)
- func (p *Parser) DefaultParseStmt() (stmt node.Stmt)
- func (p *Parser) Error(pos source.Pos, msg string)
- func (p *Parser) ErrorExpected(pos source.Pos, msg string)
- func (p *Parser) ErrorExpectedExpr(expected, got node.Expr)
- func (p *Parser) Expect(token token.Token) source.Pos
- func (p *Parser) ExpectLit(token token.Token) ast.Literal
- func (p *Parser) ExpectLits(toks ...token.Token) ast.Literal
- func (p *Parser) ExpectSemi()
- func (p *Parser) ExpectToken(token token.Token) (tok Token)
- func (p *Parser) FuncParamsOf(lparen, rparen source.Pos, exprs ...node.Expr) (params *node.FuncParams)
- func (p *Parser) IsToken(toks ...token.Token) bool
- func (p *Parser) MakeExpr(s node.Stmt, want string) node.Expr
- func (p *Parser) Next()
- func (p *Parser) ParseArrayLitOrKeyValue() node.Expr
- func (p *Parser) ParseBinaryExpr(prec1 int) node.Expr
- func (p *Parser) ParseBlockStmt(ends ...token.Token) *node.BlockStmt
- func (p *Parser) ParseBody() (b *node.BlockStmt, closure node.Expr)
- func (p *Parser) ParseBranchStmt(tok token.Token) node.Stmt
- func (p *Parser) ParseCall(x node.Expr) *node.CallExpr
- func (p *Parser) ParseCallArgs(start, end token.Token) *node.CallArgs
- func (p *Parser) ParseCatchStmt() *node.CatchStmt
- func (p *Parser) ParseCharLit() node.Expr
- func (p *Parser) ParseCondExpr(cond node.Expr) node.Expr
- func (p *Parser) ParseConfigStmt() (c *node.ConfigStmt)
- func (p *Parser) ParseDecl() node.Decl
- func (p *Parser) ParseDictLit() *node.DictLit
- func (p *Parser) ParseElse(ifs bool) node.Stmt
- func (p *Parser) ParseExpr() node.Expr
- func (p *Parser) ParseExprList() (list []node.Expr)
- func (p *Parser) ParseFile() (file *File, err error)
- func (p *Parser) ParseFileH(listHandler ParseListHandler) (file *File, err error)
- func (p *Parser) ParseFinallyStmt() *node.FinallyStmt
- func (p *Parser) ParseForStmt() node.Stmt
- func (p *Parser) ParseFuncLit() node.Expr
- func (p *Parser) ParseFuncParams(parseLambda bool) *node.FuncParams
- func (p *Parser) ParseFuncType(parseLambda bool) *node.FuncType
- func (p *Parser) ParseGenDecl(keyword token.Token, fn func(token.Token, bool, []node.Spec, int) node.Spec) *node.GenDecl
- func (p *Parser) ParseIdent() *node.Ident
- func (p *Parser) ParseIfHeader() (init node.Stmt, cond node.Expr)
- func (p *Parser) ParseIfStmt() node.Stmt
- func (p *Parser) ParseImportExpr() node.Expr
- func (p *Parser) ParseIndexOrSlice(x node.Expr) node.Expr
- func (p *Parser) ParseKeyValueArrayLit(lbrace source.Pos) *node.KeyValueArrayLit
- func (p *Parser) ParseKeyValueArrayLitAt(lbrace source.Pos, rbraceToken token.Token) *node.KeyValueArrayLit
- func (p *Parser) ParseKeyValueLit(endToken token.Token) *node.KeyValueLit
- func (p *Parser) ParseMapElementLit() *node.DictElementLit
- func (p *Parser) ParseMixedTextStmt() (t *node.MixedTextStmt)
- func (p *Parser) ParseMixedValue() (ett *node.MixedValueStmt)
- func (p *Parser) ParseNullishSelector(x node.Expr) (sel node.Expr)
- func (p *Parser) ParseOperand() node.Expr
- func (p *Parser) ParseParamDecl() (d *node.GenDecl)
- func (p *Parser) ParseParamSpec(keyword token.Token, multi bool, prev []node.Spec, i int) (spec node.Spec)
- func (p *Parser) ParseParemExpr(lparenToken, rparenToken token.Token, acceptKv, parseLambda, parseTypes bool) node.Expr
- func (p *Parser) ParsePipe(x node.Expr) node.Expr
- func (p *Parser) ParsePrimaryExpr() node.Expr
- func (p *Parser) ParsePrimitiveOperand() node.Expr
- func (p *Parser) ParseRawHeredocLit() (t *node.RawHeredocLit)
- func (p *Parser) ParseRawStringLit() (t *node.RawStringLit)
- func (p *Parser) ParseReturn() (ret node.Return)
- func (p *Parser) ParseReturnExpr() node.Expr
- func (p *Parser) ParseReturnStmt() node.Stmt
- func (p *Parser) ParseSelector(x node.Expr) (sel node.Expr)
- func (p *Parser) ParseSelectorNode(x node.Expr) (expr, sel node.Expr)
- func (p *Parser) ParseSimpleStmt(forIn bool) node.Stmt
- func (p *Parser) ParseStmt() (stmt node.Stmt)
- func (p *Parser) ParseStmtList(end ...token.Token) (list []node.Stmt)
- func (p *Parser) ParseStringLit() *node.StringLit
- func (p *Parser) ParseThrowExpr() *node.ThrowExpr
- func (p *Parser) ParseThrowStmt() node.Stmt
- func (p *Parser) ParseTryStmt() node.Stmt
- func (p *Parser) ParseType() (idents []*node.Ident)
- func (p *Parser) ParseTypedIdent() *node.TypedIdent
- func (p *Parser) ParseUnaryExpr() node.Expr
- func (p *Parser) ParseValueSpec(keyword token.Token, multi bool, _ []node.Spec, i int) node.Spec
- func (p *Parser) PrintTrace(a ...any)
- func (p *Parser) SkipSpace()
- type ParserOptions
- type ScanMode
- type Scanner
- func (s *Scanner) AddNextToken(n ...Token) (r *Token)
- func (s *Scanner) AddNextTokenPtr(n ...*Token) (r *Token)
- func (s *Scanner) Clone() (c *Scanner)
- func (s *Scanner) GetMixedDelimiter() *MixedDelimiter
- func (s *Scanner) List() (ret []Token)
- func (s *Scanner) Mode() ScanMode
- func (s *Scanner) ModeP() *ScanMode
- func (s Scanner) PeekScan() (t Token)
- func (s *Scanner) Scan() (t Token)
- func (s *Scanner) ScanCodeBlock(leftText *Token) (code Token)
- func (s *Scanner) ScanComment() string
- func (s *Scanner) ScanIdentifier() string
- func (s *Scanner) ScanNow() (t Token)
- func (s *Scanner) ScanNumber(seenDecimalPoint bool) (tok token.Token, lit string)
- func (s *Scanner) SetMode(m ScanMode)
- func (s *Scanner) Switch2(tok0, tok1 token.Token) token.Token
- func (s *Scanner) Switch3(tok0, tok1 token.Token, ch2 rune, tok2 token.Token) token.Token
- func (s *Scanner) Switch4(tok0, tok1 token.Token, ch2 rune, tok2, tok3 token.Token) token.Token
- type ScannerInterface
- type ScannerOptions
- type TextFlag
- type Token
- type TokenHandler
- type TokenHandlers
- type TokenPool
Constants ¶
View Source
const MainName = "(main)"
Variables ¶
View Source
var DefaultMixedDelimiter = MixedDelimiter{ Start: []rune("{%"), End: []rune("%}"), }
Functions ¶
func RemoveSpaces ¶
func TrimSpace ¶
TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
Types ¶
type Error ¶
type Error struct { Pos source.SourceFilePos Msg string }
Error represents a parser error.
type ErrorList ¶
type ErrorList []*Error
ErrorList is a collection of parser errors.
func (*ErrorList) Add ¶
func (p *ErrorList) Add(pos source.SourceFilePos, msg string)
Add adds a new parser error to the collection.
type File ¶
File represents a file unit.
func Parse ¶
func Parse(input, fileName string, opts *ParserOptions, scannerOpts *ScannerOptions) (*File, error)
func ParseFile ¶
func ParseFile(pth string, opts *ParserOptions, scannerOpts *ScannerOptions) (file *File, err error)
func (*File) StringTo ¶
func (n *File) StringTo(w stringw.StringWriter)
type Handlers ¶
type Handlers struct { source.NextHandlers ScanHandler func(ch rune) (t Token, insertSemi, ok bool) TokenHandlers TokenHandlers }
func (*Handlers) CallTokenHandlers ¶
func (*Handlers) TokenHandler ¶
type MixedDelimiter ¶
type MixedDelimiter = source.StartEndDelimiter
type ParseListHandler ¶
type Parser ¶
type Parser struct { File *source.File Errors ErrorList Scanner ScannerInterface Token Token PrevToken Token ExprLevel int // < 0: in control clause, >= 0: in expression Trace bool TraceOut io.Writer ParseStmtHandler func() node.Stmt InCode bool BlockStart token.Token BlockEnd token.Token ScanFunc func() Token // contains filtered or unexported fields }
Parser parses the Tengo source files. It's based on ToInterface's parser implementation.
func NewParserWithOptions ¶
func NewParserWithOptions( file *source.File, opts *ParserOptions, scannerOptions *ScannerOptions, ) *Parser
NewParserWithOptions creates a Parser with parser mode flags.
func NewParserWithScanner ¶
func NewParserWithScanner( scanner ScannerInterface, opts *ParserOptions, ) *Parser
NewParserWithScanner creates a Parser with parser mode flags.
func (*Parser) CallArgsOf ¶
func (*Parser) DefaultParseStmt ¶
func (*Parser) ErrorExpectedExpr ¶
func (*Parser) ExpectSemi ¶
func (p *Parser) ExpectSemi()
func (*Parser) FuncParamsOf ¶
func (*Parser) ParseArrayLitOrKeyValue ¶
func (*Parser) ParseBlockStmt ¶
func (*Parser) ParseCallArgs ¶
func (*Parser) ParseCatchStmt ¶
func (*Parser) ParseCharLit ¶
func (*Parser) ParseConfigStmt ¶
func (p *Parser) ParseConfigStmt() (c *node.ConfigStmt)
func (*Parser) ParseDictLit ¶
func (*Parser) ParseExprList ¶
func (*Parser) ParseFileH ¶
func (p *Parser) ParseFileH(listHandler ParseListHandler) (file *File, err error)
ParseFileH parses the source and returns an AST file unit.
func (*Parser) ParseFinallyStmt ¶
func (p *Parser) ParseFinallyStmt() *node.FinallyStmt
func (*Parser) ParseForStmt ¶
func (*Parser) ParseFuncLit ¶
func (*Parser) ParseFuncParams ¶
func (p *Parser) ParseFuncParams(parseLambda bool) *node.FuncParams
func (*Parser) ParseGenDecl ¶
func (*Parser) ParseIdent ¶
func (*Parser) ParseIfStmt ¶
func (*Parser) ParseImportExpr ¶
func (*Parser) ParseKeyValueArrayLit ¶
func (p *Parser) ParseKeyValueArrayLit(lbrace source.Pos) *node.KeyValueArrayLit
func (*Parser) ParseKeyValueArrayLitAt ¶
func (*Parser) ParseKeyValueLit ¶
func (p *Parser) ParseKeyValueLit(endToken token.Token) *node.KeyValueLit
func (*Parser) ParseMapElementLit ¶
func (p *Parser) ParseMapElementLit() *node.DictElementLit
func (*Parser) ParseMixedTextStmt ¶
func (p *Parser) ParseMixedTextStmt() (t *node.MixedTextStmt)
func (*Parser) ParseMixedValue ¶
func (p *Parser) ParseMixedValue() (ett *node.MixedValueStmt)
func (*Parser) ParseNullishSelector ¶
func (*Parser) ParseOperand ¶
func (*Parser) ParseParamDecl ¶
func (*Parser) ParseParamSpec ¶
func (*Parser) ParseParemExpr ¶
func (*Parser) ParsePrimaryExpr ¶
func (*Parser) ParsePrimitiveOperand ¶
func (*Parser) ParseRawHeredocLit ¶
func (p *Parser) ParseRawHeredocLit() (t *node.RawHeredocLit)
func (*Parser) ParseRawStringLit ¶
func (p *Parser) ParseRawStringLit() (t *node.RawStringLit)
func (*Parser) ParseReturn ¶
func (*Parser) ParseReturnExpr ¶
func (*Parser) ParseReturnStmt ¶
func (*Parser) ParseSelectorNode ¶
func (*Parser) ParseStmtList ¶
func (*Parser) ParseStringLit ¶
func (*Parser) ParseThrowExpr ¶
func (*Parser) ParseThrowStmt ¶
func (*Parser) ParseTryStmt ¶
func (*Parser) ParseTypedIdent ¶
func (p *Parser) ParseTypedIdent() *node.TypedIdent
func (*Parser) ParseUnaryExpr ¶
func (*Parser) ParseValueSpec ¶
func (*Parser) PrintTrace ¶
type ParserOptions ¶
type Scanner ¶
type Scanner struct { Handlers source.Reader MixedDelimiter MixedDelimiter // the mixed delimiters InsertSemi bool // insert a semicolon before next newline InCode bool ToText bool BraceCount int BreacksCount int ParenCount int TokenPool TokenPool SkipWhitespaceFunc func(s *Scanner) HandleMixed func(textStart *int, rt func() *Token) EOF *Token // contains filtered or unexported fields }
Scanner reads the Gad source text. It's based on ToInterface's scanner implementation.
func NewScanner ¶
func NewScanner( file *source.File, opts *ScannerOptions, ) *Scanner
NewScanner creates a Scanner.
func (*Scanner) AddNextToken ¶
func (*Scanner) AddNextTokenPtr ¶
func (*Scanner) GetMixedDelimiter ¶
func (s *Scanner) GetMixedDelimiter() *MixedDelimiter
func (*Scanner) ScanCodeBlock ¶
func (*Scanner) ScanComment ¶
func (*Scanner) ScanIdentifier ¶
func (*Scanner) ScanNumber ¶
type ScannerInterface ¶
type ScannerInterface interface { Scan() (t Token) Mode() ScanMode SetMode(m ScanMode) SourceFile() *source.File Source() []byte ErrorHandler(h ...source.ScannerErrorHandler) GetMixedDelimiter() *MixedDelimiter }
type ScannerOptions ¶
type ScannerOptions struct { Mode ScanMode MixedDelimiter MixedDelimiter }
type Token ¶
type Token struct { Pos source.Pos Token token.Token Literal string InsertSemi bool Prev []Token utils.Data // contains filtered or unexported fields }
func (*Token) LiteralRemoveLinePrefix ¶
type TokenHandler ¶
type TokenHandler func(t *Token)
type TokenHandlers ¶
type TokenHandlers []TokenHandler
func (*TokenHandlers) Remove ¶
func (th *TokenHandlers) Remove(h TokenHandler)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.