-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f737724
commit d705b25
Showing
3 changed files
with
135 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,95 @@ | ||
use std::sync::Arc; | ||
|
||
use bevy_utils::HashMap; | ||
use gramatika::ArcStr; | ||
use gramatika::{ArcStr, SpannedError}; | ||
use lsp_types::Url; | ||
use parser::pre::{self, traversal::Walk}; | ||
|
||
use crate::{ | ||
documents::{IntakeError, WgslDocumentBundle}, | ||
pre::pruner::Pruner, | ||
use parser::{ | ||
comment::Comment, | ||
pre::{self, traversal::Walk}, | ||
scopes::Scope, | ||
ParseResult, ParseStreamer, SyntaxTree, Token, | ||
}; | ||
use ropey::Rope; | ||
|
||
use crate::{documents::WgslDocumentBundle, pre::pruner::Pruner}; | ||
|
||
mod interpreter; | ||
mod pruner; | ||
|
||
pub fn process( | ||
uri: Url, | ||
uri: &Url, | ||
source: ArcStr, | ||
defs: &HashMap<String, String>, | ||
) -> gramatika::Result<WgslDocumentBundle> { | ||
) -> gramatika::Result<( | ||
ArcStr, | ||
String, | ||
Vec<Token>, | ||
Vec<Comment>, | ||
Vec<SpannedError>, | ||
Arc<Scope>, | ||
SyntaxTree, | ||
)> { | ||
eprintln!(" Preprocessing {uri}"); | ||
|
||
let (parsed, source, pre_parse_errors) = pre::parse(source); | ||
|
||
let mut pruner = Pruner::new(source, defs.clone()); | ||
parsed.walk(&mut pruner); | ||
|
||
let text = pruner.write_output(); | ||
let pruned_source = pruner.write_output(); | ||
|
||
eprintln!(" Pruned source for {uri}:"); | ||
for (idx, line) in text.lines().enumerate() { | ||
for (idx, line) in pruned_source.lines().enumerate() { | ||
eprintln!(" {:>4} | {line}", idx + 1); | ||
} | ||
|
||
match WgslDocumentBundle::new(&text, uri.clone()) { | ||
Ok(mut bundle) => { | ||
bundle.errors.extend(pre_parse_errors); | ||
bundle.errors.extend(pruner.errors); | ||
|
||
Ok(bundle) | ||
} | ||
Err(error) => match error { | ||
IntakeError::NeedsPreprocessing(_, _, errors) => { | ||
Err(errors.into_iter().next().unwrap()) | ||
} | ||
}, | ||
} | ||
let mut parser = parser::ParseStream::from(&pruned_source); | ||
let tree = parser.parse::<SyntaxTree>()?; | ||
let ParseResult { | ||
tokens, | ||
comments, | ||
mut errors, | ||
.. | ||
} = parser.into_inner(); | ||
|
||
errors.extend(pre_parse_errors); | ||
errors.extend(pruner.errors); | ||
|
||
Ok(( | ||
// uri, | ||
pruner.source, | ||
pruned_source, | ||
tokens, | ||
comments, | ||
errors, | ||
parser::scopes::build(&tree), | ||
tree, | ||
)) | ||
|
||
// Ok(WgslDocumentBundle { | ||
// uri: uri.into(), | ||
// rope: Rope::new().into(), | ||
// source: pruner.source.into(), | ||
// tokens: tokens.into(), | ||
// comments: comments.into(), | ||
// errors: errors.into(), | ||
// scopes: parser::scopes::build(&tree).into(), | ||
// ast: tree.into(), | ||
// token_refs: Default::default(), | ||
// }) | ||
|
||
// match WgslDocumentBundle::new(&text, uri.clone()) { | ||
// Ok(mut bundle) => { | ||
// bundle.source = pruner.source.into(); | ||
// bundle.errors.extend(pre_parse_errors); | ||
// bundle.errors.extend(pruner.errors); | ||
|
||
// Ok(bundle) | ||
// } | ||
// Err(error) => match error { | ||
// IntakeError::NeedsPreprocessing(_, _, errors) => { | ||
// Err(errors.into_iter().next().unwrap()) | ||
// } | ||
// }, | ||
// } | ||
} |