Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Apr 21, 2024
1 parent 646ffda commit 0633c4f
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 77 deletions.
12 changes: 6 additions & 6 deletions huff_cli/src/huffc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ fn main() {
// Check that constant override argument is valid
// Key rule: Alphabetic chars + underscore
// Value rule: Valid literal string (0x...)
if parts.len() != 2
|| parts[0].chars().any(|c| !(c.is_alphabetic() || c == '_'))
|| !parts[1].starts_with("0x")
|| parts[1][2..].chars().any(|c| {
!(c.is_numeric()
|| matches!(c, '\u{0041}'..='\u{0046}' | '\u{0061}'..='\u{0066}'))
if parts.len() != 2 ||
parts[0].chars().any(|c| !(c.is_alphabetic() || c == '_')) ||
!parts[1].starts_with("0x") ||
parts[1][2..].chars().any(|c| {
!(c.is_numeric() ||
matches!(c, '\u{0041}'..='\u{0046}' | '\u{0061}'..='\u{0066}'))
})
{
eprintln!("Invalid constant override argument: {}", Paint::red(c.to_string()));
Expand Down
4 changes: 2 additions & 2 deletions huff_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ impl<'a, 'l> Compiler<'a, 'l> {
Err(mut e) => {
// Return any errors except if the inputs is empty and the constructor
// definition is missing
if e.kind != CodegenErrorKind::MissingMacroDefinition("CONSTRUCTOR".to_string())
|| !inputs.is_empty()
if e.kind != CodegenErrorKind::MissingMacroDefinition("CONSTRUCTOR".to_string()) ||
!inputs.is_empty()
{
// Add File Source to Span
let mut errs = e
Expand Down
6 changes: 3 additions & 3 deletions huff_core/tests/parser_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ fn test_invalid_token_in_label_definition() {
fn test_invalid_single_arg() {
for _ in 0..10_000 {
let random_char = rand::random::<u8>() as char;
if random_char.is_numeric()
|| !random_char.is_alphabetic()
|| random_char.to_string().as_bytes().len() > 1
if random_char.is_numeric() ||
!random_char.is_alphabetic() ||
random_char.to_string().as_bytes().len() > 1
{
continue;
}
Expand Down
32 changes: 16 additions & 16 deletions huff_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ impl<'a> Lexer<'a> {

let kind = if let Some(kind) = &found_kind {
kind.clone()
} else if self.context == Context::MacroBody
&& BuiltinFunctionKind::try_from(&word).is_ok()
} else if self.context == Context::MacroBody &&
BuiltinFunctionKind::try_from(&word).is_ok()
{
TokenKind::BuiltinFunction(word)
} else {
Expand Down Expand Up @@ -542,20 +542,20 @@ impl<'a> Lexer<'a> {
/// by a colon or preceded by the keyword `function`
pub fn check_keyword_rules(&mut self, found_kind: &Option<TokenKind>) -> bool {
match found_kind {
Some(TokenKind::Macro)
| Some(TokenKind::Fn)
| Some(TokenKind::Test)
| Some(TokenKind::Function)
| Some(TokenKind::Constant)
| Some(TokenKind::Error)
| Some(TokenKind::Event)
| Some(TokenKind::JumpTable)
| Some(TokenKind::JumpTablePacked)
| Some(TokenKind::CodeTable) => self.checked_lookback(TokenKind::Define),
Some(TokenKind::NonPayable)
| Some(TokenKind::Payable)
| Some(TokenKind::View)
| Some(TokenKind::Pure) => {
Some(TokenKind::Macro) |
Some(TokenKind::Fn) |
Some(TokenKind::Test) |
Some(TokenKind::Function) |
Some(TokenKind::Constant) |
Some(TokenKind::Error) |
Some(TokenKind::Event) |
Some(TokenKind::JumpTable) |
Some(TokenKind::JumpTablePacked) |
Some(TokenKind::CodeTable) => self.checked_lookback(TokenKind::Define),
Some(TokenKind::NonPayable) |
Some(TokenKind::Payable) |
Some(TokenKind::View) |
Some(TokenKind::Pure) => {
let keys = [
TokenKind::NonPayable,
TokenKind::Payable,
Expand Down
14 changes: 7 additions & 7 deletions huff_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ impl Parser {
pub fn parse_label(&mut self) -> Result<Vec<Statement>, ParserError> {
let mut statements: Vec<Statement> = Vec::new();
self.match_kind(TokenKind::Colon)?;
while !self.check(TokenKind::Label("NEXT_LABEL".to_string()))
&& !self.check(TokenKind::CloseBrace)
while !self.check(TokenKind::Label("NEXT_LABEL".to_string())) &&
!self.check(TokenKind::CloseBrace)
{
match self.current_token.kind.clone() {
TokenKind::Literal(val) => {
Expand Down Expand Up @@ -930,9 +930,9 @@ impl Parser {
}

// name comes second (is optional)
if select_name
&& (self.check(TokenKind::Ident("x".to_string()))
|| self.check(TokenKind::PrimitiveType(PrimitiveEVMType::Address)))
if select_name &&
(self.check(TokenKind::Ident("x".to_string())) ||
self.check(TokenKind::PrimitiveType(PrimitiveEVMType::Address)))
{
// We need to check if the name is a keyword - not the type
if !on_type {
Expand Down Expand Up @@ -1106,8 +1106,8 @@ impl Parser {
0_usize
}
})
.sum::<usize>()
/ 2
.sum::<usize>() /
2
}
};

Expand Down
8 changes: 4 additions & 4 deletions huff_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ impl FunctionParamType {
pub fn is_memory_type(&self) -> bool {
matches!(
self,
FunctionParamType::Bytes
| FunctionParamType::String
| FunctionParamType::Tuple(_)
| FunctionParamType::Array(_, _)
FunctionParamType::Bytes |
FunctionParamType::String |
FunctionParamType::Tuple(_) |
FunctionParamType::Array(_, _)
)
}
}
Expand Down
64 changes: 32 additions & 32 deletions huff_utils/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,38 +783,38 @@ impl Opcode {
pub fn is_value_push(&self) -> bool {
matches!(
self,
Opcode::Push1
| Opcode::Push2
| Opcode::Push3
| Opcode::Push4
| Opcode::Push5
| Opcode::Push6
| Opcode::Push7
| Opcode::Push8
| Opcode::Push9
| Opcode::Push10
| Opcode::Push11
| Opcode::Push12
| Opcode::Push13
| Opcode::Push14
| Opcode::Push15
| Opcode::Push16
| Opcode::Push17
| Opcode::Push18
| Opcode::Push19
| Opcode::Push20
| Opcode::Push21
| Opcode::Push22
| Opcode::Push23
| Opcode::Push24
| Opcode::Push25
| Opcode::Push26
| Opcode::Push27
| Opcode::Push28
| Opcode::Push29
| Opcode::Push30
| Opcode::Push31
| Opcode::Push32
Opcode::Push1 |
Opcode::Push2 |
Opcode::Push3 |
Opcode::Push4 |
Opcode::Push5 |
Opcode::Push6 |
Opcode::Push7 |
Opcode::Push8 |
Opcode::Push9 |
Opcode::Push10 |
Opcode::Push11 |
Opcode::Push12 |
Opcode::Push13 |
Opcode::Push14 |
Opcode::Push15 |
Opcode::Push16 |
Opcode::Push17 |
Opcode::Push18 |
Opcode::Push19 |
Opcode::Push20 |
Opcode::Push21 |
Opcode::Push22 |
Opcode::Push23 |
Opcode::Push24 |
Opcode::Push25 |
Opcode::Push26 |
Opcode::Push27 |
Opcode::Push28 |
Opcode::Push29 |
Opcode::Push30 |
Opcode::Push31 |
Opcode::Push32
)
}

Expand Down
8 changes: 4 additions & 4 deletions huff_utils/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ impl Span {
.as_ref()
.map(|s| {
let line_num =
&s[0..self.start].as_bytes().iter().filter(|&&c| c == b'\n').count()
+ 1;
&s[0..self.start].as_bytes().iter().filter(|&&c| c == b'\n').count() +
1;
let line_start = &s[0..self.start].rfind('\n').unwrap_or(0);
let line_end = self.end
+ s[self.end..s.len()]
let line_end = self.end +
s[self.end..s.len()]
.find('\n')
.unwrap_or(s.len() - self.end)
.to_owned();
Expand Down
4 changes: 1 addition & 3 deletions huff_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ impl TryFrom<String> for EToken {
)))
}
_ => {
return Ok(EToken(Token::FixedBytes(
str_to_bytes32(cleaned_input).to_vec(),
)))
return Ok(EToken(Token::FixedBytes(str_to_bytes32(cleaned_input).to_vec())))
}
}
} else {
Expand Down

0 comments on commit 0633c4f

Please sign in to comment.