Documentation ¶
Index ¶
- Constants
- func Parse(ctx *Context) int
- type Argument
- func NewArgument(name Expression, assign *Token, value Expression) *Argument
- func NewKeywordVarArg(starStar *Token, value Expression) *Argument
- func NewKeywordVarParam(starStar *Token, name Expression) *Argument
- func NewPositionVarArg(star *Token, value Expression) *Argument
- func NewPositionVarParam(star *Token, name Expression) *Argument
- type ArgumentList
- type AssertStmt
- type BinaryExpr
- type BreakStmt
- type CallExpr
- type ClassDef
- type CollectionExpr
- type CollectionType
- type CommentsFormatting
- type ComprehensionExpr
- type ComprehensionType
- type ConditionClause
- type ConditionExpr
- type ConditionStmt
- type Context
- type ContinueStmt
- type Decorator
- type DelStmt
- type DotExpr
- type EvalExpr
- type ExecStmt
- type ExprList
- type ExprStmt
- type Expression
- type ForStmt
- type FromStmt
- type FuncDef
- type GlobalStmt
- type Identifier
- type ImportClause
- type ImportStmt
- type Iterator
- type LambdaExpr
- type Lexer
- type Location
- type LocationReader
- type Node
- type NodeInfo
- type None
- type Number
- type PassStmt
- type PrintStmt
- type RaiseStmt
- type ReturnStmt
- type Statement
- type String
- type Subscript
- type SubscriptExpr
- type Token
- type TokenExpr
- type TokenStmt
- type Tokenizer
- type TryStmt
- type UnaryExpr
- type WhileStmt
- type WithClause
- type WithStmt
- type YieldExpr
Constants ¶
const ( UnknownCollection = 0 TupleCollection = 1 ListCollection = 2 SetCollection = 3 DictCollection = 4 )
const ADD = 57389
const ADD_ASSIGN = 57390
const AND = 57355
const AND_ASSIGN = 57391
const AND_OP = 57392
const AS = 57356
const ASSERT = 57357
const ASSIGN = 57393
const AT = 57394
const BACK_QUOTE = 57395
const BREAK = 57358
const CLASS = 57359
const COLON = 57396
const COMMA = 57397
const COMMENT_NEWLINE = 57352
const CONTINUE = 57360
const DEDENT = 57354
const DEF = 57361
const DEL = 57362
const DIV = 57398
const DIV_ASSIGN = 57399
const DOT = 57400
const ELIF = 57363
const ELSE = 57364
const EQUALS = 57401
const EXCEPT = 57365
const EXEC = 57366
const FINALLY = 57367
const FLOAT = 57346
const FOR = 57368
const FROM = 57369
const GLOBAL = 57370
const GREATER_THAN = 57402
const GT_EQ = 57403
const IDIV = 57404
const IDIV_ASSIGN = 57405
const IF = 57371
const IMPORT = 57372
const IN = 57373
const INDENT = 57353
const INTEGER = 57347
const IS = 57374
const IS_NOT = 57388
const LAMBDA = 57375
const LEFT_BRACE = 57406
const LEFT_BRACKET = 57407
const LEFT_PARENTHESIS = 57408
const LEFT_SHIFT = 57409
const LEFT_SHIFT_ASSIGN = 57410
const LESS_THAN = 57411
const LINE_CONTINUATION = 57351
const LT_EQ = 57412
const MINUS = 57413
const MOD = 57414
const MOD_ASSIGN = 57415
const MULT_ASSIGN = 57416
const NAME = 57349
const NEWLINE = 57350
const NONE = 57376
const NOT = 57377
const NOT_EQUAL = 57417
const NOT_IN = 57387
const NOT_OP = 57418
const OR = 57378
const OR_ASSIGN = 57419
const OR_OP = 57420
const PASS = 57379
const POWER_ASSIGN = 57421
const PRINT = 57380
const RAISE = 57381
const RETURN = 57382
const RIGHT_BRACE = 57422
const RIGHT_BRACKET = 57423
const RIGHT_PARENTHESIS = 57424
const RIGHT_SHIFT = 57425
const RIGHT_SHIFT_ASSIGN = 57426
const SEMI_COLON = 57427
const STAR = 57428
const STAR_STAR = 57429
const STRING = 57348
const SUB_ASSIGN = 57430
const TRY = 57383
const WHILE = 57384
const WITH = 57385
const XOR = 57431
const XOR_ASSIGN = 57432
const YIELD = 57386
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Argument ¶
type Argument struct { Node // Optional when used by CallExpr Name Expression // Optional when used by FuncDef / LambdaExpr Value Expression PositionVarArg bool // '*' KeywordVarArg bool // '**' }
func NewArgument ¶
func NewArgument(name Expression, assign *Token, value Expression) *Argument
func NewKeywordVarArg ¶
func NewKeywordVarArg(starStar *Token, value Expression) *Argument
**kwarg in the context of invocation.
func NewKeywordVarParam ¶
func NewKeywordVarParam(starStar *Token, name Expression) *Argument
**kwarg in the context of defintions.
func NewPositionVarArg ¶
func NewPositionVarArg(star *Token, value Expression) *Argument
*arg in the context of invocation.
func NewPositionVarParam ¶
func NewPositionVarParam(star *Token, name Expression) *Argument
*arg in the context of definitions.
type ArgumentList ¶
intermediate node. does not appear in parsed tree.
func NewArgumentList ¶
func NewArgumentList( leftParen *Token, args []*Argument, rightParen *Token) *ArgumentList
type AssertStmt ¶
type AssertStmt struct { Expr Expression Debug Expression // Optional // contains filtered or unexported fields }
func (AssertStmt) IsStatement ¶
func (AssertStmt) IsStatement()
func (*AssertStmt) String ¶
func (a *AssertStmt) String() string
type BinaryExpr ¶
type BinaryExpr struct { Left Expression Op string Right Expression // contains filtered or unexported fields }
func NewBinaryExpr ¶
func NewBinaryExpr(lhs Expression, op *Token, rhs Expression) *BinaryExpr
func (BinaryExpr) IsExpression ¶
func (BinaryExpr) IsExpression()
func (*BinaryExpr) String ¶
func (b *BinaryExpr) String() string
type BreakStmt ¶
type BreakStmt struct {
TokenStmt
}
func NewBreakStmt ¶
func (BreakStmt) IsStatement ¶
func (BreakStmt) IsStatement()
type CallExpr ¶
type CallExpr struct { Method Expression Arguments []*Argument // contains filtered or unexported fields }
<method>(<args>)
func NewCallExpr ¶
func NewCallExpr(method Expression, args *ArgumentList) *CallExpr
func (CallExpr) IsExpression ¶
func (CallExpr) IsExpression()
type ClassDef ¶
type ClassDef struct { Decorators []*Decorator Name *Token ParentClasses []Expression Statements []Statement // contains filtered or unexported fields }
TODO doc string ...
func (ClassDef) IsStatement ¶
func (ClassDef) IsStatement()
func (*ClassDef) SetDecorators ¶
type CollectionExpr ¶
type CollectionExpr struct { Type CollectionType Items []Expression // contains filtered or unexported fields }
func (CollectionExpr) IsExpression ¶
func (CollectionExpr) IsExpression()
func (*CollectionExpr) String ¶
func (c *CollectionExpr) String() string
type CollectionType ¶
type CollectionType int
type CommentsFormatting ¶
type CommentsFormatting struct { // Same idea as go's comment map: // A comment group g is associated with a node n if: // - g starts on the same line as n ends // - g starts on the line immediately following n, and there is // at least one empty line after g and before the next node // - g starts before n and is not associated to the node before n // via the previous rules LeadingCommentGroups [][]string TrailingCommentGroups [][]string TrailingNewLine bool TrailingLineContinuation bool }
type ComprehensionExpr ¶
type ComprehensionExpr struct { Type ComprehensionType Key Expression // Set by dict / set comprehension Value Expression // Set by list / generator / dict comprehension Iterators []*Iterator // contains filtered or unexported fields }
func (ComprehensionExpr) IsExpression ¶
func (ComprehensionExpr) IsExpression()
func (*ComprehensionExpr) String ¶
func (c *ComprehensionExpr) String() string
type ComprehensionType ¶
type ComprehensionType int
const ( UnknownComprehension = 0 GeneratorComprehension ComprehensionType = 1 ListComprehension ComprehensionType = 2 SetComprehension ComprehensionType = 3 DictComprehension ComprehensionType = 4 )
type ConditionClause ¶
type ConditionClause struct { // predicate for if/while stmt, exceptions for except clauses. // nil Matches in except clause means unconditional matching. Matches Expression Alias Expression // Optional. Only used by except clauses Branch []Statement }
func (*ConditionClause) String ¶
func (c *ConditionClause) String() string
type ConditionExpr ¶
type ConditionExpr struct { Predicate Expression True Expression False Expression // contains filtered or unexported fields }
func (ConditionExpr) IsExpression ¶
func (ConditionExpr) IsExpression()
func (*ConditionExpr) String ¶
func (c *ConditionExpr) String() string
type ConditionStmt ¶
type ConditionStmt struct { If *ConditionClause Elif []*ConditionClause // Optional Else []Statement // Optional // contains filtered or unexported fields }
func (ConditionStmt) IsStatement ¶
func (ConditionStmt) IsStatement()
func (*ConditionStmt) String ¶
func (c *ConditionStmt) String() string
type Context ¶
type Context struct { Statements []Statement ParseError error // contains filtered or unexported fields }
func NewContext ¶
NOTE: lex errors are returned immediately.
func (*Context) PrintTokens ¶
func (c *Context) PrintTokens()
type ContinueStmt ¶
type ContinueStmt struct {
TokenStmt
}
func NewContinueStmt ¶
func NewContinueStmt(t *Token) *ContinueStmt
func (ContinueStmt) IsStatement ¶
func (ContinueStmt) IsStatement()
type Decorator ¶
type Decorator struct {
Expression
}
Decorator is a pseudo-Expression
func NewDecorator ¶
func NewDecorator(at *Token, expr Expression, newline *Token) *Decorator
type DelStmt ¶
type DelStmt struct { List []Expression // contains filtered or unexported fields }
func NewDelStmt ¶
func (DelStmt) IsStatement ¶
func (DelStmt) IsStatement()
type DotExpr ¶
type DotExpr struct { Parent Expression Field *Token // contains filtered or unexported fields }
<parent>.<field>
func (DotExpr) IsExpression ¶
func (DotExpr) IsExpression()
type EvalExpr ¶
type EvalExpr struct {
Expression
}
type ExecStmt ¶
type ExecStmt struct { Expr Expression Global Expression Local Expression // contains filtered or unexported fields }
func (ExecStmt) IsStatement ¶
func (ExecStmt) IsStatement()
type ExprList ¶
type ExprList struct { Expressions []Expression ExplicitCollection bool }
Intermediate node. Do not appear in the parsed tree. there are many ways to interpret exprlist / testlist / etc =...( (i) and (i,) have different meanings
func NewExprList ¶
func NewExprList(list []Expression) *ExprList
func (*ExprList) ConvertToExpr ¶
func (e *ExprList) ConvertToExpr() Expression
type ExprStmt ¶
type ExprStmt struct { Expression // contains filtered or unexported fields }
func NewExprStmt ¶
func NewExprStmt(expr Expression) *ExprStmt
func (ExprStmt) IsStatement ¶
func (ExprStmt) IsStatement()
type Expression ¶
type Expression interface { NodeInfo IsExpression() }
func DottedNameToExpr ¶
func DottedNameToExpr(names []*Token) Expression
func NewExpressionFromTrailers ¶
func NewExpressionFromTrailers( atom Expression, trailers []interface{}) Expression
func NewFactorExpr ¶
func NewFactorExpr(factorSigns []*Token, expr Expression) Expression
type ForStmt ¶
type ForStmt struct { Iterator *Iterator Loop []Statement Else []Statement // Optional // contains filtered or unexported fields }
func (ForStmt) IsStatement ¶
func (ForStmt) IsStatement()
type FromStmt ¶
type FromStmt struct { DotPrefixCount int ModulePath []*Token // Empty list implies "import *" Imports []*ImportClause // contains filtered or unexported fields }
func (FromStmt) IsStatement ¶
func (FromStmt) IsStatement()
type FuncDef ¶
type FuncDef struct { Decorators []*Decorator Name string Arguments []*Argument Statements []Statement // contains filtered or unexported fields }
TODO doc string ...
func NewFuncDef ¶
func (FuncDef) IsStatement ¶
func (FuncDef) IsStatement()
func (*FuncDef) SetDecorators ¶
type GlobalStmt ¶
type GlobalStmt struct { Names []*Token // contains filtered or unexported fields }
func (GlobalStmt) IsStatement ¶
func (GlobalStmt) IsStatement()
func (*GlobalStmt) String ¶
func (g *GlobalStmt) String() string
type Identifier ¶
type Identifier struct {
TokenExpr
}
func NewIdentifier ¶
func NewIdentifier(t *Token) *Identifier
func (Identifier) IsExpression ¶
func (Identifier) IsExpression()
type ImportClause ¶
func (*ImportClause) String ¶
func (i *ImportClause) String() string
type ImportStmt ¶
type ImportStmt struct { ModulePath []*Token Alias *Token // Optional // contains filtered or unexported fields }
func (ImportStmt) IsStatement ¶
func (ImportStmt) IsStatement()
func (*ImportStmt) String ¶
func (i *ImportStmt) String() string
type Iterator ¶
type Iterator struct { Node BoundVariables Expression Source Expression Filters []Expression // Optional }
Used by both for loops and comprehensions for <binded variables> in <source> if <filter>
type LambdaExpr ¶
type LambdaExpr struct { Arguments []*Argument Value Expression // contains filtered or unexported fields }
func (LambdaExpr) IsExpression ¶
func (LambdaExpr) IsExpression()
func (*LambdaExpr) String ¶
func (l *LambdaExpr) String() string
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
A "look ahead" lexer which handles line continuation, transforms ';' to newlines to simply parsing, and groups comments.
func (*Lexer) PrintTokens ¶
func (l *Lexer) PrintTokens()
type LocationReader ¶
type LocationReader struct { Location // contains filtered or unexported fields }
Not efficient, but probably good enough
func NewLocationReader ¶
func NewLocationReader(fileName string, reader io.Reader) *LocationReader
func (*LocationReader) ReadByte ¶
func (r *LocationReader) ReadByte() (byte, error)
func (*LocationReader) ReadString ¶
func (r *LocationReader) ReadString(delim byte) (string, error)
type Node ¶
type Node struct { Location CommentsFormatting }
func (*Node) MergeLeadingFrom ¶
func (*Node) MergeTrailingFrom ¶
type NodeInfo ¶
type NodeInfo interface { String() string NodeInfo() *Node // contains filtered or unexported methods }
TODO: Add Loc, comment, extra
type Number ¶
type Number struct {
TokenExpr
}
func (Number) IsExpression ¶
func (Number) IsExpression()
type PassStmt ¶
type PassStmt struct { // newlines and comment blocks are implicitly pass statments IsImplicit bool // contains filtered or unexported fields }
func NewPassStmt ¶
func (PassStmt) IsStatement ¶
func (PassStmt) IsStatement()
type PrintStmt ¶
type PrintStmt struct { Output Expression // Optional Values []Expression // Optional LineContinuation bool // contains filtered or unexported fields }
func NewPrintStmt ¶
func NewPrintStmt( prnt *Token, shift *Token, out Expression, values *ExprList) *PrintStmt
func (PrintStmt) IsStatement ¶
func (PrintStmt) IsStatement()
type RaiseStmt ¶
type RaiseStmt struct { First Expression Second Expression Third Expression // contains filtered or unexported fields }
func NewRaiseStmt ¶
func NewRaiseStmt( r *Token, first Expression, comma1 *Token, second Expression, comma2 *Token, third Expression) *RaiseStmt
func (RaiseStmt) IsStatement ¶
func (RaiseStmt) IsStatement()
type ReturnStmt ¶
type ReturnStmt struct { Value Expression // contains filtered or unexported fields }
func NewReturnStmt ¶
func NewReturnStmt(ret *Token, value Expression) *ReturnStmt
func (ReturnStmt) IsStatement ¶
func (ReturnStmt) IsStatement()
func (*ReturnStmt) String ¶
func (r *ReturnStmt) String() string
type String ¶
type String struct { Pieces []*Token // contains filtered or unexported fields }
func (String) IsExpression ¶
func (String) IsExpression()
type Subscript ¶
type Subscript struct { // dot dot dot Ellipsis bool // When true, Index/Left/Middle/Right must be nil // Exact index. Index Expression // <left>:<middle>:<right> Left Expression Middle Expression Right Expression }
This is a "union" of Ellipsis, Index, and (Left:Middle:Right)
type SubscriptExpr ¶
type SubscriptExpr struct { Source Expression Subscripts []*Subscript // contains filtered or unexported fields }
func (SubscriptExpr) IsExpression ¶
func (SubscriptExpr) IsExpression()
func (*SubscriptExpr) String ¶
func (s *SubscriptExpr) String() string
type TokenExpr ¶
Base type for None, Number, and Identifer.
func NewTokenExpr ¶
func (TokenExpr) IsExpression ¶
func (TokenExpr) IsExpression()
type TokenStmt ¶
type TokenStmt struct { DebugType string // contains filtered or unexported fields }
Base type for break & continue
func NewTokenStmt ¶
func (TokenStmt) IsStatement ¶
func (TokenStmt) IsStatement()
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
func (*Tokenizer) CurrentLocation ¶
type TryStmt ¶
type TryStmt struct { Try []Statement Except []*ConditionClause // Optional Else []Statement // Optional Finally []Statement // Optional // contains filtered or unexported fields }
func (TryStmt) IsStatement ¶
func (TryStmt) IsStatement()
type UnaryExpr ¶
type UnaryExpr struct { Op *Token Value Expression // contains filtered or unexported fields }
func (UnaryExpr) IsExpression ¶
func (UnaryExpr) IsExpression()
type WhileStmt ¶
type WhileStmt struct { Loop *ConditionClause Else []Statement // Optional // contains filtered or unexported fields }
func (WhileStmt) IsStatement ¶
func (WhileStmt) IsStatement()
type WithClause ¶
type WithClause struct { Value Expression BoundVariable Expression }
func (*WithClause) String ¶
func (w *WithClause) String() string
type WithStmt ¶
type WithStmt struct { WithClauses []*WithClause Statements []Statement // contains filtered or unexported fields }
func (WithStmt) IsStatement ¶
func (WithStmt) IsStatement()