1
0

Run clippy and prettier

This commit is contained in:
Jeff 2024-01-23 17:08:26 -05:00
parent e4bd0a51d6
commit 9299131024
7 changed files with 42 additions and 40 deletions

View File

@ -92,7 +92,7 @@ impl Format for For {
self.item_id.format(output, indent_level); self.item_id.format(output, indent_level);
output.push_str(" in "); output.push_str(" in ");
self.collection.format(output, indent_level); self.collection.format(output, indent_level);
output.push_str(" "); output.push(' ');
self.block.format(output, indent_level); self.block.format(output, indent_level);
} }
} }

View File

@ -16,7 +16,7 @@ impl AbstractTree for New {
let identifier_node = node.child(1).unwrap(); let identifier_node = node.child(1).unwrap();
let identifier = Identifier::from_syntax(identifier_node, source, context)?; let identifier = Identifier::from_syntax(identifier_node, source, context)?;
let mut properties = Vec::new(); let properties = Vec::new();
Ok(New { Ok(New {
identifier, identifier,
@ -24,17 +24,17 @@ impl AbstractTree for New {
}) })
} }
fn run(&self, source: &str, context: &crate::Map) -> crate::Result<Value> { fn run(&self, _source: &str, _context: &crate::Map) -> crate::Result<Value> {
todo!() todo!()
} }
fn expected_type(&self, context: &crate::Map) -> crate::Result<Type> { fn expected_type(&self, _context: &crate::Map) -> crate::Result<Type> {
todo!() todo!()
} }
} }
impl Format for New { impl Format for New {
fn format(&self, output: &mut String, indent_level: u8) { fn format(&self, _output: &mut String, _indent_level: u8) {
todo!() todo!()
} }
} }

View File

