AstElement AST Common Object
The AstElement
object is the core of ALL elements. Every single element.
info
Every single AST element in the document inherits the AstElement
and can access its data
Attributes
astType
(type string): the type of the element. The value depends in what element you are on.context
(typeContext
and depends on the language): the context of the ASTstart
(typePosition
): the starting position of the element in the ASTend
(typePosition
): the starting position of the element in the AST
tip
At any time when you write a rule, use the astType
to distinguish between the types of nodes
you are working on.
info
The context
attribute depends on your language. It inherits the Context
object.
If you are using Python, see PythonNodeContext
Usage
When you have an AST object, you can do the following:
const astObject = ...
// get the starting line of the element
const startLine = astObject.start.line;
// get the ending column of the object
const endCol = astObject.end.col;
// check if the type of the object is string
if (astObject.astType === "string") {
...
}
if (astObject.context.currentFunction) {
// this AST element is in a function
}