Skip to content

Commit 9ee12f7

Browse files
committed
fix: add a DoubleColon to the Token struct in the lexer.rs
1 parent b1a8648 commit 9ee12f7

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ copy_iterator = "warn"
6868
default_trait_access = "warn"
6969
doc_link_with_quotes = "warn"
7070
doc_markdown = "warn"
71-
empty_enum = "warn"
71+
empty_enums = "warn"
7272
enum_glob_use = "allow"
7373
expl_impl_clone_on_copy = "warn"
7474
explicit_deref_methods = "warn"
@@ -152,7 +152,7 @@ struct_field_names = "warn"
152152
too_many_lines = "allow"
153153
transmute_ptr_to_ptr = "warn"
154154
trivially_copy_pass_by_ref = "warn"
155-
unchecked_duration_subtraction = "warn"
155+
unchecked_time_subtraction = "warn"
156156
unicode_not_nfc = "warn"
157157
unnecessary_box_returns = "warn"
158158
unnecessary_join = "warn"

src/lexer.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub enum Token<'src> {
2020

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

7376
Token::Arrow => write!(f, "->"),
77+
Token::DoubleColon => write!(f, "::"),
7478
Token::Colon => write!(f, ":"),
7579
Token::Semi => write!(f, ";"),
7680
Token::Comma => write!(f, ","),
@@ -145,23 +149,24 @@ pub fn lexer<'src>(
145149
_ => Token::Ident(s),
146150
});
147151

148-
let jet = just("jet::")
149-
.labelled("jet")
152+
let jet = just("jet")
153+
.ignore_then(just("::"))
150154
.ignore_then(text::ident())
151155
.map(Token::Jet);
152-
let witness = just("witness::")
153-
.labelled("witness")
156+
let witness = just("witness")
157+
.ignore_then(just("::"))
154158
.ignore_then(text::ident())
155159
.map(Token::Witness);
156-
let param = just("param::")
157-
.labelled("param")
160+
let param = just("param")
161+
.ignore_then(just("::"))
158162
.ignore_then(text::ident())
159163
.map(Token::Param);
160164

161165
let op = choice((
162166
just("->").to(Token::Arrow),
163167
just("=>").to(Token::FatArrow),
164168
just("=").to(Token::Eq),
169+
just("::").to(Token::DoubleColon),
165170
just(":").to(Token::Colon),
166171
just(";").to(Token::Semi),
167172
just(",").to(Token::Comma),

src/parse.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,16 +1347,14 @@ impl ChumskyParse for CallName {
13471347
where
13481348
I: ValueInput<'tokens, Token = Token<'src>, Span = Span>,
13491349
{
1350-
let double_colon = just(Token::Colon).then(just(Token::Colon)).labelled("::");
1351-
1352-
let turbofish_start = double_colon.clone().then(just(Token::LAngle)).ignored();
1350+
let turbofish_start = just(Token::DoubleColon).then(just(Token::LAngle)).ignored();
13531351

13541352
let generics_close = just(Token::RAngle);
13551353

13561354
let type_cast = just(Token::LAngle)
13571355
.ignore_then(AliasedType::parser())
13581356
.then_ignore(generics_close.clone())
1359-
.then_ignore(just(Token::Colon).then(just(Token::Colon)))
1357+
.then_ignore(just(Token::DoubleColon))
13601358
.then_ignore(just(Token::Ident("into")))
13611359
.map(CallName::TypeCast);
13621360

@@ -2163,3 +2161,28 @@ impl crate::ArbitraryRec for Match {
21632161
})
21642162
}
21652163
}
2164+
2165+
#[cfg(test)]
2166+
mod tests {
2167+
use super::*;
2168+
2169+
#[test]
2170+
fn test_double_colon() {
2171+
let input = "fn main() { let ab: u8 = <(u4, u4)> : :into((0b1011, 0b1101)); }";
2172+
let mut error_handler = ErrorCollector::new(Arc::from(input));
2173+
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);
2174+
2175+
assert!(parse_program.is_none());
2176+
assert!(ErrorCollector::to_string(&error_handler).contains("Expected '::', found ':'"));
2177+
}
2178+
2179+
#[test]
2180+
fn test_double_double_colon() {
2181+
let input = "fn main() { let pk: Pubkey = witnes::::PK; }";
2182+
let mut error_handler = ErrorCollector::new(Arc::from(input));
2183+
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);
2184+
2185+
assert!(parse_program.is_none());
2186+
assert!(ErrorCollector::to_string(&error_handler).contains("Expected ';', found '::'"));
2187+
}
2188+
}

0 commit comments

Comments
 (0)