Skip to main content

Crate cyrs_syntax

Crate cyrs_syntax 

Source
Expand description

cyrs-syntax — lexer, recovering parser, lossless CST.

Reference: spec 0001 §4. The SyntaxKind enum in kind is the canonical grammar reference; treat it as authoritative. The CST is a rowan green/red tree parameterised by Lang; it preserves every byte of the input (including trivia and malformed fragments).

The parser is event-based (spec 0001 §4.2): it emits an event stream that a builder later uses to construct the rowan tree. This lets the parser rewrite events for associativity and error grouping before tree construction commits.

Everything in this crate is domain-free (spec §2). There are no references to any consumer-specific concept.

§Typed diagnostic codes for embedders (cy-emb3)

SyntaxError::code is a u16 that mirrors the discriminant of the DiagCode enum in cyrs-diag. The numeric form keeps this crate at the bottom of the crate graph (no edge from cyrs-syntax to cyrs-diag), but matching on raw u16 values is brittle — any future renumbering would silently break embedders.

Embedders that already depend on cyrs-diag (typically via cyrs-db for diagnostic rendering, see docs/integration-depth.md) should lift the numeric code to the typed enum at the boundary:

use cyrs_diag::DiagCode;
use cyrs_syntax::parse;

let parse = parse("MATCH");
for err in parse.errors() {
    match DiagCode::from(err) {
        DiagCode::E0001 => { /* generic syntax */ }
        DiagCode::E0007 => { /* expected statement */ }
        _ => { /* other */ }
    }
}

See cyrs_diag::DiagCode::try_from_u16 for a fallible variant that distinguishes “unknown numeric” from “registered E0001”.

Re-exports§

pub use edit::TextEdit;
pub use edit::incremental_reparse;
pub use kind::SyntaxKind;
pub use lexer::LexError;
pub use lexer::LexToken;
pub use lexer::lex;
pub use lexer::validate_tokens;
pub use line_index::LineCol;
pub use line_index::LineIndex;
pub use line_index::WideLineCol;
pub use parser::Parse;
pub use parser::SyntaxError;
pub use parser::parse;
pub use range_ext::TextRangeExt;

Modules§

edit
Tree-edit primitives for incremental reparse (cy-zv0, spec §11).
kind
SyntaxKind — the canonical grammar reference (spec 0001 §4.4).
lexer
Lexer — logos-generated DFA producing a stream of LexToken.
line_index
LineIndex — byte-offset → line/column conversion for diagnostic rendering.
parser
Event-based recovering parser (spec 0001 §4.2, §4.3, §4.4, §4.6).
range_ext
Extension trait sugar for TextRange.

Structs§

TextRange
Byte offset range in the source text. Re-exported from text-size for convenience so downstream crates can depend only on cyrs-syntax. A range in text, represented as a pair of TextSize.
TextSize
Byte offset range in the source text. Re-exported from text-size for convenience so downstream crates can depend only on cyrs-syntax. A measure of text length. Also, equivalently, an index into text.

Enums§

Lang
Language marker for the Cypher rowan tree.

Traits§

TextLen
Byte offset range in the source text. Re-exported from text-size for convenience so downstream crates can depend only on cyrs-syntax. Primitives with a textual length that can be passed to TextSize::of.

Type Aliases§

PreorderWithTokens
Cypher-flavoured alias for rowan::api::PreorderWithTokens — a pre-order walk that visits both nodes and tokens.
SyntaxElement
Cypher-flavoured alias for rowan::SyntaxElement — a sum of SyntaxNode | SyntaxToken used when walking a tree.
SyntaxNode
Cypher-flavoured alias for rowan::SyntaxNode — a typed handle on a node in the CST.
SyntaxNodeChildren
Cypher-flavoured alias for rowan::SyntaxNodeChildren — a node’s immediate child iterator.
SyntaxToken
Cypher-flavoured alias for rowan::SyntaxToken — a leaf token in the CST.