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 ofLexToken. - 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§
- Text
Range - Byte offset range in the source text. Re-exported from
text-sizefor convenience so downstream crates can depend only oncyrs-syntax. A range in text, represented as a pair ofTextSize. - Text
Size - Byte offset range in the source text. Re-exported from
text-sizefor convenience so downstream crates can depend only oncyrs-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-sizefor convenience so downstream crates can depend only oncyrs-syntax. Primitives with a textual length that can be passed toTextSize::of.
Type Aliases§
- Preorder
With Tokens - Cypher-flavoured alias for
rowan::api::PreorderWithTokens— a pre-order walk that visits both nodes and tokens. - Syntax
Element - Cypher-flavoured alias for
rowan::SyntaxElement— a sum ofSyntaxNode | SyntaxTokenused when walking a tree. - Syntax
Node - Cypher-flavoured alias for
rowan::SyntaxNode— a typed handle on a node in the CST. - Syntax
Node Children - Cypher-flavoured alias for
rowan::SyntaxNodeChildren— a node’s immediate child iterator. - Syntax
Token - Cypher-flavoured alias for
rowan::SyntaxToken— a leaf token in the CST.