@ -62,7 +62,7 @@ impl BuiltInFunction {
BuiltInFunction::AssertEqual => { BuiltInFunction::AssertEqual => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let left = arguments.get(0).unwrap(); let left = arguments.first().unwrap();
let right = arguments.get(1).unwrap(); let right = arguments.get(1).unwrap();
Ok(Value::Boolean(left == right)) Ok(Value::Boolean(left == right))
@ -79,7 +79,7 @@ impl BuiltInFunction {
Error::expect_argument_amount(self.name(), 1, arguments.len())?; Error::expect_argument_amount(self.name(), 1, arguments.len())?;
let string = arguments.first().unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let value = serde_json::from_str(&string)?; let value = serde_json::from_str(string)?;
Ok(value) Ok(value)
} }

View File

@ -179,7 +179,7 @@ impl StringFunction {
StringFunction::EndsWith => { StringFunction::EndsWith => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
@ -188,7 +188,7 @@ impl StringFunction {
StringFunction::Find => { StringFunction::Find => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let find = string let find = string
@ -214,11 +214,11 @@ impl StringFunction {
StringFunction::Insert => { StringFunction::Insert => {
Error::expect_argument_amount(self.name(), 3, arguments.len())?; Error::expect_argument_amount(self.name(), 3, arguments.len())?;
let mut string = arguments.get(0).unwrap().as_string()?.clone(); let mut string = arguments.first().unwrap().as_string()?.clone();
let index = arguments.get(1).unwrap().as_integer()? as usize; let index = arguments.get(1).unwrap().as_integer()? as usize;
let insertion = arguments.get(2).unwrap().as_string()?; let insertion = arguments.get(2).unwrap().as_string()?;
string.insert_str(index, &insertion); string.insert_str(index, insertion);
Value::String(string) Value::String(string)
} }
@ -236,7 +236,7 @@ impl StringFunction {
StringFunction::Matches => { StringFunction::Matches => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let matches = string let matches = string
@ -262,11 +262,11 @@ impl StringFunction {
StringFunction::Remove => { StringFunction::Remove => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let index = arguments.get(1).unwrap().as_integer()? as usize; let index = arguments.get(1).unwrap().as_integer()? as usize;
let chars = string.chars().collect::<Vec<char>>(); let chars = string.chars().collect::<Vec<char>>();
if index <= chars.len() - 1 { if index < chars.len() {
let new_string = chars let new_string = chars
.iter() .iter()
.map(|char| char.to_string()) .map(|char| char.to_string())
@ -280,20 +280,20 @@ impl StringFunction {
StringFunction::ReplaceRange => { StringFunction::ReplaceRange => {
Error::expect_argument_amount(self.name(), 3, arguments.len())?; Error::expect_argument_amount(self.name(), 3, arguments.len())?;
let mut string = arguments.get(0).unwrap().as_string()?.clone(); let mut string = arguments.first().unwrap().as_string()?.clone();
let range = arguments.get(1).unwrap().as_list()?.items(); let range = arguments.get(1).unwrap().as_list()?.items();
let start = range.get(0).unwrap_or_default().as_integer()? as usize; let start = range.first().unwrap_or_default().as_integer()? as usize;
let end = range.get(1).unwrap_or_default().as_integer()? as usize; let end = range.get(1).unwrap_or_default().as_integer()? as usize;
let pattern = arguments.get(2).unwrap().as_string()?; let pattern = arguments.get(2).unwrap().as_string()?;
string.replace_range(start..end, &pattern); string.replace_range(start..end, pattern);
Value::String(string) Value::String(string)
} }
StringFunction::Retain => { StringFunction::Retain => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let mut string = arguments.get(0).unwrap().as_string()?.clone(); let mut string = arguments.first().unwrap().as_string()?.clone();
let predicate = arguments.get(1).unwrap().as_function()?; let predicate = arguments.get(1).unwrap().as_function()?;
string.retain(|char| { string.retain(|char| {
@ -309,7 +309,7 @@ impl StringFunction {
StringFunction::Split => { StringFunction::Split => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let sections = string let sections = string
@ -322,7 +322,7 @@ impl StringFunction {
StringFunction::SplitAt => { StringFunction::SplitAt => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let index = arguments.get(1).unwrap().as_integer()?; let index = arguments.get(1).unwrap().as_integer()?;
let (left, right) = string.split_at(index as usize); let (left, right) = string.split_at(index as usize);
@ -334,7 +334,7 @@ impl StringFunction {
StringFunction::SplitInclusive => { StringFunction::SplitInclusive => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let sections = string let sections = string
@ -347,7 +347,7 @@ impl StringFunction {
StringFunction::SplitN => { StringFunction::SplitN => {
Error::expect_argument_amount(self.name(), 3, arguments.len())?; Error::expect_argument_amount(self.name(), 3, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let count = arguments.get(1).unwrap().as_integer()?; let count = arguments.get(1).unwrap().as_integer()?;
let pattern_string = arguments.get(2).unwrap().as_string()?; let pattern_string = arguments.get(2).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
@ -361,7 +361,7 @@ impl StringFunction {
StringFunction::SplitOnce => { StringFunction::SplitOnce => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let sections = string.split_once(pattern).map(|(left, right)| { let sections = string.split_once(pattern).map(|(left, right)| {
@ -376,7 +376,7 @@ impl StringFunction {
StringFunction::SplitTerminator => { StringFunction::SplitTerminator => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let sections = string let sections = string
@ -389,7 +389,7 @@ impl StringFunction {
StringFunction::SplitWhitespace => { StringFunction::SplitWhitespace => {
Error::expect_argument_amount(self.name(), 1, arguments.len())?; Error::expect_argument_amount(self.name(), 1, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let sections = string let sections = string
.split_whitespace() .split_whitespace()
.map(|section| Value::string(section.to_string())) .map(|section| Value::string(section.to_string()))
@ -400,7 +400,7 @@ impl StringFunction {
StringFunction::StartsWith => { StringFunction::StartsWith => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
@ -409,7 +409,7 @@ impl StringFunction {
StringFunction::StripPrefix => { StringFunction::StripPrefix => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let prefix_string = arguments.get(1).unwrap().as_string()?; let prefix_string = arguments.get(1).unwrap().as_string()?;
let prefix = prefix_string.as_str(); let prefix = prefix_string.as_str();
let stripped = string let stripped = string
@ -421,7 +421,7 @@ impl StringFunction {
StringFunction::ToLowercase => { StringFunction::ToLowercase => {
Error::expect_argument_amount(self.name(), 1, arguments.len())?; Error::expect_argument_amount(self.name(), 1, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let lowercase = string.to_lowercase(); let lowercase = string.to_lowercase();
Value::string(lowercase) Value::string(lowercase)
@ -429,7 +429,7 @@ impl StringFunction {
StringFunction::ToUppercase => { StringFunction::ToUppercase => {
Error::expect_argument_amount(self.name(), 1, arguments.len())?; Error::expect_argument_amount(self.name(), 1, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let uppercase = string.to_uppercase(); let uppercase = string.to_uppercase();
Value::string(uppercase) Value::string(uppercase)
@ -456,7 +456,7 @@ impl StringFunction {
StringFunction::TrimEndMatches => { StringFunction::TrimEndMatches => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?;
let pattern = pattern_string.as_str(); let pattern = pattern_string.as_str();
let trimmed = string.trim_end_matches(pattern).to_string(); let trimmed = string.trim_end_matches(pattern).to_string();
@ -466,7 +466,7 @@ impl StringFunction {
StringFunction::TrimMatches => { StringFunction::TrimMatches => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern = arguments let pattern = arguments
.get(1) .get(1)
.unwrap() .unwrap()
@ -492,7 +492,7 @@ impl StringFunction {
StringFunction::TrimStartMatches => { StringFunction::TrimStartMatches => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let string = arguments.get(0).unwrap().as_string()?; let string = arguments.first().unwrap().as_string()?;
let pattern = arguments let pattern = arguments
.get(1) .get(1)
.unwrap() .unwrap()
@ -506,7 +506,7 @@ impl StringFunction {
StringFunction::Truncate => { StringFunction::Truncate => {
Error::expect_argument_amount(self.name(), 2, arguments.len())?; Error::expect_argument_amount(self.name(), 2, arguments.len())?;
let input_string = arguments.get(0).unwrap().as_string()?; let input_string = arguments.first().unwrap().as_string()?;
let new_length = arguments.get(1).unwrap().as_integer()? as usize; let new_length = arguments.get(1).unwrap().as_integer()? as usize;
let new_string = input_string let new_string = input_string

View File

@ -54,7 +54,9 @@ impl Value {
} }
pub fn r#type(&self) -> Type { pub fn r#type(&self) -> Type {
let r#type = match self {
match self {
Value::List(list) => { Value::List(list) => {
let mut previous_type = None; let mut previous_type = None;
@ -101,9 +103,7 @@ impl Value {
} }
} }
Value::TypeDefinition(_) => todo!(), Value::TypeDefinition(_) => todo!(),
}; }
r#type
} }
pub fn none() -> Self { pub fn none() -> Self {
@ -115,7 +115,7 @@ impl Value {
} }
pub fn option(option: Option<Value>) -> Self { pub fn option(option: Option<Value>) -> Self {
Value::Option(option.map(|value| Box::new(value))) Value::Option(option.map(Box::new))
} }
pub fn is_string(&self) -> bool { pub fn is_string(&self) -> bool {

View File

@ -18,7 +18,7 @@ fn argument_count_check() {
} }
foo() foo()
"; ";
let result = interpret(&source); let result = interpret(source);
assert_eq!( assert_eq!(
"Expected 1 arguments, but got 0. Occured at (5, 12) to (5, 17). Source: foo()", "Expected 1 arguments, but got 0. Occured at (5, 12) to (5, 17). Source: foo()",

View File

@ -224,7 +224,9 @@ module.exports = grammar({
repeat1( repeat1(
seq( seq(
$.identifier, $.identifier,
optional($.type_specification), optional(
$.type_specification,
),
'=', '=',
$.statement, $.statement,
optional(','), optional(','),