yari-core

Common interfaces and abstractions shared by every Yari parser module. Defines the AST contract, the source-location system, the comment model, JSON serialization support, and base utilities. Depends on yari-parsec.

Installation

// Gradle (Groovy DSL)
implementation 'com.easyparsingapi:yari-core:VERSION'

// Maven
<dependency>
    <groupId>com.easyparsingapi</groupId>
    <artifactId>yari-core</artifactId>
    <version>VERSION</version>
</dependency>

yari-core is pulled transitively by every parser module.

AstNode — The AST Contract

The base interface implemented by every AST node in every parser module.

interface AstNode
Tree navigation
astChildren() List<AstNode> Direct children of this node
astParent() AstNode Parent node, or null for the root
astStream() Stream<AstNode> Pre-order stream over the entire subtree
walkChildren(Consumer<Handler>) Walk direct children with a typed Handler
Equality
equalsNode(AstNode) boolean Structural equality ignoring source location
equals(Object) boolean Full equality including source location
Source location
getSourceLocation() SourceLocation
setSourceLocation(SourceLocation)
Utilities
static childrenAttributes(Object…) List<AstNode> Flatten varargs (single nodes and lists) into a child list

AstUnit — Root with Comments

Extends AstNode. Implemented by the root node of each compilation unit (Javascript, Css, Xml, Html…).

interface AstUnit extends AstNode
astComments() List<AstComment> All comments in this source unit
astCommentsOf(AstNode, Position…) List<AstComment> Comments at the given positions relative to the given node
enum Position
before Relative position of a comment to a node
after
inside

AstToken — Typed Token

Represents a lexer token in a form suitable for inclusion in the AST.

interface AstToken
text() String Raw text of this token
tag() String Lexer tag name (e.g. KEYWORD, WORD)
sourceLocation() SourceLocation

AstResult<N> — Parse Result

Pairs the root AST node with the full token list produced during parsing.

class AstResult<N extends AstNode>
getNode() N The root AST node
getTokens() List<Token> The full ordered token list from the lexer
getAstTokens() List<AstToken> The token list as AstToken instances
substring(SourceLocation) String Extract the source substring for a given location

Source Locations

record SourceLocation
start() Position Inclusive start
end() Position Exclusive end
record Position
line() int 1-based line number
column() int 1-based column number
offset() int 0-based character offset in the source

AstComment — Comment Model

interface AstComment
text() String Raw comment text including delimiters
getSourceLocation() SourceLocation

Utilities

class CollectionUtil (static helpers)
nullToEmpty(List) List Returns an empty list if the argument is null

For the full code-level reference, see the README on GitHub and the Javadoc-annotated source under yari-core/src/main/java/.