diff --git a/Cargo.toml b/Cargo.toml index 72c190b..2291d53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ unneeded_field_pattern = "warn" unnested_or_patterns = "warn" allow_attributes_without_reason = "deny" -cast_lossles = "deny" +cast_lossless = "deny" fallible_impl_from = "deny" unnecessary_cast = "deny" unwrap_used = "deny" @@ -40,5 +40,11 @@ unwrap_used = "deny" expect_used = "allow" # must be allowed with clearly documented reasons -indexing_slicing = "warn" +indexing_slicing = "allow" +module_name_repetitions = "allow" +must_use_candidate = "allow" + +# TODO: more granular and clean +missing_panics_doc = "allow" +missing_errors_doc = "allow" diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 45c211b..ec7db4c 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -12,6 +12,7 @@ pub const CMD_ADD: &str = "add"; clippy::unwrap_used, reason = "Errs can only be returned in case of duplicate names in the same namespace, which will not happen here" )] +#[allow(clippy::missing_panics_doc, reason = "will not panic")] pub fn initialise_globals() -> GlobalNamespace { let ns = GlobalNamespace::init(); diff --git a/src/evaluator.rs b/src/evaluator.rs index 0cad793..ba0e002 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -49,10 +49,10 @@ impl<'a> Evaluator<'a> { } } - pub fn run(&mut self, input: String, name: Option<&'a str>) { - let fid = self.files.add(name.unwrap_or("input"), input.clone()); + pub fn run(&mut self, input: &str, name: Option<&'a str>) { + let fid = self.files.add(name.unwrap_or("input"), input.to_owned()); - let syntax = parse_syntax(&input); + let syntax = parse_syntax(input); if self.cfg.debug_raw_toks { println!("Raw tokens: {syntax:#?}"); } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b113d0f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,18 @@ +#![feature(never_type, lint_reasons)] + +use std::ops::Range; + +pub mod args; +pub mod builtins; +pub mod error; +pub mod evaluator; + +#[allow(clippy::indexing_slicing, reason = "in logos, outside our control")] +pub mod lexer; + +pub mod namespace; +pub mod syntax; +pub mod typed; + +// basically logos::Span but in this repo +pub type Span = Range; diff --git a/src/main.rs b/src/main.rs index c289f37..2727830 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,31 +1,12 @@ -#![feature(never_type, lint_reasons)] - -use std::ops::Range; - -use args::Args; use clap::Parser; -use evaluator::{EvalConfig, Evaluator}; - -mod args; -mod builtins; -mod error; -mod evaluator; - -#[allow(clippy::indexing_slicing, reason = "in logos, outside our control")] -mod lexer; - -mod namespace; -mod syntax; -mod typed; - -// basically logos::Span but in this repo -type Span = Range; +use pipeline_lang::args::Args; +use pipeline_lang::evaluator::{EvalConfig, Evaluator}; fn main() { let args = Args::parse(); let mut evaluator = Evaluator::init(EvalConfig::new(args.debug_tokens, args.debug_typed_repr)); - evaluator.run(args.text, None); + evaluator.run(&args.text, None); evaluator.next(); } diff --git a/src/namespace/command.rs b/src/namespace/command.rs index 4e8be09..40186d9 100644 --- a/src/namespace/command.rs +++ b/src/namespace/command.rs @@ -32,9 +32,9 @@ impl Display for Command<'_> { f.write_fmt(format_args!( "{name} {} -> {}", self.get_input_types() - .map_or("!".to_string(), |v| v.to_string()), + .map_or("!".to_owned(), |v| v.to_string()), self.get_output_types() - .map_or("!".to_string(), |v| v.to_string()) + .map_or("!".to_owned(), |v| v.to_string()) )) } } diff --git a/src/namespace/mod.rs b/src/namespace/mod.rs index 326bd6b..c8017e7 100644 --- a/src/namespace/mod.rs +++ b/src/namespace/mod.rs @@ -6,7 +6,7 @@ use std::{ use self::{ command::{Command, InternalCommand}, r#trait::{InternalTrait, Trait}, - r#type::InternalType, + r#type::{InternalType, Type}, typedef::TypeDef, }; @@ -30,6 +30,7 @@ enum TypeNamespaceId { enum DataNamespaceId { Commands(usize), + #[allow(dead_code, reason = "will be used later")] Globals(usize), } @@ -43,7 +44,13 @@ impl GlobalNamespace { data_namespace: RefCell::new(HashMap::new()), } } - pub fn register_type(&self, name: &str) -> Result { + + /// register a type to the namespace + /// + /// # Errors + /// + /// Will return `NsRegistrationError::NameAlreadyExists` if the desired name is already in use + pub fn register_type(&self, name: &str) -> Result { if self.type_namespace.borrow().contains_key(name) { Err(NsRegistrationError::NameAlreadyExists) } else { @@ -56,13 +63,18 @@ impl GlobalNamespace { .type_namespace .borrow_mut() .insert(name.to_owned(), TypeNamespaceId::Types(id)); - Ok(r#type::Type { + Ok(Type { id, namespace: self, }) } } + /// register a trait to the namespace + /// + /// # Errors + /// + /// Will return `NsRegistrationError::NameAlreadyExists` if the desired name is already in use pub fn register_trait(&self, name: &str) -> Result { if self.type_namespace.borrow().contains_key(name) { Err(NsRegistrationError::NameAlreadyExists) @@ -83,6 +95,11 @@ impl GlobalNamespace { } } + /// register a command to the namespace + /// + /// # Errors + /// + /// Will return `NsRegistrationError::NameAlreadyExists` if the desired name is already in use pub fn register_command( &self, name: &str, @@ -109,42 +126,30 @@ impl GlobalNamespace { } } - pub fn get_type(&self, id: usize) -> Option { - if self.types.borrow().len() > id { - Some(r#type::Type { - id, - namespace: self, - }) - } else { - None - } + pub fn get_type(&self, id: usize) -> Option { + (self.types.borrow().len() > id).then_some(Type { + id, + namespace: self, + }) } pub fn get_trait(&self, id: usize) -> Option { - if self.traits.borrow().len() > id { - Some(Trait { - id, - namespace: self, - }) - } else { - None - } + (self.traits.borrow().len() > id).then_some(Trait { + id, + namespace: self, + }) } pub fn get_command(&self, id: usize) -> Option { - if self.commands.borrow().len() > id { - Some(Command { - id, - namespace: self, - }) - } else { - None - } + (self.commands.borrow().len() > id).then_some(Command { + id, + namespace: self, + }) } - pub fn get_type_by_name(&self, name: &str) -> Option { + pub fn get_type_by_name(&self, name: &str) -> Option { if let Some(TypeNamespaceId::Types(id)) = self.type_namespace.borrow().get(name) { - Some(r#type::Type { + Some(Type { id: *id, namespace: self, }) diff --git a/src/syntax/check.rs b/src/syntax/check.rs index 4f2c701..ff5b76e 100644 --- a/src/syntax/check.rs +++ b/src/syntax/check.rs @@ -113,7 +113,7 @@ fn check_missing_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> { fn check_literal_as_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> { let last_block: Option<&[PipelineElement]> = syntax - .split(|PipelineElement { kind, span: _ }| kind == &PipelineElementKind::Pipe) + .split(|PipelineElement { kind, .. }| kind == &PipelineElementKind::Pipe) .last(); // there HAS to be a better way to do this... this is HORRIBLE @@ -124,16 +124,16 @@ fn check_literal_as_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> }) = last_block.first() { if let Some(first_part) = parts.first() { - if !matches!( + if matches!( first_part, CommandPart { kind: CommandPartKind::Word(_), - span: _ + .. } ) { - Err(span.clone()) - } else { Ok(()) + } else { + Err(span.clone()) } } else { Ok(()) @@ -156,7 +156,7 @@ fn check_literal_as_filter(syntax: &[PipelineElement]) -> Result<(), Vec Result<(), Vec Result<(), logos::Span c.first(), Some(CommandPart { kind: CommandPartKind::Word(_), - span: _ + .. }) ) { diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index a4a8481..cb4bbfd 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -1,5 +1,3 @@ - - use logos::Logos; use logos::Span; @@ -52,7 +50,9 @@ pub fn parse_syntax(input: &str) -> Result, Vec Result, Vec {} } } else { errs.push(span); diff --git a/src/typed.rs b/src/typed.rs index 2eafa95..764916e 100644 --- a/src/typed.rs +++ b/src/typed.rs @@ -8,6 +8,7 @@ use crate::{ Span, }; +#[allow(dead_code, reason = "will be used later")] #[derive(Debug)] pub struct Expr<'a> { kind: ExprKind<'a>, @@ -56,7 +57,7 @@ pub fn into_typed_repr( match kind { PipelineElementKind::Command(c) => { if c.len() == 1 { - let CommandPart { kind, span: _ } = &c[0]; + let CommandPart { kind, .. } = &c[0]; res.push(Expr { kind: match kind { @@ -105,14 +106,12 @@ pub fn into_typed_repr( .skip(1) .map(|CommandPart { kind, span }| Expr { kind: ExprKind::Literal(match kind { - CommandPartKind::Word(val) => { + CommandPartKind::String(val) + | CommandPartKind::Word(val) => { LiteralKind::String(val.to_string()) } CommandPartKind::Integer(val) => LiteralKind::Int(*val), CommandPartKind::Float(val) => LiteralKind::Float(*val), - CommandPartKind::String(val) => { - LiteralKind::String(val.to_string()) - } }), span: span.clone(), })