Skip to main content

fatou_parser/
parser.rs

1//! The parse pipeline: `lex → parse_expr (Pratt) + structural (recursive
2//! descent) → events → build_tree → rowan CST`.
3//!
4//! Losslessness is the core invariant: `reconstruct(text) == text` for all
5//! inputs. Incremental reparse splicing lives in
6//! [`reparse`] (a single edit) and [`reparse_edits`] (a chain of them); both
7//! return `None` when no strategy applies, and the host's salsa layer
8//! (`fatou::incremental`) then does a full parse.
9
10mod context;
11mod core;
12mod cursor;
13mod diagnostics;
14mod edit;
15mod events;
16mod expr;
17mod lexer;
18mod recovery;
19mod reparse;
20mod sexpr;
21mod structural;
22mod tree_builder;
23mod unescape;
24mod unicode_ident;
25mod unicode_ops;
26
27pub use core::{ParseDiagnostic, ParseOutput, parse, reconstruct};
28// Semver-loose: exposed for the fatou CLI's completion and semantic layers,
29// not a stable part of this crate's API.
30pub use lexer::{KEYWORDS, is_ident_continue, is_ident_start};
31pub use reparse::{
32    Edit, ReparseTier, Reparsed, apply_edits, diff_edit, reparse, reparse_edits, try_apply_edits,
33};
34// Test support, not API: the in-crate Tenet-4 assert and the
35// `tests/incremental_reparse.rs` oracle harness share this one definition so
36// they can never diverge, which is the only reason it is `pub` at all.
37#[doc(hidden)]
38pub use reparse::fingerprint;
39pub use sexpr::{normalize_sexpr, sexpr_tokens, to_juliasyntax_sexpr};
40// The `lex` bench's entry point. Gated on `bench` so tokenizing on its own —
41// which no consumer has a reason to do — never becomes part of the API.
42#[cfg(feature = "bench")]
43pub fn token_count(input: &str) -> usize {
44    lexer::lex(input).len()
45}
46// A lossless CST hands out a literal's *source*; a consumer reading it as data
47// (the `include` path resolver) needs the value it denotes.
48pub use unescape::{StringDecodeError, string_value};
49
50/// Whether `text` is exactly one symbolic operator token in Julia's comparison
51/// precedence tier. Kept crate-private so typed AST wrappers can share the
52/// parser's generated Unicode classification without exposing lexer internals.
53pub(crate) fn is_comparison_operator_text(text: &str) -> bool {
54    let tokens = lexer::lex(text);
55    tokens.len() == 1 && expr::token_is_comparison_op(tokens[0].kind)
56}