Skip to content

Commit

Permalink
fix(cli): actually setup fs preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
alixinne authored and AlexTMjugador committed Nov 11, 2023
1 parent fba1694 commit ca89a01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions lang-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["command-line-interface", "parser-implementations", "rendering"]

[dependencies]
glsl-lang = { version = "=0.5.1", features = ["lexer-v2-full"] }
glsl-lang-pp = { version = "=0.5.1" }
lang-util = "=0.5.1"
argh = "0.1"

Expand Down
20 changes: 17 additions & 3 deletions lang-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

#![deny(missing_docs)]

use std::io::prelude::*;
use std::{io::prelude::*, path::Path};

use argh::FromArgs;

use glsl_lang::{
ast::{NodeDisplay, TranslationUnit},
parse::DefaultParse,
lexer::v2_full::fs::PreprocessorExt,
parse::IntoParseBuilderExt,
};

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

use miette::{NamedSource, Result};
fn parse_tu(source: &str, path: &str) -> Result<glsl_lang::ast::TranslationUnit> {
match glsl_lang::ast::TranslationUnit::parse(source) {
let mut processor = glsl_lang_pp::processor::fs::StdProcessor::new();
let tu: Result<glsl_lang::ast::TranslationUnit, _> = processor
.open_source(
source,
Path::new(path).parent().unwrap_or_else(|| Path::new(".")),
)
.builder()
.parse()
.map(|(mut tu, _, iter)| {
iter.into_directives().inject(&mut tu);
tu
});

match tu {
Ok(tu) => Ok(tu),
Err(err) => {
let pos = err.pos();
Expand Down

0 comments on commit ca89a01

Please sign in to comment.