fix clippy warnings or disable unneeded lints
This commit is contained in:
parent
6af2c7c02c
commit
daa551caa3
10 changed files with 88 additions and 79 deletions
10
Cargo.toml
10
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"
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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:#?}");
|
||||
}
|
||||
|
|
18
src/lib.rs
Normal file
18
src/lib.rs
Normal file
|
@ -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<usize>;
|
25
src/main.rs
25
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<usize>;
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<r#type::Type, NsRegistrationError> {
|
||||
|
||||
/// 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<Type, NsRegistrationError> {
|
||||
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<Trait, NsRegistrationError> {
|
||||
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<r#type::Type> {
|
||||
if self.types.borrow().len() > id {
|
||||
Some(r#type::Type {
|
||||
pub fn get_type(&self, id: usize) -> Option<Type> {
|
||||
(self.types.borrow().len() > id).then_some(Type {
|
||||
id,
|
||||
namespace: self,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_trait(&self, id: usize) -> Option<Trait> {
|
||||
if self.traits.borrow().len() > id {
|
||||
Some(Trait {
|
||||
(self.traits.borrow().len() > id).then_some(Trait {
|
||||
id,
|
||||
namespace: self,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_command(&self, id: usize) -> Option<Command> {
|
||||
if self.commands.borrow().len() > id {
|
||||
Some(Command {
|
||||
(self.commands.borrow().len() > id).then_some(Command {
|
||||
id,
|
||||
namespace: self,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_type_by_name(&self, name: &str) -> Option<r#type::Type> {
|
||||
pub fn get_type_by_name(&self, name: &str) -> Option<Type> {
|
||||
if let Some(TypeNamespaceId::Types(id)) = self.type_namespace.borrow().get(name) {
|
||||
Some(r#type::Type {
|
||||
Some(Type {
|
||||
id: *id,
|
||||
namespace: self,
|
||||
})
|
||||
|
|
|
@ -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<logos::
|
|||
element,
|
||||
PipelineElement {
|
||||
kind: PipelineElementKind::Pipe,
|
||||
span: _
|
||||
..
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -169,14 +169,14 @@ fn check_literal_as_filter(syntax: &[PipelineElement]) -> Result<(), Vec<logos::
|
|||
return None;
|
||||
};
|
||||
|
||||
let Some(CommandPart { kind, span: _ }) = c.first() else {
|
||||
let Some(CommandPart { kind, .. }) = c.first() else {
|
||||
return None;
|
||||
};
|
||||
|
||||
if !matches!(kind, CommandPartKind::Word(_)) {
|
||||
Some(span)
|
||||
} else {
|
||||
if matches!(kind, CommandPartKind::Word(_)) {
|
||||
None
|
||||
} else {
|
||||
Some(span)
|
||||
}
|
||||
})
|
||||
.filter_map(|err| err.map(Clone::clone))
|
||||
|
@ -200,7 +200,7 @@ fn check_literal_with_args(syntax: &[PipelineElement]) -> Result<(), logos::Span
|
|||
c.first(),
|
||||
Some(CommandPart {
|
||||
kind: CommandPartKind::Word(_),
|
||||
span: _
|
||||
..
|
||||
})
|
||||
)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
use logos::Logos;
|
||||
use logos::Span;
|
||||
|
||||
|
@ -52,7 +50,9 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
|
|||
let span = partial_command.first().unwrap().span.start
|
||||
..partial_command.last().unwrap().span.end;
|
||||
r.push(PipelineElement {
|
||||
kind: PipelineElementKind::Command(std::mem::take(&mut partial_command)),
|
||||
kind: PipelineElementKind::Command(std::mem::take(
|
||||
&mut partial_command,
|
||||
)),
|
||||
span,
|
||||
});
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
|
|||
kind: CommandPartKind::String(string),
|
||||
span,
|
||||
}),
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
errs.push(span);
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue