1mod error;
8mod index;
9mod lower;
10mod parse;
11#[cfg(test)]
12mod tests;
13mod to_wgsl;
14
15use crate::front::wgsl::error::Error;
16use crate::front::wgsl::parse::Parser;
17use thiserror::Error;
18
19pub use crate::front::wgsl::error::ParseError;
20use crate::front::wgsl::lower::Lowerer;
21use crate::Scalar;
22
23pub struct Frontend {
24 parser: Parser,
25}
26
27impl Frontend {
28 pub const fn new() -> Self {
29 Self {
30 parser: Parser::new(),
31 }
32 }
33
34 pub fn parse(&mut self, source: &str) -> Result<crate::Module, ParseError> {
35 self.inner(source).map_err(|x| x.as_parse_error(source))
36 }
37
38 fn inner<'a>(&mut self, source: &'a str) -> Result<crate::Module, Error<'a>> {
39 let tu = self.parser.parse(source)?;
40 let index = index::Index::generate(&tu)?;
41 let module = Lowerer::new(&index).lower(&tu)?;
42
43 Ok(module)
44 }
45}
46
47pub fn parse_str(source: &str) -> Result<crate::Module, ParseError> {
59 Frontend::new().parse(source)
60}