Skip to content

Commit

Permalink
fix: lexer
Browse files Browse the repository at this point in the history
Signed-off-by: Blue Kirby <blue.kirby@tutanota.com>
  • Loading branch information
guscalonico committed May 17, 2023
1 parent 2e98702 commit 3b741e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/utils/eip712/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum Token {
#[regex("[a-zA-Z_$][a-zA-Z0-9_$]*")]
Identifier,

#[regex("byte|bytes[1-2][0-9]?|bytes3[0-2]?|bytes[4-9]", validate_bytes)]
#[regex("bytes1|bytes[1-2][0-9]?|bytes3[0-2]?|bytes[4-9]", validate_bytes)]
TypeByte,

#[token("bytes")]
Expand All @@ -36,10 +36,10 @@ pub enum Token {
#[token("bool")]
TypeBool,

#[regex("uint|uint256", default_size)]
#[regex("uint(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)", default_size)]
TypeUint,

#[token("int", default_size)]
#[regex("int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)", default_size)]
TypeInt,

#[token("string")]
Expand Down
10 changes: 8 additions & 2 deletions src/utils/eip712/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod tests {

#[test]
fn test_parser() {
let source = "byte[][][7][][][][][][][]";
let source = "bytes1[][][7][][][][][][][]";
let ok = parse_type(source).unwrap();
println!("{:?}", ok);
assert!(
Expand Down Expand Up @@ -158,13 +158,19 @@ mod tests {

#[test]
fn test_nested_array() {
let source = "bytes1[][][7][][][][][][][][]";
assert!(parse_type(source).is_err());
let source = "byte1[][][7][][][][][][][][]";
assert!(parse_type(source).is_err());
let source = "byte[][][7][][][][][][][][]";
assert!(parse_type(source).is_err());
}

#[test]
fn test_malformed_array_type() {
let source = "bytes1[7[]uint][]";
assert!(parse_type(source).is_err());
let source = "byte[7[]uint][]";
assert!(parse_type(source).is_err())
assert!(parse_type(source).is_err());
}
}
6 changes: 3 additions & 3 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(any(feature = "ethereum", feature = "erc20"))]
mod eip712;

pub use eip712::hash_structured_data;
pub use eip712::Eip712Error;
pub use eip712::EIP712;
pub(crate) use eip712::hash_structured_data;
pub(crate) use eip712::Eip712Error;
pub(crate) use eip712::EIP712;

use std::{
fs::File,
Expand Down

0 comments on commit 3b741e5

Please sign in to comment.