1pub mod ast;
2pub(crate) mod ast_folder;
3pub mod attributes;
4pub mod containment;
5pub mod desugar;
6mod display;
7pub mod go_names;
8pub mod lex;
9pub mod parse;
10pub mod program;
11pub mod types;
12
13pub use ecow::EcoString;
14pub use parse::ParseError;
15
16pub const ENTRY_MODULE_ID: &str = "_entry_";
17pub const ROOT_IMPORT: &str = "root";
18
19pub type AstBuildResult = parse::ParseResult;
20
21#[cfg(target_pointer_width = "64")]
22mod size_assertions {
23 use std::mem::size_of;
24 const _: () = assert!(size_of::<super::ast::Expression>() == 288);
25 const _: () = assert!(size_of::<super::ast::Pattern>() == 152);
26 const _: () = assert!(size_of::<super::types::Type>() == 40);
27 const _: () = assert!(size_of::<super::ast::Span>() == 12);
28}
29
30const MAX_SOURCE_BYTES: usize = 10 * 1024 * 1024; pub fn build_ast(source: &str, file_id: u32) -> AstBuildResult {
33 if source.len() > MAX_SOURCE_BYTES {
34 return parse::ParseResult {
35 ast: vec![],
36 errors: vec![
37 ParseError::new(
38 "File too large",
39 ast::Span::new(file_id, 0, 0),
40 format!(
41 "file is {} bytes, maximum is {} bytes",
42 source.len(),
43 MAX_SOURCE_BYTES,
44 ),
45 )
46 .with_parse_code("file_too_large"),
47 ],
48 file_comment: None,
49 };
50 }
51
52 let parse_result = parse::Parser::lex_and_parse_file(source, file_id);
53 if parse_result.failed() {
54 return parse::ParseResult {
55 ast: vec![],
56 errors: parse_result.errors,
57 file_comment: None,
58 };
59 }
60
61 let desugar_result = desugar::desugar(parse_result.ast);
62 parse::ParseResult {
63 ast: desugar_result.ast,
64 errors: desugar_result.errors,
65 file_comment: parse_result.file_comment,
66 }
67}