14 releases

0.3.6 Nov 11, 2023
0.3.5 Nov 11, 2023
0.2.3 Oct 14, 2023
0.1.2 Sep 25, 2023

#62 in Parser tooling

Download history 2/week @ 2024-03-08 2/week @ 2024-03-15 50/week @ 2024-03-29 17/week @ 2024-04-05

143 downloads per month

MIT/Apache

15KB
283 lines

Stars Forks

Lib-lexin

A simple lexer library.

  • Description
  • Getting Started
  • Authors
  • Versions
  • License
  • Description

    lib-lexin is a small lexer library created to be able to quickly lex anything

    Getting Started

    Usage

    Example

    This example shows how easy it is to lex a file

    use lib_lexin::{Lexer, Section};
    
    let mut lexer = Lexer::new(
        &[ // keywords
            "fn",
            "return"
        ],
        &[ // section
            Section::new("string", "\"", "\""),
        ],
        &[ // symbols
            ('+', "Plus"),
        ],
    );
    
    lexer.load_file("[FILE]");
    
    let tokens = lexer.tokenize()?;
    

    Functions

    Lexer::new

    pub fn new(keywords: &[&'a str], sections: &[Section], symbols: &[(char, &'a str)]) -> Lexer<'a>
    

    Lexer::load_file

    pub fn load_file(&mut self, filename: &str) -> Result<(), Box<dyn std::error::Error>>
    

    Lexer::load_str

    pub fn load_str(&mut self, string: &str)
    

    Lexer::tokenize

    pub fn tokenize(&mut self) -> Result<Vec<Token>, Box<dyn std::error::Error>>
    

    Section::new

    pub fn new(name: &str, start: &str, end: &str) -> Section
    

    Token::is_keyword

    pub fn is_keyword(&self, keyword: &str) -> Result<(), Box<dyn std::error::Error>>
    

    Token::is_section

    pub fn is_section(&self, name: &str) -> Result<String, Box<dyn std::error::Error>>
    

    Token::is_ident

    pub fn is_ident(&self) -> Result<String, Box<dyn std::error::Error>>
    

    Token::is_integer

    pub fn is_integer(&self) -> Result<usize, Box<dyn std::error::Error>>
    

    Token::is_float

    pub fn is_float(&self) -> Result<f64, Box<dyn std::error::Error>>
    

    Token::is_symbol

    pub fn is_symbol(&self, name: &str) -> Result<(), Box<dyn std::error::Error>>
    

    Help

    Sections are always escaped

    Authors

    Contributors names and contact info

    Versions

    • 0.1
      • Initial Release

    License

    Currently there is no license, this may change in the future

    No runtime deps