Skip to content

Commit 682d829

Browse files
committed
Merge #243: 🐛 add a DoubleColon to the Token struct in the lexer.rs
e11d27a fix: add a `DoubleColon` to the `Token` struct in the lexer.rs (LesterEvSe) Pull request description: This prevents the lexer from allowing spaces between colons (e.g., `a: :b`), ACKs for top commit: KyrylR: ACK e11d27a ran tests locally stringhandler: ACK [e11d27a](e11d27a) Tree-SHA512: 94ef1dd453ae58bb74b65f8f5633047d43fb75bd9785fea068b05a9257a5e2a8b2f261258348eee54c6a016028d4e4cb2739c5e033d63a95e151644f73c31cc1
2 parents eeabada + e11d27a commit 682d829

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

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: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,16 +1338,14 @@ impl ChumskyParse for CallName {
13381338
where
13391339
I: ValueInput<'tokens, Token = Token<'src>, Span = Span>,
13401340
{
1341-
let double_colon = just(Token::Colon).then(just(Token::Colon)).labelled("::");
1342-
1343-
let turbofish_start = double_colon.clone().then(just(Token::LAngle)).ignored();
1341+
let turbofish_start = just(Token::DoubleColon).then(just(Token::LAngle)).ignored();
13441342

13451343
let generics_close = just(Token::RAngle);
13461344

13471345
let type_cast = just(Token::LAngle)
13481346
.ignore_then(AliasedType::parser())
13491347
.then_ignore(generics_close.clone())
1350-
.then_ignore(just(Token::Colon).then(just(Token::Colon)))
1348+
.then_ignore(just(Token::DoubleColon))
13511349
.then_ignore(just(Token::Ident("into")))
13521350
.map(CallName::TypeCast);
13531351

@@ -2187,4 +2185,24 @@ mod test {
21872185
&Error::RedefinedAliasAsBuiltin(AliasName::from_str_unchecked("Ctx8"))
21882186
);
21892187
}
2188+
2189+
#[test]
2190+
fn test_double_colon() {
2191+
let input = "fn main() { let ab: u8 = <(u4, u4)> : :into((0b1011, 0b1101)); }";
2192+
let mut error_handler = ErrorCollector::new(Arc::from(input));
2193+
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);
2194+
2195+
assert!(parse_program.is_none());
2196+
assert!(ErrorCollector::to_string(&error_handler).contains("Expected '::', found ':'"));
2197+
}
2198+
2199+
#[test]
2200+
fn test_double_double_colon() {
2201+
let input = "fn main() { let pk: Pubkey = witnes::::PK; }";
2202+
let mut error_handler = ErrorCollector::new(Arc::from(input));
2203+
let parse_program = Program::parse_from_str_with_errors(input, &mut error_handler);
2204+
2205+
assert!(parse_program.is_none());
2206+
assert!(ErrorCollector::to_string(&error_handler).contains("Expected ';', found '::'"));
2207+
}
21902208
}

0 commit comments

Comments
 (0)