diff options
author | Wim <wim@42.be> | 2019-02-23 16:39:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-23 16:39:44 +0100 |
commit | 1bb39eba8717f62336cc98c5bb7cfbef194f3626 (patch) | |
tree | 0437ae89473b8e25ad1c9597e1049a23a7933f6a /vendor/github.com/d5/tengo/compiler/ast | |
parent | 3190703dc8618896c932a23d8ca155fbbf6fab13 (diff) | |
download | matterbridge-msglm-1bb39eba8717f62336cc98c5bb7cfbef194f3626.tar.gz matterbridge-msglm-1bb39eba8717f62336cc98c5bb7cfbef194f3626.tar.bz2 matterbridge-msglm-1bb39eba8717f62336cc98c5bb7cfbef194f3626.zip |
Add scripting (tengo) support for every incoming message (#731)
TengoModifyMessage allows you to specify the location of a tengo (https://github.com/d5/tengo/) script.
This script will receive every incoming message and can be used to modify the Username and the Text of that message.
The script will have the following global variables:
to modify: msgUsername and msgText
to read: msgChannel and msgAccount
The script is reloaded on every message, so you can modify the script on the fly.
Example script can be found in https://github.com/42wim/matterbridge/tree/master/gateway/bench.tengo
and https://github.com/42wim/matterbridge/tree/master/contrib/example.tengo
The example below will check if the text contains blah and if so, it'll replace the text and the username of that message.
text := import("text")
if text.re_match("blah",msgText) {
msgText="replaced by this"
msgUsername="fakeuser"
}
More information about tengo on: https://github.com/d5/tengo/blob/master/docs/tutorial.md and
https://github.com/d5/tengo/blob/master/docs/stdlib.md
Diffstat (limited to 'vendor/github.com/d5/tengo/compiler/ast')
42 files changed, 1205 insertions, 0 deletions
diff --git a/vendor/github.com/d5/tengo/compiler/ast/array_lit.go b/vendor/github.com/d5/tengo/compiler/ast/array_lit.go new file mode 100644 index 00000000..9fb4ed67 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/array_lit.go @@ -0,0 +1,35 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// ArrayLit represents an array literal. +type ArrayLit struct { + Elements []Expr + LBrack source.Pos + RBrack source.Pos +} + +func (e *ArrayLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *ArrayLit) Pos() source.Pos { + return e.LBrack +} + +// End returns the position of first character immediately after the node. +func (e *ArrayLit) End() source.Pos { + return e.RBrack + 1 +} + +func (e *ArrayLit) String() string { + var elements []string + for _, m := range e.Elements { + elements = append(elements, m.String()) + } + + return "[" + strings.Join(elements, ", ") + "]" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/assign_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/assign_stmt.go new file mode 100644 index 00000000..e129114e --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/assign_stmt.go @@ -0,0 +1,40 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// AssignStmt represents an assignment statement. +type AssignStmt struct { + LHS []Expr + RHS []Expr + Token token.Token + TokenPos source.Pos +} + +func (s *AssignStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *AssignStmt) Pos() source.Pos { + return s.LHS[0].Pos() +} + +// End returns the position of first character immediately after the node. +func (s *AssignStmt) End() source.Pos { + return s.RHS[len(s.RHS)-1].End() +} + +func (s *AssignStmt) String() string { + var lhs, rhs []string + for _, e := range s.LHS { + lhs = append(lhs, e.String()) + } + for _, e := range s.RHS { + rhs = append(rhs, e.String()) + } + + return strings.Join(lhs, ", ") + " " + s.Token.String() + " " + strings.Join(rhs, ", ") +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/ast.go b/vendor/github.com/d5/tengo/compiler/ast/ast.go new file mode 100644 index 00000000..9fd06728 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/ast.go @@ -0,0 +1,5 @@ +package ast + +const ( + nullRep = "<null>" +) diff --git a/vendor/github.com/d5/tengo/compiler/ast/bad_expr.go b/vendor/github.com/d5/tengo/compiler/ast/bad_expr.go new file mode 100644 index 00000000..771f26fd --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/bad_expr.go @@ -0,0 +1,25 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// BadExpr represents a bad expression. +type BadExpr struct { + From source.Pos + To source.Pos +} + +func (e *BadExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *BadExpr) Pos() source.Pos { + return e.From +} + +// End returns the position of first character immediately after the node. +func (e *BadExpr) End() source.Pos { + return e.To +} + +func (e *BadExpr) String() string { + return "<bad expression>" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/bad_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/bad_stmt.go new file mode 100644 index 00000000..c2d0ae9a --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/bad_stmt.go @@ -0,0 +1,25 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// BadStmt represents a bad statement. +type BadStmt struct { + From source.Pos + To source.Pos +} + +func (s *BadStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *BadStmt) Pos() source.Pos { + return s.From +} + +// End returns the position of first character immediately after the node. +func (s *BadStmt) End() source.Pos { + return s.To +} + +func (s *BadStmt) String() string { + return "<bad statement>" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/binary_expr.go b/vendor/github.com/d5/tengo/compiler/ast/binary_expr.go new file mode 100644 index 00000000..0cc5bba8 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/binary_expr.go @@ -0,0 +1,30 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// BinaryExpr represents a binary operator expression. +type BinaryExpr struct { + LHS Expr + RHS Expr + Token token.Token + TokenPos source.Pos +} + +func (e *BinaryExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *BinaryExpr) Pos() source.Pos { + return e.LHS.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *BinaryExpr) End() source.Pos { + return e.RHS.End() +} + +func (e *BinaryExpr) String() string { + return "(" + e.LHS.String() + " " + e.Token.String() + " " + e.RHS.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/block_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/block_stmt.go new file mode 100644 index 00000000..9bde9fa3 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/block_stmt.go @@ -0,0 +1,35 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// BlockStmt represents a block statement. +type BlockStmt struct { + Stmts []Stmt + LBrace source.Pos + RBrace source.Pos +} + +func (s *BlockStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *BlockStmt) Pos() source.Pos { + return s.LBrace +} + +// End returns the position of first character immediately after the node. +func (s *BlockStmt) End() source.Pos { + return s.RBrace + 1 +} + +func (s *BlockStmt) String() string { + var list []string + for _, e := range s.Stmts { + list = append(list, e.String()) + } + + return "{" + strings.Join(list, "; ") + "}" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/bool_lit.go b/vendor/github.com/d5/tengo/compiler/ast/bool_lit.go new file mode 100644 index 00000000..e667a5c8 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/bool_lit.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// BoolLit represents a boolean literal. +type BoolLit struct { + Value bool + ValuePos source.Pos + Literal string +} + +func (e *BoolLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *BoolLit) Pos() source.Pos { + return e.ValuePos +} + +// End returns the position of first character immediately after the node. +func (e *BoolLit) End() source.Pos { + return source.Pos(int(e.ValuePos) + len(e.Literal)) +} + +func (e *BoolLit) String() string { + return e.Literal +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/branch_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/branch_stmt.go new file mode 100644 index 00000000..f6c7fdea --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/branch_stmt.go @@ -0,0 +1,38 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// BranchStmt represents a branch statement. +type BranchStmt struct { + Token token.Token + TokenPos source.Pos + Label *Ident +} + +func (s *BranchStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *BranchStmt) Pos() source.Pos { + return s.TokenPos +} + +// End returns the position of first character immediately after the node. +func (s *BranchStmt) End() source.Pos { + if s.Label != nil { + return s.Label.End() + } + + return source.Pos(int(s.TokenPos) + len(s.Token.String())) +} + +func (s *BranchStmt) String() string { + var label string + if s.Label != nil { + label = " " + s.Label.Name + } + + return s.Token.String() + label +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/call_expr.go b/vendor/github.com/d5/tengo/compiler/ast/call_expr.go new file mode 100644 index 00000000..0219d7c9 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/call_expr.go @@ -0,0 +1,36 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// CallExpr represents a function call expression. +type CallExpr struct { + Func Expr + LParen source.Pos + Args []Expr + RParen source.Pos +} + +func (e *CallExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *CallExpr) Pos() source.Pos { + return e.Func.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *CallExpr) End() source.Pos { + return e.RParen + 1 +} + +func (e *CallExpr) String() string { + var args []string + for _, e := range e.Args { + args = append(args, e.String()) + } + + return e.Func.String() + "(" + strings.Join(args, ", ") + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/char_lit.go b/vendor/github.com/d5/tengo/compiler/ast/char_lit.go new file mode 100644 index 00000000..592f8744 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/char_lit.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// CharLit represents a character literal. +type CharLit struct { + Value rune + ValuePos source.Pos + Literal string +} + +func (e *CharLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *CharLit) Pos() source.Pos { + return e.ValuePos +} + +// End returns the position of first character immediately after the node. +func (e *CharLit) End() source.Pos { + return source.Pos(int(e.ValuePos) + len(e.Literal)) +} + +func (e *CharLit) String() string { + return e.Literal +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/cond_expr.go b/vendor/github.com/d5/tengo/compiler/ast/cond_expr.go new file mode 100644 index 00000000..bb1db849 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/cond_expr.go @@ -0,0 +1,30 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" +) + +// CondExpr represents a ternary conditional expression. +type CondExpr struct { + Cond Expr + True Expr + False Expr + QuestionPos source.Pos + ColonPos source.Pos +} + +func (e *CondExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *CondExpr) Pos() source.Pos { + return e.Cond.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *CondExpr) End() source.Pos { + return e.False.End() +} + +func (e *CondExpr) String() string { + return "(" + e.Cond.String() + " ? " + e.True.String() + " : " + e.False.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/empty_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/empty_stmt.go new file mode 100644 index 00000000..a2ac6ffe --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/empty_stmt.go @@ -0,0 +1,29 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// EmptyStmt represents an empty statement. +type EmptyStmt struct { + Semicolon source.Pos + Implicit bool +} + +func (s *EmptyStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *EmptyStmt) Pos() source.Pos { + return s.Semicolon +} + +// End returns the position of first character immediately after the node. +func (s *EmptyStmt) End() source.Pos { + if s.Implicit { + return s.Semicolon + } + + return s.Semicolon + 1 +} + +func (s *EmptyStmt) String() string { + return ";" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/error_expr.go b/vendor/github.com/d5/tengo/compiler/ast/error_expr.go new file mode 100644 index 00000000..7ce5667e --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/error_expr.go @@ -0,0 +1,29 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" +) + +// ErrorExpr represents an error expression +type ErrorExpr struct { + Expr Expr + ErrorPos source.Pos + LParen source.Pos + RParen source.Pos +} + +func (e *ErrorExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *ErrorExpr) Pos() source.Pos { + return e.ErrorPos +} + +// End returns the position of first character immediately after the node. +func (e *ErrorExpr) End() source.Pos { + return e.RParen +} + +func (e *ErrorExpr) String() string { + return "error(" + e.Expr.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/export_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/export_stmt.go new file mode 100644 index 00000000..64eb7606 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/export_stmt.go @@ -0,0 +1,27 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" +) + +// ExportStmt represents an export statement. +type ExportStmt struct { + ExportPos source.Pos + Result Expr +} + +func (s *ExportStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *ExportStmt) Pos() source.Pos { + return s.ExportPos +} + +// End returns the position of first character immediately after the node. +func (s *ExportStmt) End() source.Pos { + return s.Result.End() +} + +func (s *ExportStmt) String() string { + return "export " + s.Result.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/expr.go b/vendor/github.com/d5/tengo/compiler/ast/expr.go new file mode 100644 index 00000000..764bacec --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/expr.go @@ -0,0 +1,7 @@ +package ast + +// Expr represents an expression node in the AST. +type Expr interface { + Node + exprNode() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/expr_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/expr_stmt.go new file mode 100644 index 00000000..095a3ad5 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/expr_stmt.go @@ -0,0 +1,24 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// ExprStmt represents an expression statement. +type ExprStmt struct { + Expr Expr +} + +func (s *ExprStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *ExprStmt) Pos() source.Pos { + return s.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (s *ExprStmt) End() source.Pos { + return s.Expr.End() +} + +func (s *ExprStmt) String() string { + return s.Expr.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/file.go b/vendor/github.com/d5/tengo/compiler/ast/file.go new file mode 100644 index 00000000..fc18b2d7 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/file.go @@ -0,0 +1,32 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// File represents a file unit. +type File struct { + InputFile *source.File + Stmts []Stmt +} + +// Pos returns the position of first character belonging to the node. +func (n *File) Pos() source.Pos { + return source.Pos(n.InputFile.Base) +} + +// End returns the position of first character immediately after the node. +func (n *File) End() source.Pos { + return source.Pos(n.InputFile.Base + n.InputFile.Size) +} + +func (n *File) String() string { + var stmts []string + for _, e := range n.Stmts { + stmts = append(stmts, e.String()) + } + + return strings.Join(stmts, "; ") +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/float_lit.go b/vendor/github.com/d5/tengo/compiler/ast/float_lit.go new file mode 100644 index 00000000..670f744b --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/float_lit.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// FloatLit represents a floating point literal. +type FloatLit struct { + Value float64 + ValuePos source.Pos + Literal string +} + +func (e *FloatLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *FloatLit) Pos() source.Pos { + return e.ValuePos +} + +// End returns the position of first character immediately after the node. +func (e *FloatLit) End() source.Pos { + return source.Pos(int(e.ValuePos) + len(e.Literal)) +} + +func (e *FloatLit) String() string { + return e.Literal +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/for_in_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/for_in_stmt.go new file mode 100644 index 00000000..18020b56 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/for_in_stmt.go @@ -0,0 +1,32 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// ForInStmt represents a for-in statement. +type ForInStmt struct { + ForPos source.Pos + Key *Ident + Value *Ident + Iterable Expr + Body *BlockStmt +} + +func (s *ForInStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *ForInStmt) Pos() source.Pos { + return s.ForPos +} + +// End returns the position of first character immediately after the node. +func (s *ForInStmt) End() source.Pos { + return s.Body.End() +} + +func (s *ForInStmt) String() string { + if s.Value != nil { + return "for " + s.Key.String() + ", " + s.Value.String() + " in " + s.Iterable.String() + " " + s.Body.String() + } + + return "for " + s.Key.String() + " in " + s.Iterable.String() + " " + s.Body.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/for_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/for_stmt.go new file mode 100644 index 00000000..4b5a0a17 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/for_stmt.go @@ -0,0 +1,43 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// ForStmt represents a for statement. +type ForStmt struct { + ForPos source.Pos + Init Stmt + Cond Expr + Post Stmt + Body *BlockStmt +} + +func (s *ForStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *ForStmt) Pos() source.Pos { + return s.ForPos +} + +// End returns the position of first character immediately after the node. +func (s *ForStmt) End() source.Pos { + return s.Body.End() +} + +func (s *ForStmt) String() string { + var init, cond, post string + if s.Init != nil { + init = s.Init.String() + } + if s.Cond != nil { + cond = s.Cond.String() + " " + } + if s.Post != nil { + post = s.Post.String() + } + + if init != "" || post != "" { + return "for " + init + " ; " + cond + " ; " + post + s.Body.String() + } + + return "for " + cond + s.Body.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/func_lit.go b/vendor/github.com/d5/tengo/compiler/ast/func_lit.go new file mode 100644 index 00000000..2e90ed2b --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/func_lit.go @@ -0,0 +1,25 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// FuncLit represents a function literal. +type FuncLit struct { + Type *FuncType + Body *BlockStmt +} + +func (e *FuncLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *FuncLit) Pos() source.Pos { + return e.Type.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *FuncLit) End() source.Pos { + return e.Body.End() +} + +func (e *FuncLit) String() string { + return "func" + e.Type.Params.String() + " " + e.Body.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/func_type.go b/vendor/github.com/d5/tengo/compiler/ast/func_type.go new file mode 100644 index 00000000..2afaabb1 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/func_type.go @@ -0,0 +1,25 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// FuncType represents a function type definition. +type FuncType struct { + FuncPos source.Pos + Params *IdentList +} + +func (e *FuncType) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *FuncType) Pos() source.Pos { + return e.FuncPos +} + +// End returns the position of first character immediately after the node. +func (e *FuncType) End() source.Pos { + return e.Params.End() +} + +func (e *FuncType) String() string { + return "func" + e.Params.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/ident.go b/vendor/github.com/d5/tengo/compiler/ast/ident.go new file mode 100644 index 00000000..33b7ff76 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/ident.go @@ -0,0 +1,29 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// Ident represents an identifier. +type Ident struct { + Name string + NamePos source.Pos +} + +func (e *Ident) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *Ident) Pos() source.Pos { + return e.NamePos +} + +// End returns the position of first character immediately after the node. +func (e *Ident) End() source.Pos { + return source.Pos(int(e.NamePos) + len(e.Name)) +} + +func (e *Ident) String() string { + if e != nil { + return e.Name + } + + return nullRep +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/ident_list.go b/vendor/github.com/d5/tengo/compiler/ast/ident_list.go new file mode 100644 index 00000000..ee8f7db2 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/ident_list.go @@ -0,0 +1,58 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// IdentList represents a list of identifiers. +type IdentList struct { + LParen source.Pos + List []*Ident + RParen source.Pos +} + +// Pos returns the position of first character belonging to the node. +func (n *IdentList) Pos() source.Pos { + if n.LParen.IsValid() { + return n.LParen + } + + if len(n.List) > 0 { + return n.List[0].Pos() + } + + return source.NoPos +} + +// End returns the position of first character immediately after the node. +func (n *IdentList) End() source.Pos { + if n.RParen.IsValid() { + return n.RParen + 1 + } + + if l := len(n.List); l > 0 { + return n.List[l-1].End() + } + + return source.NoPos +} + +// NumFields returns the number of fields. +func (n *IdentList) NumFields() int { + if n == nil { + return 0 + } + + return len(n.List) +} + +func (n *IdentList) String() string { + var list []string + for _, e := range n.List { + list = append(list, e.String()) + } + + return "(" + strings.Join(list, ", ") + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/if_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/if_stmt.go new file mode 100644 index 00000000..b3d65606 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/if_stmt.go @@ -0,0 +1,40 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// IfStmt represents an if statement. +type IfStmt struct { + IfPos source.Pos + Init Stmt + Cond Expr + Body *BlockStmt + Else Stmt // else branch; or nil +} + +func (s *IfStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *IfStmt) Pos() source.Pos { + return s.IfPos +} + +// End returns the position of first character immediately after the node. +func (s *IfStmt) End() source.Pos { + if s.Else != nil { + return s.Else.End() + } + + return s.Body.End() +} + +func (s *IfStmt) String() string { + var initStmt, elseStmt string + if s.Init != nil { + initStmt = s.Init.String() + "; " + } + if s.Else != nil { + elseStmt = " else " + s.Else.String() + } + + return "if " + initStmt + s.Cond.String() + " " + s.Body.String() + elseStmt +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/immutable_expr.go b/vendor/github.com/d5/tengo/compiler/ast/immutable_expr.go new file mode 100644 index 00000000..f9843b50 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/immutable_expr.go @@ -0,0 +1,29 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" +) + +// ImmutableExpr represents an immutable expression +type ImmutableExpr struct { + Expr Expr + ErrorPos source.Pos + LParen source.Pos + RParen source.Pos +} + +func (e *ImmutableExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *ImmutableExpr) Pos() source.Pos { + return e.ErrorPos +} + +// End returns the position of first character immediately after the node. +func (e *ImmutableExpr) End() source.Pos { + return e.RParen +} + +func (e *ImmutableExpr) String() string { + return "immutable(" + e.Expr.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/import_expr.go b/vendor/github.com/d5/tengo/compiler/ast/import_expr.go new file mode 100644 index 00000000..6eff74a9 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/import_expr.go @@ -0,0 +1,29 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// ImportExpr represents an import expression +type ImportExpr struct { + ModuleName string + Token token.Token + TokenPos source.Pos +} + +func (e *ImportExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *ImportExpr) Pos() source.Pos { + return e.TokenPos +} + +// End returns the position of first character immediately after the node. +func (e *ImportExpr) End() source.Pos { + return source.Pos(int(e.TokenPos) + 10 + len(e.ModuleName)) // import("moduleName") +} + +func (e *ImportExpr) String() string { + return `import("` + e.ModuleName + `")"` +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/inc_dec_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/inc_dec_stmt.go new file mode 100644 index 00000000..e4e7f92c --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/inc_dec_stmt.go @@ -0,0 +1,29 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// IncDecStmt represents increment or decrement statement. +type IncDecStmt struct { + Expr Expr + Token token.Token + TokenPos source.Pos +} + +func (s *IncDecStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *IncDecStmt) Pos() source.Pos { + return s.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (s *IncDecStmt) End() source.Pos { + return source.Pos(int(s.TokenPos) + 2) +} + +func (s *IncDecStmt) String() string { + return s.Expr.String() + s.Token.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/index_expr.go b/vendor/github.com/d5/tengo/compiler/ast/index_expr.go new file mode 100644 index 00000000..bc0992a3 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/index_expr.go @@ -0,0 +1,32 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// IndexExpr represents an index expression. +type IndexExpr struct { + Expr Expr + LBrack source.Pos + Index Expr + RBrack source.Pos +} + +func (e *IndexExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *IndexExpr) Pos() source.Pos { + return e.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *IndexExpr) End() source.Pos { + return e.RBrack + 1 +} + +func (e *IndexExpr) String() string { + var index string + if e.Index != nil { + index = e.Index.String() + } + + return e.Expr.String() + "[" + index + "]" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/int_lit.go b/vendor/github.com/d5/tengo/compiler/ast/int_lit.go new file mode 100644 index 00000000..3e1fd98b --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/int_lit.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// IntLit represents an integer literal. +type IntLit struct { + Value int64 + ValuePos source.Pos + Literal string +} + +func (e *IntLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *IntLit) Pos() source.Pos { + return e.ValuePos +} + +// End returns the position of first character immediately after the node. +func (e *IntLit) End() source.Pos { + return source.Pos(int(e.ValuePos) + len(e.Literal)) +} + +func (e *IntLit) String() string { + return e.Literal +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/map_element_lit.go b/vendor/github.com/d5/tengo/compiler/ast/map_element_lit.go new file mode 100644 index 00000000..3d7fca9e --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/map_element_lit.go @@ -0,0 +1,27 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// MapElementLit represents a map element. +type MapElementLit struct { + Key string + KeyPos source.Pos + ColonPos source.Pos + Value Expr +} + +func (e *MapElementLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *MapElementLit) Pos() source.Pos { + return e.KeyPos +} + +// End returns the position of first character immediately after the node. +func (e *MapElementLit) End() source.Pos { + return e.Value.End() +} + +func (e *MapElementLit) String() string { + return e.Key + ": " + e.Value.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/map_lit.go b/vendor/github.com/d5/tengo/compiler/ast/map_lit.go new file mode 100644 index 00000000..a228224d --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/map_lit.go @@ -0,0 +1,35 @@ +package ast + +import ( + "strings" + + "github.com/d5/tengo/compiler/source" +) + +// MapLit represents a map literal. +type MapLit struct { + LBrace source.Pos + Elements []*MapElementLit + RBrace source.Pos +} + +func (e *MapLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *MapLit) Pos() source.Pos { + return e.LBrace +} + +// End returns the position of first character immediately after the node. +func (e *MapLit) End() source.Pos { + return e.RBrace + 1 +} + +func (e *MapLit) String() string { + var elements []string + for _, m := range e.Elements { + elements = append(elements, m.String()) + } + + return "{" + strings.Join(elements, ", ") + "}" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/node.go b/vendor/github.com/d5/tengo/compiler/ast/node.go new file mode 100644 index 00000000..44677b47 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/node.go @@ -0,0 +1,13 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// Node represents a node in the AST. +type Node interface { + // Pos returns the position of first character belonging to the node. + Pos() source.Pos + // End returns the position of first character immediately after the node. + End() source.Pos + // String returns a string representation of the node. + String() string +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/paren_expr.go b/vendor/github.com/d5/tengo/compiler/ast/paren_expr.go new file mode 100644 index 00000000..8db4ac02 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/paren_expr.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// ParenExpr represents a parenthesis wrapped expression. +type ParenExpr struct { + Expr Expr + LParen source.Pos + RParen source.Pos +} + +func (e *ParenExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *ParenExpr) Pos() source.Pos { + return e.LParen +} + +// End returns the position of first character immediately after the node. +func (e *ParenExpr) End() source.Pos { + return e.RParen + 1 +} + +func (e *ParenExpr) String() string { + return "(" + e.Expr.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/return_stmt.go b/vendor/github.com/d5/tengo/compiler/ast/return_stmt.go new file mode 100644 index 00000000..592d45b8 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/return_stmt.go @@ -0,0 +1,35 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" +) + +// ReturnStmt represents a return statement. +type ReturnStmt struct { + ReturnPos source.Pos + Result Expr +} + +func (s *ReturnStmt) stmtNode() {} + +// Pos returns the position of first character belonging to the node. +func (s *ReturnStmt) Pos() source.Pos { + return s.ReturnPos +} + +// End returns the position of first character immediately after the node. +func (s *ReturnStmt) End() source.Pos { + if s.Result != nil { + return s.Result.End() + } + + return s.ReturnPos + 6 +} + +func (s *ReturnStmt) String() string { + if s.Result != nil { + return "return " + s.Result.String() + } + + return "return" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/selector_expr.go b/vendor/github.com/d5/tengo/compiler/ast/selector_expr.go new file mode 100644 index 00000000..31d2e6d1 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/selector_expr.go @@ -0,0 +1,25 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// SelectorExpr represents a selector expression. +type SelectorExpr struct { + Expr Expr + Sel Expr +} + +func (e *SelectorExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *SelectorExpr) Pos() source.Pos { + return e.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *SelectorExpr) End() source.Pos { + return e.Sel.End() +} + +func (e *SelectorExpr) String() string { + return e.Expr.String() + "." + e.Sel.String() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/slice_expr.go b/vendor/github.com/d5/tengo/compiler/ast/slice_expr.go new file mode 100644 index 00000000..e7e2e05b --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/slice_expr.go @@ -0,0 +1,36 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// SliceExpr represents a slice expression. +type SliceExpr struct { + Expr Expr + LBrack source.Pos + Low Expr + High Expr + RBrack source.Pos +} + +func (e *SliceExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *SliceExpr) Pos() source.Pos { + return e.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *SliceExpr) End() source.Pos { + return e.RBrack + 1 +} + +func (e *SliceExpr) String() string { + var low, high string + if e.Low != nil { + low = e.Low.String() + } + if e.High != nil { + high = e.High.String() + } + + return e.Expr.String() + "[" + low + ":" + high + "]" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/stmt.go b/vendor/github.com/d5/tengo/compiler/ast/stmt.go new file mode 100644 index 00000000..6b26ba88 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/stmt.go @@ -0,0 +1,7 @@ +package ast + +// Stmt represents a statement in the AST. +type Stmt interface { + Node + stmtNode() +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/string_lit.go b/vendor/github.com/d5/tengo/compiler/ast/string_lit.go new file mode 100644 index 00000000..2119d34b --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/string_lit.go @@ -0,0 +1,26 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// StringLit represents a string literal. +type StringLit struct { + Value string + ValuePos source.Pos + Literal string +} + +func (e *StringLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *StringLit) Pos() source.Pos { + return e.ValuePos +} + +// End returns the position of first character immediately after the node. +func (e *StringLit) End() source.Pos { + return source.Pos(int(e.ValuePos) + len(e.Literal)) +} + +func (e *StringLit) String() string { + return e.Literal +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/unary_expr.go b/vendor/github.com/d5/tengo/compiler/ast/unary_expr.go new file mode 100644 index 00000000..53236146 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/unary_expr.go @@ -0,0 +1,29 @@ +package ast + +import ( + "github.com/d5/tengo/compiler/source" + "github.com/d5/tengo/compiler/token" +) + +// UnaryExpr represents an unary operator expression. +type UnaryExpr struct { + Expr Expr + Token token.Token + TokenPos source.Pos +} + +func (e *UnaryExpr) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *UnaryExpr) Pos() source.Pos { + return e.Expr.Pos() +} + +// End returns the position of first character immediately after the node. +func (e *UnaryExpr) End() source.Pos { + return e.Expr.End() +} + +func (e *UnaryExpr) String() string { + return "(" + e.Token.String() + e.Expr.String() + ")" +} diff --git a/vendor/github.com/d5/tengo/compiler/ast/undefined_lit.go b/vendor/github.com/d5/tengo/compiler/ast/undefined_lit.go new file mode 100644 index 00000000..8e51b113 --- /dev/null +++ b/vendor/github.com/d5/tengo/compiler/ast/undefined_lit.go @@ -0,0 +1,24 @@ +package ast + +import "github.com/d5/tengo/compiler/source" + +// UndefinedLit represents an undefined literal. +type UndefinedLit struct { + TokenPos source.Pos +} + +func (e *UndefinedLit) exprNode() {} + +// Pos returns the position of first character belonging to the node. +func (e *UndefinedLit) Pos() source.Pos { + return e.TokenPos +} + +// End returns the position of first character immediately after the node. +func (e *UndefinedLit) End() source.Pos { + return e.TokenPos + 9 // len(undefined) == 9 +} + +func (e *UndefinedLit) String() string { + return "undefined" +} |