Documentation
¶
Overview ¶
Package dsl contains support routines used between package parsing and package cst. Package parsing contains the Miller DSL grammar; package dsl contains the abstract syntax tree which user DSL statements are parsed into; package cst turns the abstract syntax tree from the parser into a concrete syntax tree which is executable.
Index ¶
- func NewASTToken(iliteral interface{}, iclonee interface{}) *token.Token
- func TokenToLocationInfo(sourceToken *token.Token) string
- type AST
- type ASTNode
- func AdoptChildren(iparent interface{}, ichild interface{}) (*ASTNode, error)
- func AppendChild(iparent interface{}, child interface{}) (*ASTNode, error)
- func Nestable(iparent interface{}) (*ASTNode, error)
- func NewASTNode(itok interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeBinary(itok, childA, childB interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeBinaryNestable(itok, childA, childB interface{}, nodeType TNodeType) *ASTNode
- func NewASTNodeEmpty(nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeEmptyNestable(nodeType TNodeType) *ASTNode
- func NewASTNodeNestable(itok interface{}, nodeType TNodeType) *ASTNode
- func NewASTNodeQuaternary(itok, childA, childB, childC, childD interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeStripDollarOrAtSign(itok interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeStripDollarOrAtSignAndCurlyBraces(itok interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeStripDoubleQuotePair(itok interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeTernary(itok, childA, childB, childC interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeUnary(itok, childA interface{}, nodeType TNodeType) (*ASTNode, error)
- func NewASTNodeUnaryNestable(itok, childA interface{}, nodeType TNodeType) *ASTNode
- func NewASTNodeZary(itok interface{}, nodeType TNodeType) (*ASTNode, error)
- func PrependChild(iparent interface{}, ichild interface{}) (*ASTNode, error)
- func PrependTwoChildren(iparent interface{}, ichildA, ichildB interface{}) (*ASTNode, error)
- func Wrap(inode interface{}) (*ASTNode, error)
- type TNodeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewASTToken ¶
Tokens are produced by GOCC. However there is an exception: for the ternary operator I want the AST to have a "?:" token, which GOCC doesn't produce since nothing is actually spelled like that in the DSL.
func TokenToLocationInfo ¶
TokenToLocationInfo is used to track runtime errors back to source-code locations in DSL expressions, so we can have more informative error messages.
Types ¶
type AST ¶
type AST struct {
RootNode *ASTNode
}
----------------------------------------------------------------
func (*AST) PrintParex ¶
func (ast *AST) PrintParex()
func (*AST) PrintParexOneLine ¶
func (ast *AST) PrintParexOneLine()
type ASTNode ¶
type ASTNode struct { Token *token.Token // Nil for tokenless/structural nodes Type TNodeType Children []*ASTNode }
----------------------------------------------------------------
func AdoptChildren ¶
func AppendChild ¶
func Nestable ¶
Pass-through expressions in the grammar sometimes need to be turned from (ASTNode) to (ASTNode, error)
func NewASTNode ¶
----------------------------------------------------------------
func NewASTNodeBinary ¶
Signature: Token Node Node Type
func NewASTNodeBinaryNestable ¶
Signature: Token Node Node Type
func NewASTNodeEmpty ¶
For handling empty expressions.
func NewASTNodeEmptyNestable ¶
For handling empty expressions.
func NewASTNodeNestable ¶
xxx comment why grammar use
func NewASTNodeQuaternary ¶
func NewASTNodeStripDollarOrAtSign ¶
Strips the leading '$' from field names, or '@' from oosvar names. Not done in the parser itself due to LR-1 conflicts.
func NewASTNodeStripDollarOrAtSignAndCurlyBraces ¶
func NewASTNodeStripDollarOrAtSignAndCurlyBraces( itok interface{}, nodeType TNodeType, ) (*ASTNode, error)
Strips the leading '${' and trailing '}' from braced field names, or '@{' and '}' from oosvar names. Not done in the parser itself due to LR-1 conflicts.
func NewASTNodeStripDoubleQuotePair ¶
Likewise for the leading/trailing double quotes on string literals. Also, since string literals can have backslash-escaped double-quotes like "...\"...\"...", we also unbackslash here.
func NewASTNodeTernary ¶
func NewASTNodeUnary ¶
func NewASTNodeUnaryNestable ¶
func NewASTNodeZary ¶
func PrependChild ¶
func PrependTwoChildren ¶
func (*ASTNode) CheckArity ¶
func (*ASTNode) ChildrenAreAllLeaves ¶
ChildrenAreAllLeaves determines if an AST node's children are all leaf nodes.
func (*ASTNode) PrintParex ¶
func (node *ASTNode) PrintParex()
PrintParex is parenthesized-expression print.
func (*ASTNode) PrintParexOneLine ¶
func (node *ASTNode) PrintParexOneLine()
PrintParexOneLine is parenthesized-expression print, all on one line.
type TNodeType ¶
type TNodeType string
----------------------------------------------------------------
const ( NodeTypeStringLiteral TNodeType = "string literal" NodeTypeRegex TNodeType = "regular expression" // not in the BNF -- written during CST pre-build pass NodeTypeRegexCaseInsensitive TNodeType = "case-insensitive regular expression" // E.g. "a.*b"i -- note the trailing 'i' NodeTypeIntLiteral TNodeType = "int literal" NodeTypeFloatLiteral TNodeType = "float literal" NodeTypeBoolLiteral TNodeType = "bool literal" NodeTypeNullLiteral TNodeType = "null literal" NodeTypeArrayLiteral TNodeType = "array literal" NodeTypeMapLiteral TNodeType = "map literal" NodeTypeMapLiteralKeyValuePair TNodeType = "map-literal key-value pair" NodeTypeArrayOrMapIndexAccess TNodeType = "array or map index access" NodeTypeArraySliceAccess TNodeType = "array-slice access" NodeTypeArraySliceEmptyLowerIndex TNodeType = "array-slice empty lower index" NodeTypeArraySliceEmptyUpperIndex TNodeType = "array-slice empty upper index" NodeTypePositionalFieldName TNodeType = "positionally-indexed field name" NodeTypePositionalFieldValue TNodeType = "positionally-indexed field value" NodeTypeArrayOrMapPositionalNameAccess TNodeType = "positionally-indexed map key" NodeTypeArrayOrMapPositionalValueAccess TNodeType = "positionally-indexed map value" NodeTypeContextVariable TNodeType = "context variable" NodeTypeConstant TNodeType = "mathematical constant" NodeTypeEnvironmentVariable TNodeType = "environment variable" NodeTypeDirectFieldValue TNodeType = "direct field value" NodeTypeIndirectFieldValue TNodeType = "indirect field value" NodeTypeFullSrec TNodeType = "full record" NodeTypeDirectOosvarValue TNodeType = "direct oosvar value" NodeTypeIndirectOosvarValue TNodeType = "indirect oosvar value" NodeTypeFullOosvar TNodeType = "full oosvar" NodeTypeLocalVariable TNodeType = "local variable" NodeTypeTypedecl TNodeType = "type declaration" NodeTypeStatementBlock TNodeType = "statement block" NodeTypeAssignment TNodeType = "assignment" NodeTypeUnset TNodeType = "unset" NodeTypeBareBoolean TNodeType = "bare boolean" NodeTypeFilterStatement TNodeType = "filter statement" NodeTypeTeeStatement TNodeType = "tee statement" NodeTypeEmit1Statement TNodeType = "emit1 statement" NodeTypeEmitStatement TNodeType = "emit statement" NodeTypeEmitPStatement TNodeType = "emitp statement" NodeTypeEmitFStatement TNodeType = "emitf statement" NodeTypeEmittableList TNodeType = "emittable list" NodeTypeEmitKeys TNodeType = "emit keys" NodeTypeDumpStatement TNodeType = "dump statement" NodeTypeEdumpStatement TNodeType = "edump statement" NodeTypePrintStatement TNodeType = "print statement" NodeTypeEprintStatement TNodeType = "eprint statement" NodeTypePrintnStatement TNodeType = "printn statement" NodeTypeEprintnStatement TNodeType = "eprintn statement" // For 'print > filename, "string"' et al. NodeTypeRedirectWrite TNodeType = "redirect write" NodeTypeRedirectAppend TNodeType = "redirect append" NodeTypeRedirectPipe TNodeType = "redirect pipe" NodeTypeRedirectTargetStdout TNodeType = "stdout redirect target" NodeTypeRedirectTargetStderr TNodeType = "stderr redirect target" NodeTypeRedirectTarget TNodeType = "redirect target" // This helps various emit-variant sub-ASTs have the same shape. For // example, in 'emit > "foo.txt", @v' and 'emit @v', the latter has a no-op // for its redirect target. NodeTypeNoOp TNodeType = "no-op" // The dot operator is a little different from other operators since it's // type-dependent: for strings/int/bools etc it's just concatenation of // string representations, but if the left-hand side is a map, it's a // key-lookup with an unquoted literal on the right. E.g. mymap.foo is the // same as mymap["foo"]. NodeTypeOperator TNodeType = "operator" NodeTypeDotOperator TNodeType = "dot operator" NodeTypeFunctionCallsite TNodeType = "function callsite" NodeTypeSubroutineCallsite TNodeType = "subroutine callsite" NodeTypeBeginBlock TNodeType = "begin block" NodeTypeEndBlock TNodeType = "end block" NodeTypeIfChain TNodeType = "if-chain" NodeTypeIfItem TNodeType = "if-item" NodeTypeCondBlock TNodeType = "cond block" NodeTypeWhileLoop TNodeType = "while loop" NodeTypeDoWhileLoop TNodeType = "do-while`loop" NodeTypeForLoopOneVariable TNodeType = "single-variable for-loop" NodeTypeForLoopTwoVariable TNodeType = "double-variable for-loop" NodeTypeForLoopMultivariable TNodeType = "multi-variable for-loop" NodeTypeTripleForLoop TNodeType = "triple-for loop" NodeTypeBreak TNodeType = "break" NodeTypeContinue TNodeType = "continue" NodeTypeNamedFunctionDefinition TNodeType = "function definition" NodeTypeUnnamedFunctionDefinition TNodeType = "function literal" NodeTypeSubroutineDefinition TNodeType = "subroutine definition" NodeTypeParameterList TNodeType = "parameter list" NodeTypeParameter TNodeType = "parameter" NodeTypeParameterName TNodeType = "parameter name" NodeTypeReturn TNodeType = "return" // A special token which causes a panic when evaluated. This is for // testing that AND/OR short-circuiting is implemented correctly: output = // input1 || panic should NOT panic the process when input1 is true. NodeTypePanic TNodeType = "panic token" )