mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-24 06:18:44 +01:00
fix clippy warnings or disable unneeded lints
This commit is contained in:
parent
6af2c7c02c
commit
daa551caa3
10
Cargo.toml
10
Cargo.toml
|
@ -32,7 +32,7 @@ unneeded_field_pattern = "warn"
|
||||||
unnested_or_patterns = "warn"
|
unnested_or_patterns = "warn"
|
||||||
|
|
||||||
allow_attributes_without_reason = "deny"
|
allow_attributes_without_reason = "deny"
|
||||||
cast_lossles = "deny"
|
cast_lossless = "deny"
|
||||||
fallible_impl_from = "deny"
|
fallible_impl_from = "deny"
|
||||||
unnecessary_cast = "deny"
|
unnecessary_cast = "deny"
|
||||||
unwrap_used = "deny"
|
unwrap_used = "deny"
|
||||||
|
@ -40,5 +40,11 @@ unwrap_used = "deny"
|
||||||
expect_used = "allow"
|
expect_used = "allow"
|
||||||
|
|
||||||
# must be allowed with clearly documented reasons
|
# 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,
|
clippy::unwrap_used,
|
||||||
reason = "Errs can only be returned in case of duplicate names in the same namespace, which will not happen here"
|
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 {
|
pub fn initialise_globals() -> GlobalNamespace {
|
||||||
let ns = GlobalNamespace::init();
|
let ns = GlobalNamespace::init();
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,10 @@ impl<'a> Evaluator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self, input: String, name: Option<&'a str>) {
|
pub fn run(&mut self, input: &str, name: Option<&'a str>) {
|
||||||
let fid = self.files.add(name.unwrap_or("input"), input.clone());
|
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 {
|
if self.cfg.debug_raw_toks {
|
||||||
println!("Raw tokens: {syntax:#?}");
|
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 clap::Parser;
|
||||||
use evaluator::{EvalConfig, Evaluator};
|
use pipeline_lang::args::Args;
|
||||||
|
use pipeline_lang::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>;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let mut evaluator = Evaluator::init(EvalConfig::new(args.debug_tokens, args.debug_typed_repr));
|
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();
|
evaluator.next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ impl Display for Command<'_> {
|
||||||
f.write_fmt(format_args!(
|
f.write_fmt(format_args!(
|
||||||
"{name} {} -> {}",
|
"{name} {} -> {}",
|
||||||
self.get_input_types()
|
self.get_input_types()
|
||||||
.map_or("!".to_string(), |v| v.to_string()),
|
.map_or("!".to_owned(), |v| v.to_string()),
|
||||||
self.get_output_types()
|
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::{
|
use self::{
|
||||||
command::{Command, InternalCommand},
|
command::{Command, InternalCommand},
|
||||||
r#trait::{InternalTrait, Trait},
|
r#trait::{InternalTrait, Trait},
|
||||||
r#type::InternalType,
|
r#type::{InternalType, Type},
|
||||||
typedef::TypeDef,
|
typedef::TypeDef,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ enum TypeNamespaceId {
|
||||||
|
|
||||||
enum DataNamespaceId {
|
enum DataNamespaceId {
|
||||||
Commands(usize),
|
Commands(usize),
|
||||||
|
#[allow(dead_code, reason = "will be used later")]
|
||||||
Globals(usize),
|
Globals(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +44,13 @@ impl GlobalNamespace {
|
||||||
data_namespace: RefCell::new(HashMap::new()),
|
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) {
|
if self.type_namespace.borrow().contains_key(name) {
|
||||||
Err(NsRegistrationError::NameAlreadyExists)
|
Err(NsRegistrationError::NameAlreadyExists)
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,13 +63,18 @@ impl GlobalNamespace {
|
||||||
.type_namespace
|
.type_namespace
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(name.to_owned(), TypeNamespaceId::Types(id));
|
.insert(name.to_owned(), TypeNamespaceId::Types(id));
|
||||||
Ok(r#type::Type {
|
Ok(Type {
|
||||||
id,
|
id,
|
||||||
namespace: self,
|
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> {
|
pub fn register_trait(&self, name: &str) -> Result<Trait, NsRegistrationError> {
|
||||||
if self.type_namespace.borrow().contains_key(name) {
|
if self.type_namespace.borrow().contains_key(name) {
|
||||||
Err(NsRegistrationError::NameAlreadyExists)
|
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(
|
pub fn register_command(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
|
@ -109,42 +126,30 @@ impl GlobalNamespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_type(&self, id: usize) -> Option<r#type::Type> {
|
pub fn get_type(&self, id: usize) -> Option<Type> {
|
||||||
if self.types.borrow().len() > id {
|
(self.types.borrow().len() > id).then_some(Type {
|
||||||
Some(r#type::Type {
|
|
||||||
id,
|
id,
|
||||||
namespace: self,
|
namespace: self,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_trait(&self, id: usize) -> Option<Trait> {
|
pub fn get_trait(&self, id: usize) -> Option<Trait> {
|
||||||
if self.traits.borrow().len() > id {
|
(self.traits.borrow().len() > id).then_some(Trait {
|
||||||
Some(Trait {
|
|
||||||
id,
|
id,
|
||||||
namespace: self,
|
namespace: self,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(&self, id: usize) -> Option<Command> {
|
pub fn get_command(&self, id: usize) -> Option<Command> {
|
||||||
if self.commands.borrow().len() > id {
|
(self.commands.borrow().len() > id).then_some(Command {
|
||||||
Some(Command {
|
|
||||||
id,
|
id,
|
||||||
namespace: self,
|
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) {
|
if let Some(TypeNamespaceId::Types(id)) = self.type_namespace.borrow().get(name) {
|
||||||
Some(r#type::Type {
|
Some(Type {
|
||||||
id: *id,
|
id: *id,
|
||||||
namespace: self,
|
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> {
|
fn check_literal_as_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> {
|
||||||
let last_block: Option<&[PipelineElement]> = syntax
|
let last_block: Option<&[PipelineElement]> = syntax
|
||||||
.split(|PipelineElement { kind, span: _ }| kind == &PipelineElementKind::Pipe)
|
.split(|PipelineElement { kind, .. }| kind == &PipelineElementKind::Pipe)
|
||||||
.last();
|
.last();
|
||||||
|
|
||||||
// there HAS to be a better way to do this... this is HORRIBLE
|
// 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()
|
}) = last_block.first()
|
||||||
{
|
{
|
||||||
if let Some(first_part) = parts.first() {
|
if let Some(first_part) = parts.first() {
|
||||||
if !matches!(
|
if matches!(
|
||||||
first_part,
|
first_part,
|
||||||
CommandPart {
|
CommandPart {
|
||||||
kind: CommandPartKind::Word(_),
|
kind: CommandPartKind::Word(_),
|
||||||
span: _
|
..
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Err(span.clone())
|
|
||||||
} else {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(span.clone())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -156,7 +156,7 @@ fn check_literal_as_filter(syntax: &[PipelineElement]) -> Result<(), Vec<logos::
|
||||||
element,
|
element,
|
||||||
PipelineElement {
|
PipelineElement {
|
||||||
kind: PipelineElementKind::Pipe,
|
kind: PipelineElementKind::Pipe,
|
||||||
span: _
|
..
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -169,14 +169,14 @@ fn check_literal_as_filter(syntax: &[PipelineElement]) -> Result<(), Vec<logos::
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(CommandPart { kind, span: _ }) = c.first() else {
|
let Some(CommandPart { kind, .. }) = c.first() else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
if !matches!(kind, CommandPartKind::Word(_)) {
|
if matches!(kind, CommandPartKind::Word(_)) {
|
||||||
Some(span)
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
Some(span)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter_map(|err| err.map(Clone::clone))
|
.filter_map(|err| err.map(Clone::clone))
|
||||||
|
@ -200,7 +200,7 @@ fn check_literal_with_args(syntax: &[PipelineElement]) -> Result<(), logos::Span
|
||||||
c.first(),
|
c.first(),
|
||||||
Some(CommandPart {
|
Some(CommandPart {
|
||||||
kind: CommandPartKind::Word(_),
|
kind: CommandPartKind::Word(_),
|
||||||
span: _
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
use logos::Logos;
|
use logos::Logos;
|
||||||
use logos::Span;
|
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
|
let span = partial_command.first().unwrap().span.start
|
||||||
..partial_command.last().unwrap().span.end;
|
..partial_command.last().unwrap().span.end;
|
||||||
r.push(PipelineElement {
|
r.push(PipelineElement {
|
||||||
kind: PipelineElementKind::Command(std::mem::take(&mut partial_command)),
|
kind: PipelineElementKind::Command(std::mem::take(
|
||||||
|
&mut partial_command,
|
||||||
|
)),
|
||||||
span,
|
span,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ pub fn parse_syntax(input: &str) -> Result<Vec<PipelineElement>, Vec<logos::Span
|
||||||
kind: CommandPartKind::String(string),
|
kind: CommandPartKind::String(string),
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errs.push(span);
|
errs.push(span);
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
||||||
Span,
|
Span,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(dead_code, reason = "will be used later")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Expr<'a> {
|
pub struct Expr<'a> {
|
||||||
kind: ExprKind<'a>,
|
kind: ExprKind<'a>,
|
||||||
|
@ -56,7 +57,7 @@ pub fn into_typed_repr(
|
||||||
match kind {
|
match kind {
|
||||||
PipelineElementKind::Command(c) => {
|
PipelineElementKind::Command(c) => {
|
||||||
if c.len() == 1 {
|
if c.len() == 1 {
|
||||||
let CommandPart { kind, span: _ } = &c[0];
|
let CommandPart { kind, .. } = &c[0];
|
||||||
|
|
||||||
res.push(Expr {
|
res.push(Expr {
|
||||||
kind: match kind {
|
kind: match kind {
|
||||||
|
@ -105,14 +106,12 @@ pub fn into_typed_repr(
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.map(|CommandPart { kind, span }| Expr {
|
.map(|CommandPart { kind, span }| Expr {
|
||||||
kind: ExprKind::Literal(match kind {
|
kind: ExprKind::Literal(match kind {
|
||||||
CommandPartKind::Word(val) => {
|
CommandPartKind::String(val)
|
||||||
|
| CommandPartKind::Word(val) => {
|
||||||
LiteralKind::String(val.to_string())
|
LiteralKind::String(val.to_string())
|
||||||
}
|
}
|
||||||
CommandPartKind::Integer(val) => LiteralKind::Int(*val),
|
CommandPartKind::Integer(val) => LiteralKind::Int(*val),
|
||||||
CommandPartKind::Float(val) => LiteralKind::Float(*val),
|
CommandPartKind::Float(val) => LiteralKind::Float(*val),
|
||||||
CommandPartKind::String(val) => {
|
|
||||||
LiteralKind::String(val.to_string())
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
span: span.clone(),
|
span: span.clone(),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue