Documentation ¶
Overview ¶
********************************************************************** MicroCore Copyright 2020 - 2022 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2017 - 2022 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2022 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2020 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2020 - 2022 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
********************************************************************** MicroCore Copyright 2017 - 2022 by Danyil Dobryvechir (dobrivecher@yahoo.com ddobryvechir@gmail.com) ***********************************************************************
Index ¶
- Constants
- Variables
- func CheckCreateGrammarTable(rules *GrammarRuleDefinitions)
- func EnrichErrorStr(err error, info string) error
- func ErrorMessageForNode(message string, node *BuildNode, context *ExpressionContext) error
- func ExecuteBracketExpression(parent *ExpressionValue, hasNoParent bool, nodes []*BuildNode, ...) (*ExpressionValue, *ExpressionValue, error)
- func GetEscapedString(data []byte) string
- type BracketOperatorVisitor
- type BuildNode
- func (b *BuildNode) CloneFrom(other *BuildNode)
- func (tree *BuildNode) ExecuteExpression(context *ExpressionContext) (int, *ExpressionValue, error)
- func (tree *BuildNode) GetChildrenExpressionValue(childNo int, context *ExpressionContext) (*ExpressionValue, error)
- func (tree *BuildNode) GetChildrenNumber() int
- type ExpressionContext
- type ExpressionValue
- type GrammarBaseDefinition
- type GrammarRuleDefinitions
- type GrammarTable
- type InterOperator
- type InterOperatorVisitor
- type LanguageOperator
- type LanguageOperatorVisitor
- type ScopeInterface
- type SourceReference
- type Token
- func RecognizerByteControl(grammar *GrammarTable, data []byte, pos int, n int) (t *Token, nextPos int, err error)
- func RecognizerByteDigit(grammar *GrammarTable, data []byte, pos int, n int) (t *Token, nextPos int, err error)
- func RecognizerByteLetter(grammar *GrammarTable, data []byte, pos int, n int) (t *Token, nextPos int, err error)
- func RecognizerByteListControl(grammar *GrammarTable, data []byte, pos int, n int) (t *Token, nextPos int, err error)
- func RecognizerByteQuotation(grammar *GrammarTable, data []byte, pos int, n int) (t *Token, nextPos int, err error)
- func Tokenize(src *SourceReference, data []byte, grammar *GrammarTable) ([]Token, error)
- type TokenBlock
- type TokenMapType
- type TypeRecognizer
- type UnaryOperator
- type UnaryVisitor
Constants ¶
const ( NON_LATIN_LETTERS_ONLY_IN_STRINGS = 1 << iota SINGLE_QUOTE_HAS_TYPE_CHAR EXCLUDE_RECOGNIZER_BYTE_LETTER EXCLUDE_RECOGNIZER_BYTE_DIGIT EXCLUDE_RECOGNIZER_BYTE_QUOTATION EXCLUDE_RECOGNIZER_BYTE_CONTROL EXCLUDE_RECOGNIZER_BYTE_LIST_CONTROL )
bitwise values of EvaluateOptions
const ( FEATURE_ROUND_BRACKET = 1 << iota FEATURE_CURLY_BRACKETS = 1 << iota FEATURE_CURLY_BRACKETS_OR_CODE = 1 << iota FEATURE_FINISH = 1 << iota FEATURE_FINISH_OR_ELSE = 1 << iota )
const ( TYPE_CONTROL = iota TYPE_OPERATOR = iota TYPE_STRING = iota TYPE_CHAR = iota TYPE_NUMBER = iota TYPE_NUMBER_INT = iota TYPE_BOOLEAN = iota TYPE_NULL = iota TYPE_UNDEFINED = iota TYPE_NAN = iota TYPE_FUNCTION = iota TYPE_DATA = iota TYPE_OBJECT = iota TYPE_ERROR = iota TYPE_MASK = 0x7ff )
const ( FLOW_NORMAL = iota FLOW_RETURN FLOW_BREAK FLOW_CONTINUE )
const ( EVALUATE_OPTION_UNDEFINED = 1 << (iota + 8) EVALUATE_OPTION_PARENT = 1 << (iota + 8) EVALUATE_OPTION_NAME = 1 << (iota + 8) )
const ( BYTE_ONLY_INSIDE_STRING = iota BYTE_CONTROL BYTE_DIGIT BYTE_LETTER BYTE_LIST_CLOSING BYTE_LIST_SEPARATOR BYTE_OPERATOR BYTE_QUOTATION BYTE_SPACE )
const (
VISITOR_OPTION_CASHED = 1 << iota
)
bitwise values of VisitorOptions
Variables ¶
var CommonGrammarBaseDefinition = &GrammarBaseDefinition{ Operators: map[string]*InterOperator{ ";": &InterOperator{ Precedence: 0, Multi: true, }, "in": &InterOperator{ Precedence: 1, }, "of": &InterOperator{ Precedence: 1, }, "else": &InterOperator{ Precedence: 1, Multi: true, }, ",": &InterOperator{ Precedence: 1, Multi: true, }, "=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, LazyLoadedOperands: true, }, "+=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "-=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "**=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "*=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "/=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "%=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "<<=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, ">>=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, ">>>=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "&=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "^=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "|=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "&&=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "||=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "??=": &InterOperator{ Precedence: 3, Multi: true, RightToLeft: true, Assignment: true, }, "?": &InterOperator{ Precedence: 4, Multi: false, RightToLeft: true, LazyLoadedOperands: true, }, ":": &InterOperator{ Precedence: 4, Multi: false, RightToLeft: true, LazyLoadedOperands: true, }, "||": &InterOperator{ Precedence: 5, Multi: true, LazyLoadedOperands: true, }, "&&": &InterOperator{ Precedence: 6, Multi: true, LazyLoadedOperands: true, }, "??": &InterOperator{ Precedence: 6, Multi: true, LazyLoadedOperands: true, }, "|": &InterOperator{ Precedence: 7, Multi: true, }, "^": &InterOperator{ Precedence: 8, Multi: true, }, "&": &InterOperator{ Precedence: 9, Multi: true, }, "!==": &InterOperator{ Precedence: 10, }, "===": &InterOperator{ Precedence: 10, }, "==": &InterOperator{ Precedence: 10, }, "!=": &InterOperator{ Precedence: 10, }, "<": &InterOperator{ Precedence: 11, }, ">": &InterOperator{ Precedence: 11, }, "<=": &InterOperator{ Precedence: 11, }, ">=": &InterOperator{ Precedence: 11, }, "<<": &InterOperator{ Precedence: 12, }, ">>": &InterOperator{ Precedence: 12, }, ">>>": &InterOperator{ Precedence: 12, }, "+": &InterOperator{ Precedence: 13, Multi: true, }, "-": &InterOperator{ Precedence: 13, Multi: true, }, "*": &InterOperator{ Precedence: 14, }, "/": &InterOperator{ Precedence: 14, }, "%": &InterOperator{ Precedence: 14, }, "**": &InterOperator{ Precedence: 15, }, "IN": &InterOperator{ Precedence: 16, }, "NOT IN": &InterOperator{ Precedence: 16, }, "=>": &InterOperator{ Precedence: 18, Multi: true, }, "(": &InterOperator{ Precedence: 19, Closing: ")", }, ")": &InterOperator{ Precedence: 19, Opening: "(", }, "[": &InterOperator{ Precedence: 19, Closing: "]", }, "]": &InterOperator{ Precedence: 19, Opening: "[", }, ".": &InterOperator{ Precedence: 19, Multi: true, }, }, UnaryOperators: map[string]*UnaryOperator{ "!": &UnaryOperator{ Post: false, Pre: true, }, "~": &UnaryOperator{ Post: false, Pre: true, }, "+": &UnaryOperator{ Post: false, Pre: true, }, "-": &UnaryOperator{ Post: false, Pre: true, }, "++": &UnaryOperator{ Post: true, Pre: true, }, "--": &UnaryOperator{ Post: true, Pre: true, }, "...": &UnaryOperator{ Post: true, Pre: false, }, }, VoidOperators: map[string]int{ "var": 1, "const": 1, "let": 1, "try": 1, "catch": 1, "public": 1, "private": 1, "protected": 1, "await": 1, "class": 1, "debugger": 1, "enum": 1, "export": 1, "extends": 1, "finally": 1, "implements": 1, "import": 1, "instanceof": 1, "interface": 1, "new": 1, "package": 1, "super": 1, "static": 1, "void": 1, "with": 1, "yield": 1, }, Language: map[string]*LanguageOperator{ "return": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: false, }, "for": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, ParenthesesFollow: true, CurlyBracesFollowParentheses: true, FeatureOptions: FEATURE_ROUND_BRACKET | FEATURE_CURLY_BRACKETS_OR_CODE | FEATURE_FINISH, }, "if": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, ParenthesesFollow: true, CurlyBracesFollowParentheses: true, FeatureOptions: FEATURE_ROUND_BRACKET | FEATURE_CURLY_BRACKETS_OR_CODE | FEATURE_FINISH_OR_ELSE, }, "else": { AlwaysFirst: false, CanHaveArgument: true, MustHaveArgument: false, }, "break": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: false, }, "continue": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: false, }, "switch": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, ParenthesesFollow: true, CurlyBracesFollowParentheses: true, }, "case": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: true, }, "default": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, }, "function": { AlwaysFirst: false, CanHaveArgument: true, MustHaveArgument: false, ParenthesesFollow: true, CurlyBracesFollowParentheses: true, }, "while": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, ParenthesesFollow: true, CurlyBracesFollowParentheses: true, }, "typeof": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: true, }, "do": { AlwaysFirst: true, CanHaveArgument: false, MustHaveArgument: false, }, "throw": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: true, }, "delete": { AlwaysFirst: true, CanHaveArgument: true, MustHaveArgument: true, }, }, DefaultOperator: "", }
var ErrorExpressionValue = &ExpressionValue{DataType: TYPE_ERROR}
var LogicalGrammarBaseDefinition = &GrammarBaseDefinition{ Operators: map[string]*InterOperator{ "||": &InterOperator{ Precedence: 0, Multi: true, LazyLoadedOperands: true, }, "&&": &InterOperator{ Precedence: 1, Multi: true, LazyLoadedOperands: true, }, }, UnaryOperators: map[string]*UnaryOperator{ "!": &UnaryOperator{ Post: false, Pre: true, }, }, DefaultOperator: "&&", }
Functions ¶
func CheckCreateGrammarTable ¶
func CheckCreateGrammarTable(rules *GrammarRuleDefinitions)
func EnrichErrorStr ¶
func ErrorMessageForNode ¶
func ErrorMessageForNode(message string, node *BuildNode, context *ExpressionContext) error
func ExecuteBracketExpression ¶ added in v1.0.2
func ExecuteBracketExpression(parent *ExpressionValue, hasNoParent bool, nodes []*BuildNode, context *ExpressionContext) (*ExpressionValue, *ExpressionValue, error)
func GetEscapedString ¶
Types ¶
type BracketOperatorVisitor ¶ added in v1.0.2
type BracketOperatorVisitor func(*ExpressionValue, *BuildNode, *ExpressionContext, []*BuildNode) (*ExpressionValue, *ExpressionValue, bool, error, bool)
type BuildNode ¶
type BuildNode struct { Children []*BuildNode Parent *BuildNode Operator string Value *Token PreAttributes []string PostAttributes []string Group int // contains filtered or unexported fields }
func CompileOrCache ¶
func CompileOrCache(data []byte, context *ExpressionContext, cache bool) ([]*BuildNode, error)
func (*BuildNode) ExecuteExpression ¶
func (tree *BuildNode) ExecuteExpression(context *ExpressionContext) (int, *ExpressionValue, error)
func (*BuildNode) GetChildrenExpressionValue ¶
func (tree *BuildNode) GetChildrenExpressionValue(childNo int, context *ExpressionContext) (*ExpressionValue, error)
func (*BuildNode) GetChildrenNumber ¶
type ExpressionContext ¶
type ExpressionContext struct { Scope ScopeInterface Reference *SourceReference Rules *GrammarRuleDefinitions VisitorOptions int }
type ExpressionValue ¶
type ExpressionValue struct { DataType int Value interface{} Name string Parent *ExpressionValue }
func BuildNodeExecution ¶ added in v1.0.2
func BuildNodeExecution(nodes []*BuildNode, context *ExpressionContext) (flow int, value *ExpressionValue, err error)
func FastEvaluation ¶
func FastEvaluation(data []byte, context *ExpressionContext) (*ExpressionValue, error)
type GrammarBaseDefinition ¶
type GrammarBaseDefinition struct { Operators map[string]*InterOperator UnaryOperators map[string]*UnaryOperator VoidOperators map[string]int Language map[string]*LanguageOperator DefaultOperator string }
type GrammarRuleDefinitions ¶
type GrammarRuleDefinitions struct { BaseGrammar *GrammarBaseDefinition GrammarAliases map[string]string Recognizers []TypeRecognizer EvaluateOptions int Visitors map[string]InterOperatorVisitor BracketVisitor map[string]BracketOperatorVisitor LanguageOperator map[string]LanguageOperatorVisitor UnaryPostVisitors map[string]UnaryVisitor UnaryPreVisitors map[string]UnaryVisitor DataGetter func(*Token, *ExpressionContext) (*ExpressionValue, error) Grammar *GrammarTable // contains filtered or unexported fields }
type GrammarTable ¶
type GrammarTable struct { TokenMap TokenMapType IsSingleQuoteTypeChar bool }
type InterOperator ¶
type InterOperatorVisitor ¶
type InterOperatorVisitor func([]*ExpressionValue, *BuildNode, *ExpressionContext, string) (*ExpressionValue, error)
type LanguageOperator ¶ added in v1.0.2
type LanguageOperatorVisitor ¶ added in v1.0.2
type LanguageOperatorVisitor func(*BuildNode, *ExpressionContext) (int, *ExpressionValue, error)
type ScopeInterface ¶
type SourceReference ¶
type Token ¶
func RecognizerByteControl ¶
func RecognizerByteDigit ¶
func RecognizerByteLetter ¶
func RecognizerByteQuotation ¶
func Tokenize ¶
func Tokenize(src *SourceReference, data []byte, grammar *GrammarTable) ([]Token, error)
type TokenBlock ¶
type TokenMapType ¶
type TokenMapType [256]*TokenBlock
type TypeRecognizer ¶
type UnaryOperator ¶
type UnaryVisitor ¶
type UnaryVisitor func(*ExpressionValue, *BuildNode, *ExpressionContext, string, string, *ExpressionValue) (*ExpressionValue, error)