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 options;
19mod recovery;
20mod reparse;
21mod sexpr;
22mod structural;
23mod tree_builder;
24mod unescape;
25mod unicode_ident;
26mod unicode_ops;
27
28pub use core::{ParseDiagnostic, ParseOutput, parse, parse_with_options, reconstruct};
29pub use options::{InvalidSyntaxEdition, ParseOptions, SyntaxEdition};
30// Semver-loose: exposed for the fatou CLI's completion and semantic layers,
31// not a stable part of this crate's API.
32pub use lexer::{KEYWORDS, is_ident_continue, is_ident_start};
33pub use reparse::{
34 Edit, ReparseBase, ReparseTier, Reparsed, apply_edits, diff_edit, reparse, reparse_edits,
35 reparse_edits_with_options, reparse_with_options, try_apply_edits,
36};
37// Test support, not API: the in-crate Tenet-4 assert and the
38// `tests/incremental_reparse.rs` oracle harness share this one definition so
39// they can never diverge, which is the only reason it is `pub` at all.
40#[doc(hidden)]
41pub use reparse::fingerprint;
42pub use sexpr::{
43 normalize_sexpr, sexpr_tokens, to_juliasyntax_sexpr, to_juliasyntax_sexpr_with_options,
44};
45// The `lex` bench's entry point. Gated on `bench` so tokenizing on its own —
46// which no consumer has a reason to do — never becomes part of the API.
47#[cfg(feature = "bench")]
48pub fn token_count(input: &str) -> usize {
49 lexer::lex(input).len()
50}
51// A lossless CST hands out a literal's *source*; a consumer reading it as data
52// (the `include` path resolver) needs the value it denotes.
53pub use unescape::{StringDecodeError, string_value};
54
55/// Whether `text` is exactly one symbolic operator token in Julia's comparison
56/// precedence tier. Kept crate-private so typed AST wrappers can share the
57/// parser's generated Unicode classification without exposing lexer internals.
58pub(crate) fn is_comparison_operator_text(text: &str) -> bool {
59 let tokens = lexer::lex(text);
60 tokens.len() == 1 && expr::token_is_comparison_op(tokens[0].kind)
61}