Skip to main content

brink_syntax_native/
lib.rs

1//! Lexer and error-resilient CST for the `.brink` native surface.
2//!
3//! This crate is the **B0.5 grammar skeleton** (`docs/b0-sequencing.md`
4//! §B0.5): the token vocabulary and a lossless, error-resilient rowan CST
5//! for the ruled native surface subset (`docs/native-surface-charter.md`
6//! §5/§6, NF-2's writer-sufficient subset). It performs **no HIR
7//! lowering, no resolution, no type-checking** — those are B0.6/B0.7/B0.8.
8//!
9//! Peer crate to `brink-syntax` (the ink frontend), per the NF-1 ruling: its
10//! own `SyntaxKind` space, its own rowan tree, depending on nothing
11//! ink-shaped.
12
13pub mod ast;
14pub mod lexer;
15pub mod parser;
16pub mod syntax_kind;
17
18pub use lexer::lex;
19pub use parser::{Parse, ParseError, ParseSeverity, parse, parse_with_cache};
20pub use syntax_kind::{NativeLanguage, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken};
21
22impl Parse {
23    /// Returns the typed root AST node.
24    #[must_use]
25    #[expect(
26        clippy::expect_used,
27        reason = "parse() always produces SOURCE_FILE root"
28    )]
29    pub fn tree(&self) -> ast::SourceFile {
30        use ast::AstNode as _;
31        ast::SourceFile::cast(self.syntax()).expect("parse always produces a SOURCE_FILE root")
32    }
33}