summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 1b0ce7d..54f17a5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,6 @@
use std::{path::PathBuf, fs, process::exit};
-use pipeline::{Change, ChangeKind};
-use rnix::SyntaxNode;
-use rowan::{ast::AstNode, TextSize, NodeOrToken, TextRange};
+use pipeline::Change;
+use rowan::{ast::AstNode, NodeOrToken};
use clap::{arg, Parser};
#[allow(dead_code)]
@@ -50,10 +49,18 @@ fn main() {
exit(1);
}
+ let query = match parse.to_query() {
+ Err(es) => {
+ eprintln!("{}", es.join("\n"));
+ exit(1);
+ },
+ Ok(query) => query
+ };
+
// println!("{nexp:#?}");
if args.batchmode {
- batchmode::batchmode(args.path, parse, args.debug);
+ batchmode::batchmode(args.path, query, args.debug);
} else {
let (content, nexp) = match parse_nexp(&args.path[0]) {
Err(e) => {
@@ -63,7 +70,7 @@ fn main() {
Ok(exp) => exp
};
- let (changes, results) = parse.apply(&content, nexp.syntax().clone()).unwrap();
+ let (changes, results) = query.apply(&content, nexp.syntax().clone()).unwrap();
if args.debug {
println!("{changes:?}");
@@ -89,8 +96,9 @@ fn apply_changes(content: &str, mut changes: Vec<Change>, debug: bool) -> String
changes.sort_by_key(|change| change.node.text_range().start());
for change in changes {
+ use queries::Operator::*;
match change.kind {
- ChangeKind::Remove => {
+ Remove => {
let (before, after) = remove_node(&change.node);
if last_pos > before { continue }
ncontent += &content[last_pos..before];
@@ -99,7 +107,7 @@ fn apply_changes(content: &str, mut changes: Vec<Change>, debug: bool) -> String
}
last_pos = after;
}
- ChangeKind::Keep => {
+ Keep => {
let (before, after) = surrounding_noise(&change.node);
let (before, after) = eat_whitespace(&before, &after);
// let (before, after) = (change.node.text_range().start().into(), change.node.text_range().end().into());