Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ copy_iterator = "warn"
default_trait_access = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
empty_enum = "warn"
empty_enums = "warn"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain in description why this is changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updating to Rust 1.94.0, cargo clippy started complaining about these lints. I just applied the automatic suggestions from Clippy to fix the warnings.

enum_glob_use = "allow"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
Expand Down Expand Up @@ -152,7 +152,7 @@ struct_field_names = "warn"
too_many_lines = "allow"
transmute_ptr_to_ptr = "warn"
trivially_copy_pass_by_ref = "warn"
unchecked_duration_subtraction = "warn"
unchecked_time_subtraction = "warn"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution is the same as in the previous answer.

unicode_not_nfc = "warn"
unnecessary_box_returns = "warn"
unnecessary_join = "warn"
Expand Down
23 changes: 17 additions & 6 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum Token<'src> {

// Control symbols
Arrow,
/// Represents a contiguous `::` token.
/// This prevents the lexer from allowing spaces between colons (e.g., `use a: :b`),
DoubleColon,
Colon,
Semi,
Comma,
Expand Down Expand Up @@ -71,6 +74,7 @@ impl<'src> fmt::Display for Token<'src> {
Token::Match => write!(f, "match"),

Token::Arrow => write!(f, "->"),
Token::DoubleColon => write!(f, "::"),
Token::Colon => write!(f, ":"),
Token::Semi => write!(f, ";"),
Token::Comma => write!(f, ","),
Expand Down Expand Up @@ -145,23 +149,30 @@ pub fn lexer<'src>(
_ => Token::Ident(s),
});

let jet = just("jet::")
.labelled("jet")
let jet = just("jet")
.padded()
.ignore_then(just("::"))
.padded()
Comment on lines +152 to +155
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change in respect to the previous grammar

Let's not add .padded(), so it becomes like this

let jet = just("jet")
    .then_ignore(just("::"))
    .ignore_then(text::ident())
    .map(Token::Jet);

Or do you have a reasoning why .padded() is needed?

.ignore_then(text::ident())
.map(Token::Jet);
let witness = just("witness::")
.labelled("witness")
let witness = just("witness")
.padded()
.ignore_then(just("::"))
.padded()
.ignore_then(text::ident())
.map(Token::Witness);
let param = just("param::")
.labelled("param")
let param = just("param")
.padded()
.ignore_then(just("::"))
.padded()
.ignore_then(text::ident())
.map(Token::Param);

let op = choice((
just("->").to(Token::Arrow),
just("=>").to(Token::FatArrow),
just("=").to(Token::Eq),
just("::").to(Token::DoubleColon),
just(":").to(Token::Colon),
just(";").to(Token::Semi),
just(",").to(Token::Comma),
Expand Down
31 changes: 27 additions & 4 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,16 +1347,14 @@ impl ChumskyParse for CallName {
where
I: ValueInput<'tokens, Token = Token<'src>, Span = Span>,
{
let double_colon = just(Token::Colon).then(just(Token::Colon)).labelled("::");

let turbofish_start = double_colon.clone().then(just(Token::LAngle)).ignored();
let turbofish_start = just(Token::DoubleColon).then(just(Token::LAngle)).ignored();

let generics_close = just(Token::RAngle);

let type_cast = just(Token::LAngle)
.ignore_then(AliasedType::parser())
.then_ignore(generics_close.clone())
.then_ignore(just(Token::Colon).then(just(Token::Colon)))
.then_ignore(just(Token::DoubleColon))
.then_ignore(just(Token::Ident("into")))
.map(CallName::TypeCast);

Expand Down Expand Up @@ -2163,3 +2161,28 @@ impl crate::ArbitraryRec for Match {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_double_colon() {
let input = "fn main() { let ab: u8 = <(u4, u4)> : :into((0b1011, 0b1101)); }";
let mut error_handler = ErrorCollector::new(Arc::from(input));
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);

assert!(parse_program.is_none());
assert!(ErrorCollector::to_string(&error_handler).contains("Expected '::', found ':'"));
}

#[test]
fn test_double_double_colon() {
let input = "fn main() { let pk: Pubkey = witnes::::PK; }";
let mut error_handler = ErrorCollector::new(Arc::from(input));
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);

assert!(parse_program.is_none());
assert!(ErrorCollector::to_string(&error_handler).contains("Expected ';', found '::'"));
}
}
Loading