Skip to content

Commit

Permalink
fix a bunch of more things
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed May 19, 2024
1 parent f2686a4 commit 429b5a7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 47 deletions.
2 changes: 2 additions & 0 deletions benches/tree_construction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]

use criterion::{criterion_group, criterion_main, Criterion};
use gosub_testing::testing::tree_construction;
use gosub_testing::testing::tree_construction::Harness;
Expand Down
1 change: 1 addition & 0 deletions benches/tree_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::fs::File;

use criterion::{criterion_group, criterion_main, Criterion};
Expand Down
36 changes: 18 additions & 18 deletions crates/gosub_css3/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl Css3<'_> {
let t = self.tokenizer.consume();
if t.token_type != *token_type {
return Err(Error::new(
format!("Expected {:?}, got {:?}", token_type, t),
self.tokenizer.current_location().clone(),
format!("Expected {token_type:?}, got {t:?}"),
self.tokenizer.current_location(),
));
}

Expand All @@ -43,8 +43,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Function(name) => Ok(name),
_ => Err(Error::new(
format!("Expected function, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected function, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -54,8 +54,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Number(value) => Ok(value),
_ => Err(Error::new(
format!("Expected number, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected number, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -65,8 +65,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Delim(c) => Ok(c),
_ => Err(Error::new(
format!("Expected delimiter, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected delimiter, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -76,8 +76,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::QuotedString(s) => Ok(s),
_ => Err(Error::new(
format!("Expected string, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected string, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -87,8 +87,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Delim(c) if c == delimiter => Ok(c),
_ => Err(Error::new(
format!("Expected delimiter '{}', got {:?}", delimiter, t),
self.tokenizer.current_location().clone(),
format!("Expected delimiter '{delimiter}', got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -113,8 +113,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Ident(s) if s.eq_ignore_ascii_case(ident) => Ok(s),
_ => Err(Error::new(
format!("Expected ident, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected ident, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -124,8 +124,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Ident(s) if s == ident => Ok(s),
_ => Err(Error::new(
format!("Expected ident, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected ident, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand All @@ -135,8 +135,8 @@ impl Css3<'_> {
match t.token_type {
TokenType::Ident(s) => Ok(s),
_ => Err(Error::new(
format!("Expected ident, got {:?}", t),
self.tokenizer.current_location().clone(),
format!("Expected ident, got {t:?}"),
self.tokenizer.current_location(),
)),
}
}
Expand Down
36 changes: 15 additions & 21 deletions crates/gosub_css3/src/parser/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ impl Css3<'_> {
while !self.tokenizer.eof() {
let t = self.consume_any()?;
match t.token_type {
TokenType::Comment(_) => {
// eat token
}
TokenType::Whitespace => {
TokenType::Comment(_) | TokenType::Whitespace => {
// eat token
}
_ => {
Expand All @@ -26,7 +23,10 @@ impl Css3<'_> {
if child.is_none() {
break;
}
let child = child.unwrap();
let child = child.ok_or(Error::new(
"Expected value, got none".into(),
self.tokenizer.current_location(),
))?;
children.push(child);
}

Expand All @@ -46,7 +46,7 @@ impl Css3<'_> {
TokenType::IDHash(value) => {
let node = Node::new(
NodeType::Ident {
value: format!("#{}", value),
value: format!("#{value}"),
},
t.location,
);
Expand Down Expand Up @@ -118,32 +118,26 @@ impl Css3<'_> {
self.consume_delim('=')?;
let t = self.consume_any()?;
let node = match t.token_type {
TokenType::QuotedString(default_value) => Node::new(
TokenType::QuotedString(default_value)
| TokenType::Ident(default_value) => Node::new(
NodeType::MSIdent {
value: value.to_string(),
value,
default_value,
},
t.location,
),
TokenType::Number(default_value) => Node::new(
NodeType::MSIdent {
value: value.to_string(),
default_value: default_value.to_string(),
},
t.location,
),
TokenType::Ident(default_value) => Node::new(
NodeType::MSIdent {
value,
default_value,
default_value: default_value.to_string(),
},
t.location,
),
_ => {
return Err(Error::new(
format!("Expected number or ident, got {:?}", t),
self.tokenizer.current_location().clone(),
))
format!("Expected number or ident, got {t:?}"),
self.tokenizer.current_location(),
));
}
};

Expand All @@ -165,8 +159,8 @@ impl Css3<'_> {
Ok(Some(node))
}
'#' => Err(Error::new(
format!("Unexpected token {:?}", t),
self.tokenizer.current_location().clone(),
format!("Unexpected token {t:?}"),
self.tokenizer.current_location(),
)),
_ => {
self.tokenizer.reconsume();
Expand Down
14 changes: 6 additions & 8 deletions crates/gosub_jsapi/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ impl Console {
return;
}

let start = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => n.as_millis(),
Err(_) => 0,
};
let start = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |n| n.as_millis());

self.timer_map.insert(
label.to_owned(),
Expand Down Expand Up @@ -269,10 +268,9 @@ impl Console {

/// End the timer with the given label
pub fn time_end(&mut self, label: &str) {
let end = match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => n.as_millis(),
Err(_) => 0,
};
let end = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |n| n.as_millis());

let concat = format!(
"{}: {}ms",
Expand Down

0 comments on commit 429b5a7

Please sign in to comment.