From 9ffb69d6cb41784e53ee205aea41c714fdc2429e Mon Sep 17 00:00:00 2001 From: Andrzej Lichnerowicz Date: Mon, 12 Jul 2021 12:45:46 +0200 Subject: [PATCH] Allow for preprocessor as a statement Closes #64. Closes #117. --- glsl-quasiquote/src/tokenize.rs | 5 +++++ glsl/src/parsers.rs | 1 + glsl/src/syntax.rs | 1 + glsl/src/transpiler/glsl.rs | 1 + glsl/src/visitor.rs | 1 + 5 files changed, 9 insertions(+) diff --git a/glsl-quasiquote/src/tokenize.rs b/glsl-quasiquote/src/tokenize.rs index 5f45674..a8f55c1 100644 --- a/glsl-quasiquote/src/tokenize.rs +++ b/glsl-quasiquote/src/tokenize.rs @@ -955,6 +955,11 @@ fn tokenize_statement(st: &syntax::Statement) -> TokenStream { fn tokenize_simple_statement(sst: &syntax::SimpleStatement) -> TokenStream { match *sst { + syntax::SimpleStatement::Preprocessor(ref pp) => { + let d = tokenize_preprocessor(pp); + quote! { glsl::syntax::SimpleStatement::Preprocessor(#pp) } + } + syntax::SimpleStatement::Declaration(ref d) => { let d = tokenize_declaration(d); quote! { glsl::syntax::SimpleStatement::Declaration(#d) } diff --git a/glsl/src/parsers.rs b/glsl/src/parsers.rs index 916e57f..2e645ca 100644 --- a/glsl/src/parsers.rs +++ b/glsl/src/parsers.rs @@ -1305,6 +1305,7 @@ pub fn multiplicative_expr(i: &str) -> ParserResult { /// Parse a simple statement. pub fn simple_statement(i: &str) -> ParserResult { alt(( + map(preprocessor, syntax::SimpleStatement::Preprocessor), map(jump_statement, syntax::SimpleStatement::Jump), map(iteration_statement, syntax::SimpleStatement::Iteration), map(case_label, syntax::SimpleStatement::CaseLabel), diff --git a/glsl/src/syntax.rs b/glsl/src/syntax.rs index 36c0ea5..71dc585 100644 --- a/glsl/src/syntax.rs +++ b/glsl/src/syntax.rs @@ -1011,6 +1011,7 @@ impl Statement { /// Simple statement. #[derive(Clone, Debug, PartialEq)] pub enum SimpleStatement { + Preprocessor(Preprocessor), Declaration(Declaration), Expression(ExprStatement), Selection(SelectionStatement), diff --git a/glsl/src/transpiler/glsl.rs b/glsl/src/transpiler/glsl.rs index da9395d..58f0b42 100644 --- a/glsl/src/transpiler/glsl.rs +++ b/glsl/src/transpiler/glsl.rs @@ -1343,6 +1343,7 @@ where F: Write, { match *sst { + syntax::SimpleStatement::Preprocessor(ref pp) => show_preprocessor(f, pp), syntax::SimpleStatement::Declaration(ref d) => show_declaration(f, d), syntax::SimpleStatement::Expression(ref e) => show_expression_statement(f, e), syntax::SimpleStatement::Selection(ref s) => show_selection_statement(f, s), diff --git a/glsl/src/visitor.rs b/glsl/src/visitor.rs index 5867c72..ed9d2e2 100644 --- a/glsl/src/visitor.rs +++ b/glsl/src/visitor.rs @@ -1199,6 +1199,7 @@ macro_rules! make_host_trait { if visit == Visit::Children { match self { + syntax::SimpleStatement::Preprocessor(p) => p.$mthd_name(visitor), syntax::SimpleStatement::Declaration(d) => d.$mthd_name(visitor), syntax::SimpleStatement::Expression(e) => e.$mthd_name(visitor), syntax::SimpleStatement::Selection(s) => s.$mthd_name(visitor),