moonrockz/rego/syntax does not have a README file

    PositionError

    pub(all) suberror PositionError {
    InvalidPosition(line~ : Int, column~ : Int)
    StartAfterEnd(start~ : TextPosition, end~ : TextPosition)
    InvalidOffsets(start~ : Int, end~ : Int)
    } derive(Eq,
    Debug
    )

    Raised when a source position or span breaks its invariants.

    TokenError

    pub(all) suberror TokenError {
    SpanTextLengthMismatch(span_len~ : Int, text_len~ : Int)
    NonEmptyEof(text~ : String)
    } derive(Eq,
    Debug
    )

    Raised when a syntax token breaks its invariants.

    LexDiagnostic

    type LexDiagnostic derive(Eq, Hash,
    Debug
    )

    A lexical error recorded during tokenization.

    LexDiagnostic::LexDiagnostic

    fn LexDiagnostic::LexDiagnostic(kind~ : LexErrorKind, span~ : SourceSpan, message~ : String) -> LexDiagnostic

    Creates a lexical diagnostic.

    LexDiagnostic::kind

    LexDiagnostic::message

    fn LexDiagnostic::message(self : LexDiagnostic) -> String

    LexDiagnostic::span

    LexErrorKind

    pub(all) enum LexErrorKind {
    UnterminatedString
    UnterminatedRawString
    UnterminatedTemplateString
    InvalidEscape
    InvalidNumber
    LeadingZeroNumber
    UnexpectedCharacter
    } derive(Eq, Hash,
    Debug
    )

    The category of a lexical error.

    LexResult

    type LexResult derive(Eq,
    Debug
    )

    The result of lexing Rego v1 source text: all tokens (including trivia and trailing Eof) and any lexical diagnostics.

    LexResult::diagnostics

    fn LexResult::diagnostics(self : LexResult) -> ReadOnlyArray[LexDiagnostic]

    LexResult::has_errors

    fn LexResult::has_errors(self : LexResult) -> Bool

    LexResult::to_source

    fn LexResult::to_source(self : LexResult) -> String

    Reconstructs the exact source text by concatenating all token texts.

    LexResult::tokens

    fn LexResult::tokens(self : LexResult) -> ReadOnlyArray[SyntaxToken]

    ParseResult

    type ParseResult derive(Eq,
    Debug
    )

    The lossless result of parsing a Rego v1 module or standalone query.

    ParseResult::ParseResult

    fn ParseResult::ParseResult(root~ : SyntaxNode, diagnostics~ : ArrayView[SyntaxDiagnostic]) -> ParseResult

    Creates an immutable parse result from a CST root and its diagnostics.

    ParseResult::diagnostics

    fn ParseResult::diagnostics(self : ParseResult) -> ReadOnlyArray[SyntaxDiagnostic]

    Returns all lexical and syntax diagnostics in source order.

    ParseResult::has_errors

    fn ParseResult::has_errors(self : ParseResult) -> Bool

    Reports whether parsing produced any diagnostic.

    ParseResult::root

    fn ParseResult::root(self : ParseResult) -> SyntaxNode

    Returns the root green CST node.

    ParseResult::to_source

    fn ParseResult::to_source(self : ParseResult) -> String

    Reconstructs the exact original source text from the CST root.

    SourceSpan

    type SourceSpan derive(Eq, Hash,
    Debug
    )

    A half-open UTF-16 offset range [start_offset, end_offset) paired with 1-based start and end positions.
    impl Show for SourceSpan

    SourceSpan::SourceSpan

    fn SourceSpan::SourceSpan(start~ : TextPosition, end~ : TextPosition, start_offset~ : Int, end_offset~ : Int) -> SourceSpan raise PositionError

    Creates a validated source span.

    SourceSpan::contains

    fn SourceSpan::contains(self : SourceSpan, other : SourceSpan) -> Bool

    Whether other lies completely inside self.

    SourceSpan::cover

    fn SourceSpan::cover(self : SourceSpan, other : SourceSpan) -> SourceSpan

    Merges two spans into the smallest span covering both.

    SourceSpan::empty_at_start

    fn SourceSpan::empty_at_start() -> SourceSpan

    An empty span at the start of a file (0..0, 1:1..1:1).

    SourceSpan::end

    SourceSpan::end_offset

    fn SourceSpan::end_offset(self : SourceSpan) -> Int

    SourceSpan::len

    fn SourceSpan::len(self : SourceSpan) -> Int

    Length in UTF-16 code units.

    SourceSpan::start

    fn SourceSpan::start(self : SourceSpan) -> TextPosition

    SourceSpan::start_offset

    fn SourceSpan::start_offset(self : SourceSpan) -> Int

    SourceSpan::to_string

    fn SourceSpan::to_string(self : SourceSpan) -> String

    SyntaxCursor

    type SyntaxCursor derive(Eq,
    Debug
    )

    An immutable cursor pointing at one SyntaxNode inside a green CST. Every navigation method returns a new cursor without mutating self.

    SyntaxCursor::ancestors

    fn SyntaxCursor::ancestors(self : SyntaxCursor) -> ReadOnlyArray[SyntaxNode]

    Ancestor nodes ordered from the root down to the immediate parent.

    SyntaxCursor::child_at

    fn SyntaxCursor::child_at(self : SyntaxCursor, index : Int) -> SyntaxCursor?

    Moves to the n-th child SyntaxNode (0-based among node children).

    SyntaxCursor::depth

    fn SyntaxCursor::depth(self : SyntaxCursor) -> Int

    Depth from the root (0 at the root).

    SyntaxCursor::first_child

    fn SyntaxCursor::first_child(self : SyntaxCursor) -> SyntaxCursor?

    Moves to the first child SyntaxNode, skipping leaf tokens.

    SyntaxCursor::last_child

    fn SyntaxCursor::last_child(self : SyntaxCursor) -> SyntaxCursor?

    Moves to the last child SyntaxNode, skipping leaf tokens.

    SyntaxCursor::next_sibling

    fn SyntaxCursor::next_sibling(self : SyntaxCursor) -> SyntaxCursor?

    Moves to the next sibling SyntaxNode under the same parent.

    SyntaxCursor::node

    The SyntaxNode at this cursor position.

    SyntaxCursor::parent

    fn SyntaxCursor::parent(self : SyntaxCursor) -> SyntaxCursor?

    Moves to the parent node, or returns None at the root.

    SyntaxCursor::prev_sibling

    fn SyntaxCursor::prev_sibling(self : SyntaxCursor) -> SyntaxCursor?

    Moves to the previous sibling SyntaxNode under the same parent.

    SyntaxCursor::root

    Creates a cursor positioned at the root of a CST.

    SyntaxCursor::span

    The UTF-16 SourceSpan of the current node.

    SyntaxDiagnostic

    type SyntaxDiagnostic derive(Eq, Hash,
    Debug
    )

    An immutable syntax diagnostic with kind, UTF-16 span and message.

    SyntaxDiagnostic::SyntaxDiagnostic

    fn SyntaxDiagnostic::SyntaxDiagnostic(kind~ : SyntaxDiagnosticKind, span~ : SourceSpan, message~ : String) -> SyntaxDiagnostic

    Creates an immutable syntax diagnostic.

    SyntaxDiagnostic::kind

    Returns the category of this diagnostic.

    SyntaxDiagnostic::message

    fn SyntaxDiagnostic::message(self : SyntaxDiagnostic) -> String

    Returns the human-readable diagnostic message.

    SyntaxDiagnostic::span

    Returns the UTF-16 source span of this diagnostic.

    SyntaxDiagnosticKind

    pub(all) enum SyntaxDiagnosticKind {
    Lexical(LexErrorKind)
    UnexpectedToken
    ExpectedToken
    MissingIfKeyword
    MissingContainsKeyword
    ReservedKeywordAsVar
    DuplicatePackage
    MissingPackage
    InvalidRuleHead
    InvalidExpression
    UnclosedDelimiter
    UnexpectedPackageInQuery
    } derive(Eq, Hash,
    Debug
    )

    The category of a syntax diagnostic recorded during lexing or parsing.

    SyntaxElement

    pub(all) enum SyntaxElement {
    Token(SyntaxToken)
    Node(SyntaxNode)
    } derive(Eq, Hash,
    Debug
    )

    A child element of a green CST node: either a leaf token or an interior node.

    SyntaxElement::span

    SyntaxKind

    pub(all) enum SyntaxKind {
    Module
    Query
    PackageDecl
    ImportDecl
    ImportAlias
    Rule
    DefaultRule
    RuleHead
    RuleHeadRef
    RuleArgs
    RuleContainsKey
    RuleValue
    RuleBody
    ElseBranch
    Expr
    NotExpr
    SomeDecl
    SomeIn
    EveryExpr
    AssignExpr
    UnifyExpr
    InExpr
    BinaryExpr
    UnaryExpr
    WithModifier
    Ref
    RefDot
    RefBracket
    CallExpr
    ArgList
    ParenTerm
    Literal
    Var
    TemplateString
    TemplatePartText
    TemplatePartExpr
    ArrayLiteral
    ObjectLiteral
    ObjectEntry
    SetLiteral
    EmptySet
    ArrayComprehension
    ObjectComprehension
    SetComprehension
    Error
    } derive(Compare, Eq, Hash,
    Debug
    )

    Every concrete syntax tree node kind in strict Rego v1.

    SyntaxNode

    type SyntaxNode derive(Eq, Hash,
    Debug
    )

    An immutable green CST node preserving exact token order, trivia and spans.

    SyntaxNode::child_nodes

    fn SyntaxNode::child_nodes(self : SyntaxNode) -> ReadOnlyArray[SyntaxNode]

    Returns the direct child SyntaxNodes in source order.

    SyntaxNode::child_tokens

    fn SyntaxNode::child_tokens(self : SyntaxNode) -> ReadOnlyArray[SyntaxToken]

    Returns the direct child SyntaxTokens in source order.

    SyntaxNode::children

    fn SyntaxNode::children(self : SyntaxNode) -> ReadOnlyArray[SyntaxElement]

    Returns all direct children (nodes and tokens, including trivia).

    SyntaxNode::kind

    fn SyntaxNode::kind(self : SyntaxNode) -> SyntaxKind

    Returns the syntax kind of this node.

    SyntaxNode::non_trivia_children

    fn SyntaxNode::non_trivia_children(self : SyntaxNode) -> ReadOnlyArray[SyntaxElement]

    Returns direct children excluding trivia tokens and Eof.

    SyntaxNode::span

    fn SyntaxNode::span(self : SyntaxNode) -> SourceSpan

    Returns the UTF-16 source span covering this node.

    SyntaxNode::to_source

    fn SyntaxNode::to_source(self : SyntaxNode) -> String

    Reconstructs the exact original source slice covered by this CST node.

    SyntaxToken

    type SyntaxToken derive(Eq, Hash,
    Debug
    )

    One immutable lexical token with its exact source slice and UTF-16 span.

    SyntaxToken::SyntaxToken

    fn SyntaxToken::SyntaxToken(kind~ : TokenKind, text~ : String, span~ : SourceSpan) -> SyntaxToken raise TokenError

    Creates a validated syntax token.

    SyntaxToken::kind

    fn SyntaxToken::kind(self : SyntaxToken) -> TokenKind

    SyntaxToken::span

    fn SyntaxToken::span(self : SyntaxToken) -> SourceSpan

    SyntaxToken::text

    fn SyntaxToken::text(self : SyntaxToken) -> String

    TextPosition

    type TextPosition derive(Compare, Eq, Hash,
    Debug
    )

    A 1-based line and column position in source text. Columns count UTF-16 code units. Positions order by line, then by column.

    TextPosition::TextPosition

    fn TextPosition::TextPosition(line~ : Int, column~ : Int) -> TextPosition raise PositionError

    Creates a validated 1-based text position.

    TextPosition::column

    fn TextPosition::column(self : TextPosition) -> Int

    The 1-based UTF-16 column number.

    TextPosition::line

    fn TextPosition::line(self : TextPosition) -> Int

    The 1-based line number.

    TextPosition::start_of_file

    fn TextPosition::start_of_file() -> TextPosition

    The 1-based start of a file (1:1).

    TextPosition::to_string

    fn TextPosition::to_string(self : TextPosition) -> String

    Formats the position as line:column.

    TokenKind

    pub(all) enum TokenKind {
    Whitespace
    Newline
    Comment
    Package
    Import
    As
    Default
    Else
    Not
    Some
    With
    Null
    True
    False
    Every
    Contains
    If
    In
    Ident
    Number
    String
    RawString
    TemplateStringStart
    RawTemplateStringStart
    TemplateStringText
    TemplateExprStart
    TemplateExprEnd
    TemplateStringEnd
    RawTemplateStringEnd
    LBrack
    RBrack
    LBrace
    RBrace
    LParen
    RParen
    Comma
    Colon
    Dot
    Semicolon
    Add
    Sub
    Mul
    Quo
    Rem
    And
    Or
    Unify
    Equal
    Assign
    Neq
    Gt
    Lt
    Gte
    Lte
    Illegal
    Eof
    } derive(Compare, Eq, Hash,
    Debug
    )

    Every lexical token kind in strict Rego v1 (OPA v1.23.0).

    TokenKind::is_dot_key

    fn TokenKind::is_dot_key(self : TokenKind) -> Bool

    Whether this token can appear as a dot-chained key after . (identifier or keyword).

    TokenKind::is_keyword

    fn TokenKind::is_keyword(self : TokenKind) -> Bool

    Whether this token kind is a Rego v1 keyword.

    TokenKind::is_trivia

    fn TokenKind::is_trivia(self : TokenKind) -> Bool

    Whether this token kind is trivia (whitespace, newline, or comment).

    TokenKind::is_var_ident

    fn TokenKind::is_var_ident(self : TokenKind) -> Bool

    Whether this token can act as a variable identifier in Rego v1. In OPA v1.23.0, contains is contextual and valid as a variable/ref head.

    lex

    fn lex(source : String) -> LexResult

    Tokenizes Rego v1 source text into a lossless stream of UTF-16 spanned tokens (including trivia and a final Eof token) and lexical diagnostics.

    parse_module_cst

    fn parse_module_cst(source : String) -> ParseResult

    Parses a Rego v1 module into a lossless CST and diagnostics.

    parse_query_cst

    fn parse_query_cst(source : String) -> ParseResult

    Parses a standalone Rego v1 query (no package header) into a lossless CST.