clex 0.1.0

Fast C-lang lexer (library)
Documentation
  • Coverage
  • 80.28%
    57 out of 71 items documented1 out of 9 items with examples
  • Size
  • Source code size: 51.18 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.89 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • katyo/clex
    4 0 2
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • katyo

C source lexer in Rust

github crate docs MIT CI

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

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"

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.