added basic method to check syntax command input

This commit is contained in:
Schrottkatze 2023-11-18 19:46:41 +01:00
parent 03412ce8cd
commit 3952091018
6 changed files with 251 additions and 7 deletions

11
src/args.rs Normal file
View file

@ -0,0 +1,11 @@
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
pub text: String,
#[arg(long)]
pub debug_tokens: bool,
}

View file

@ -1,6 +1,61 @@
use args::Args;
use clap::Parser;
use codespan_reporting::{
files::{SimpleFile, SimpleFiles},
term::{
self,
termcolor::{ColorChoice, StandardStream},
},
};
use syntax::{
check::{self, check},
error::SyntaxError,
parse_syntax, PipelineElement,
};
mod args;
mod builtins;
mod lexer;
mod namespace;
mod syntax;
fn main() {}
fn main() {
let args = dbg!(Args::parse());
let syntax = parse_syntax(&args.text);
if args.debug_tokens {
println!("Tokens: {syntax:#?}");
}
let mut files = SimpleFiles::new();
let input_id = files.add("input", args.text);
let writer = StandardStream::stderr(ColorChoice::Always);
let config = term::Config::default();
if let Err(errs) = syntax {
let writer = &mut writer.lock();
term::emit(
writer,
&config,
&files,
&SyntaxError::InvalidToken(errs).to_diagnostic(input_id),
)
.unwrap();
} else {
let check_res = check(&syntax.unwrap());
if let Err(errs) = check_res {
let writer = &mut writer.lock();
let diags = errs.into_iter().map(|err| err.to_diagnostic(input_id));
for diag in diags {
term::emit(writer, &config, &files, &diag);
}
}
}
}

View file

@ -4,10 +4,8 @@ use super::{
};
pub fn check(
syntax: Vec<PipelineElement>,
raw_source: &str,
file_id: FileId,
) -> Result<Vec<PipelineElement>, Vec<SyntaxError>> {
syntax: &Vec<PipelineElement>,
) -> Result<(), Vec<SyntaxError>> {
let mut errs = Vec::new();
if let Err(e_span) = check_missing_streamer(&syntax) {
@ -23,7 +21,7 @@ pub fn check(
}
if errs.is_empty() {
Ok(syntax)
Ok(())
} else {
Err(errs)
}

View file

@ -6,7 +6,7 @@ use logos::Span;
use crate::lexer::Token;
pub mod check;
mod error;
pub mod error;
#[derive(Debug, Clone, PartialEq)]
pub struct PipelineElement {