summaryrefslogtreecommitdiffstats
path: root/third_party/rust/naga/src/front/glsl/mod.rs
blob: 4661011828e968dfe4af8934a2335f92db45aa74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::{FastHashMap, Module, ShaderStage};

mod lex;
#[cfg(test)]
mod lex_tests;

mod preprocess;
#[cfg(test)]
mod preprocess_tests;

mod ast;
use ast::Program;

use lex::Lexer;
mod error;
use error::ParseError;
mod parser;
#[cfg(test)]
mod parser_tests;
mod token;
mod types;
mod variables;

pub fn parse_str(
    source: &str,
    entry: &str,
    stage: ShaderStage,
    defines: FastHashMap<String, String>,
) -> Result<Module, ParseError> {
    let mut program = Program::new(stage, entry);

    let mut lex = Lexer::new(source);
    lex.pp.defines = defines;

    let mut parser = parser::Parser::new(&mut program);

    for token in lex {
        parser.parse(token)?;
    }
    parser.end_of_input()?;

    Ok(program.module)
}