1mod diagnostics;
2mod line_helpers;
3mod parse;
4mod relation_helpers;
5mod validate;
6
7#[cfg(test)]
8mod tests_basic;
9#[cfg(test)]
10mod tests_docs;
11#[cfg(test)]
12mod tests_enums;
13#[cfg(test)]
14mod tests_field_attrs;
15#[cfg(test)]
16mod tests_mixins;
17#[cfg(test)]
18mod tests_model_attrs;
19#[cfg(test)]
20mod tests_procedures;
21#[cfg(test)]
22mod tests_relations;
23#[cfg(test)]
24mod tests_relations_policy;
25#[cfg(test)]
26mod tests_transport;
27#[cfg(test)]
28mod tests_types;
29#[cfg(test)]
30mod tests_validators;
31#[cfg(test)]
32mod tests_version;
33
34use std::path::Path;
35
36pub use diagnostics::SchemaError;
37
38#[cfg(test)]
39use relation_helpers::parse_relation_attribute;
40
41pub fn parse_schema(source: &str) -> Result<cratestack_core::Schema, SchemaError> {
42 parse_schema_named("<schema>", source)
43}
44
45pub fn parse_schema_named(
46 path: &str,
47 source: &str,
48) -> Result<cratestack_core::Schema, SchemaError> {
49 let schema = parse::parse_schema_only(source)?;
50 validate::validate_schema(path, source, &schema)?;
51 Ok(schema)
52}
53
54pub fn parse_schema_file(path: impl AsRef<Path>) -> Result<cratestack_core::Schema, SchemaError> {
55 let path = path.as_ref();
56 let source = std::fs::read_to_string(path).map_err(|error| {
57 SchemaError::new(
58 format!("failed to read schema file {}: {error}", path.display()),
59 0..0,
60 1,
61 )
62 })?;
63 parse_schema_named(&path.display().to_string(), &source)
64}