Class Node
Parsed trees are shared across threads, so treat a Node as read-only once parsing has
returned. A Suite parses karate-config.js once and every scenario — running
in parallel — evaluates that one AST, and the interpreter only ever reads: no node.x =
assignment exists on any evaluation path. The mutators below (add(io.karatelabs.parser.Node), addFirst(io.karatelabs.parser.Node),
removeFirst()) belong to tree construction, and the safety of the sharing rests on nobody
calling them afterwards. That is a convention, not an invariant this class enforces.
One field already bends it: getText() caches into a non-volatile cachedText
on first ask, which under sharing is a data race. It is benign — every racing thread computes
the same value, and a String's final fields make it safe to publish that way — but it is
the reason "a Node is read-only once parsed" is a description of intent rather than a fact.
A lazily assigned field of any other type would not be benign. An array or a mutable
object published by a plain write can be seen non-null with its contents not yet visible; if you
add one here, make it volatile and read it once into a local.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidfindChildren(TokenType token) findFirstChild(NodeType type) findFirstChild(TokenType token) findParent(NodeType type) get(int index) getFirst()getLast()getText()booleanisEmpty()booleanisEof()booleanisToken()intsize()toString()toStringError(String message)
-
Field Details
-
type
-
token
-
async
public boolean asyncTheasyncmodifier, for the node types that can carry one —FN_EXPR(a declaration / expression / object-literal method / class method) andFN_ARROW_EXPR. It is a field rather than a child token becauseasyncis a contextual keyword that the lexer emits as a plainIDENT: an extra leading child would shift every positional lookup the interpreter does on those two node types, and a synthesized method has no token of its own to carry the marker. Written by the parser during tree construction only — same read-only-once-parsed convention as the children, and abooleanwritten before publication is safe to share (see the class javadoc). -
slot
public short slot -
meta
-
-
Constructor Details
-
Node
-
Node
-
-
Method Details
-
getParent
-
isToken
public boolean isToken() -
isEof
public boolean isEof() -
getFirstToken
-
getLastToken
-
toStringError
-
toString
-
findFirstChild
-
findAll
-
findFirstChild
-
findParent
-
findImmediateChildren
-
findChildren
-
getText
-
getTextIncludingWhitespace
-
removeFirst
-
addFirst
-
add
-
getFirst
-
getLast
-
get
-
size
public int size() -
isEmpty
public boolean isEmpty()
-