Crates.io | clex |
lib.rs | clex |
version | 0.1.0 |
source | src |
created_at | 2022-07-03 19:08:58.900631 |
updated_at | 2022-07-03 19:08:58.900631 |
description | Fast C-lang lexer (library) |
homepage | https://github.com/katyo/clex |
repository | https://github.com/katyo/clex |
max_upload_size | |
id | 618512 |
size | 44,450 |
This is a fast and robust C source lexer in Rust. For example it can be used to extract some metadata from sources like comments or strings.
use clex::{Lexer, Token};
let src = r#"
static const char *s = "world";
int main() {
// Hello world
printf("Hello %s\n", s);
return 0;
}
"#;
for lexeme in Lexer::from(src) {
match lexeme.token {
Token::Comment => {
println!("comment: {:?}", lexeme.comment().unwrap());
}
Token::String => {
println!("string: {:?}", lexeme.string().unwrap());
}
_ => {}
}
}
This example prints the following:
string: "world"
comment: "Hello world"
string: "Hello %s\n"
Currently command-line tool is used to test this library. You can use it to analyze variuos C-sources and extract data.