Skip to content

Commit ca89a01

Browse files
alixinneAlexTMjugador
authored andcommitted
fix(cli): actually setup fs preprocessor
1 parent fba1694 commit ca89a01

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lang-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ categories = ["command-line-interface", "parser-implementations", "rendering"]
1414

1515
[dependencies]
1616
glsl-lang = { version = "=0.5.1", features = ["lexer-v2-full"] }
17+
glsl-lang-pp = { version = "=0.5.1" }
1718
lang-util = "=0.5.1"
1819
argh = "0.1"
1920

lang-cli/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
1616
#![deny(missing_docs)]
1717

18-
use std::io::prelude::*;
18+
use std::{io::prelude::*, path::Path};
1919

2020
use argh::FromArgs;
2121

2222
use glsl_lang::{
2323
ast::{NodeDisplay, TranslationUnit},
24-
parse::DefaultParse,
24+
lexer::v2_full::fs::PreprocessorExt,
25+
parse::IntoParseBuilderExt,
2526
};
2627

2728
fn output_text(output: &mut dyn std::io::Write, tu: TranslationUnit) -> std::io::Result<()> {
@@ -94,7 +95,20 @@ impl<I: std::error::Error> std::fmt::Display for ParseError<I> {
9495

9596
use miette::{NamedSource, Result};
9697
fn parse_tu(source: &str, path: &str) -> Result<glsl_lang::ast::TranslationUnit> {
97-
match glsl_lang::ast::TranslationUnit::parse(source) {
98+
let mut processor = glsl_lang_pp::processor::fs::StdProcessor::new();
99+
let tu: Result<glsl_lang::ast::TranslationUnit, _> = processor
100+
.open_source(
101+
source,
102+
Path::new(path).parent().unwrap_or_else(|| Path::new(".")),
103+
)
104+
.builder()
105+
.parse()
106+
.map(|(mut tu, _, iter)| {
107+
iter.into_directives().inject(&mut tu);
108+
tu
109+
});
110+
111+
match tu {
98112
Ok(tu) => Ok(tu),
99113
Err(err) => {
100114
let pos = err.pos();

0 commit comments

Comments
 (0)