Skip to main content

trident/
lib.rs

1pub mod api;
2pub mod ast;
3pub mod config;
4pub mod cost;
5pub mod deploy;
6pub mod diagnostic;
7pub mod field;
8pub mod gpu;
9pub mod ir;
10pub mod lsp;
11pub mod neural;
12pub mod package;
13pub mod runtime;
14pub mod syntax;
15pub mod typecheck;
16pub mod verify;
17
18// Re-exports — moved modules keep their old `crate::X` paths
19pub(crate) use api::pipeline;
20pub use ir::tir;
21pub use syntax::span;
22pub use typecheck::types;
23
24// Re-exports — preserves `trident::X` paths used by CLI and tests
25pub use config::project;
26pub use config::resolve;
27pub use config::scaffold;
28pub use config::target;
29pub use package::cache;
30pub use package::hash;
31pub use package::manifest;
32pub use package::poseidon2;
33pub use package::registry;
34pub use package::store;
35pub use syntax::format;
36pub use syntax::lexeme;
37pub use syntax::lexer;
38pub use syntax::parser;
39pub use verify::equiv;
40pub use verify::report;
41pub use verify::smt;
42pub use verify::solve;
43pub use verify::sym;
44pub use verify::synthesize;
45
46// Re-export public API — preserves `trident::compile()` etc.
47pub use api::*;
48
49use diagnostic::{render_diagnostics, Diagnostic};
50use lexer::Lexer;
51use parser::Parser;
52
53pub(crate) fn parse_source(source: &str, filename: &str) -> Result<ast::File, Vec<Diagnostic>> {
54    let (tokens, _comments, lex_errors) = Lexer::new(source, 0).tokenize();
55    if !lex_errors.is_empty() {
56        render_diagnostics(&lex_errors, filename, source);
57        return Err(lex_errors);
58    }
59
60    match Parser::new_with_source(tokens, source).parse_file() {
61        Ok(file) => Ok(file),
62        Err(errors) => {
63            render_diagnostics(&errors, filename, source);
64            Err(errors)
65        }
66    }
67}
68
69pub fn parse_source_silent(source: &str, _filename: &str) -> Result<ast::File, Vec<Diagnostic>> {
70    let (tokens, _comments, lex_errors) = Lexer::new(source, 0).tokenize();
71    if !lex_errors.is_empty() {
72        return Err(lex_errors);
73    }
74    Parser::new_with_source(tokens, source).parse_file()
75}