GenerateInputTree
isTreeExtendable
isTreeExtendable(tree, op, isFinal) => false | true
Checks if the input tree can have its number of inputs increased.
Parameters
tree: InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode
– The tree to check.op: "|" | "^" | "&"
– The operation the tree should have.isFinal: false | true
– Whether or not the tree can be modified.
Returns
-
false | true
– True if tree has kind "binop", tree's type is op, and isFinal is false or undefined, false otherwise.
generateNestedTrees
generateNestedTrees(children, currentOp) => (InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode)[]
Generates a nested tree structure where each layer has at most 8 children.
Parameters
children: (InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode)[]
– The array of children to turn into a nested structure.currentOp: "|" | "^" | "&"
– The operand all these nodes have.
Returns
-
(InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode)[]
– The properly nested tree structure.
generateErrorMessage
generateErrorMessage(prev, next, ops) => string
Generates a specific error message when no operator is detected between two tokens. This message searches to see if one of the tokens is the operator for a different format.
Parameters
prev: string
– The name of the first token.next: string
– The name of the second token.ops: Record
– The represenation of the operands in the original expression.
Returns
-
string
– The generate error message.
generateInputTreeCore
generateInputTreeCore(tokens, ops, currentOpNum, index) => NewTreeRetValue
The core of the function to generate the input tree. Various errors are returned for invalid inputs. It is recommended to not call this function directly and instead call GenerateInputTree.
Parameters
tokens: (OpToken | InputToken)[]
– The array of tokens representing the expression to parse.ops: Record
– The represenation of the operands in the original expression, only used for error text formatting.currentOpNum: number
– The index of the current operation to evaluate.index: number
– The index of the parsing process in the tokens Array.
Returns
-
NewTreeRetValue
– The current input tree and the current parsing index.
GenerateInputTree
GenerateInputTree(tokens, ops) => InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode
The core of the function to generate the input tree. Various errors are returned for invalid inputs.
Parameters
tokens: (OpToken | InputToken)[]
– The array of tokens representing the expression to parse.ops: Record
– The representation format for the operations used in this expression (only used for error messages).
Returns
-
InputTreeIdent | InputTreeUnOpNode | InputTreeBinOpNode
–undefined
if tokens.length is 0, the relevant input tree otherwise.