A Rust lexer — tokenizes Rust source code into categorized tokens..
cargo run -- path/to/file.rsEach token is printed with its kind, source span, and optional value:
Token { kind: Fn, span: 1:1-1:3, value: Some("fn") }
Token { kind: Identifier, span: 1:4-1:8, value: Some("main") }
Token { kind: IntLiteral, span: 1:21-1:23, value: Some("42") }
Keywords — let, fn, if, else, while, loop, for, in, return, struct, enum, impl, self, match, mut, const, type, use, mod, as, break, continue
Literals — IntLiteral, FloatLiteral, StringLiteral, CharLiteral, BoolLiteral
Operators — +, -, *, /, %, =, ==, !=, <, >, <=, >=, &&, ||, &, |, ^, ~, <<, >>, +=, -=, *=, /=, ->, =>, ., .., ..=
Delimiters — (, ), {, }, [, ], ;, :, ,, _, #, @
Special — Comment, Whitespace, Newline, Unknown, Eof
- Decimal:
42,1_000 - Hex:
0xFF,0xdead_beef - Octal:
0o77 - Binary:
0b1010 - Float:
3.14,1e10,2.5e-3
\n, \t, \r, \0, \\, \', \", \xHH, \u{HHHH}