https://github.com/katyo/clex
Fast and robust C source lexer in Rust
https://github.com/katyo/clex
Last synced: 3 months ago
JSON representation
Fast and robust C source lexer in Rust
- Host: GitHub
- URL: https://github.com/katyo/clex
- Owner: katyo
- License: mit
- Created: 2022-07-03T07:06:40.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-03T18:55:36.000Z (almost 3 years ago)
- Last Synced: 2025-04-01T06:31:32.373Z (3 months ago)
- Language: Rust
- Size: 14.6 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C source lexer in Rust
[](https://github.com/katyo/clex)
[](https://crates.io/crates/clex)
[](https://docs.rs/clex)
[](https://opensource.org/licenses/MIT)
[](https://github.com/katyo/clex/actions?query=workflow%3ARust)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.
## Library usage
```rust
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:
```text
string: "world"
comment: "Hello world"
string: "Hello %s\n"
```## Command-line usage
Currently command-line tool is used to test this library.
You can use it to analyze variuos C-sources and extract data.