Crates.io | lexerus_derive |
lib.rs | lexerus_derive |
version | 0.1.0 |
source | src |
created_at | 2024-09-11 11:00:53.233017 |
updated_at | 2024-09-11 11:00:53.233017 |
description | Simple annotated lexer |
homepage | |
repository | https://github.com/babagreensheep/lexerus |
max_upload_size | |
id | 1371838 |
size | 83,490 |
Note: This readme is auto generated. Please refer to the docs.
Lexerus is a lexer dinosaur that consumes a [Buffer] constructed from [str] and spits out a structure through the [lexer::Lexer::lex] call.
This library uses the [lexer_derive::Token] and [lexer_derive::Lexer] macros to decorate a structure for automatic parsing. See those macros for additional options.
This library was developed in conjunction with SPEW and examples on actual implementation can be found there.
// Create and decorate a struct
#[derive(Lexer, Token, Debug)]
struct Trex<'code>(#[pattern = "trex::"] Buffer<'code>);
#[derive(Lexer, Token, Debug)]
struct TrexCall<'code>(
#[pattern = "RAWR"] Buffer<'code>,
);
#[derive(Lexer, Token, Debug)]
struct Call<'code> {
rex: Trex<'code>,
call: TrexCall<'code>,
}
// Create a raw buffe
let mut buffer = Buffer::from("trex::RAWR");
// Attempt to parse the trex
let trex_calling = Call::lex(&mut buffer).unwrap();
// Extract the buffer from trex
let trex = trex_calling.rex.buffer().unwrap();
let trex_calling = trex_calling.buffer().unwrap();
// Buffer should contain the exact matched string
assert_eq!(trex_calling.to_string(), "trex::RAWR");
assert_eq!(trex.to_string(), "trex::");