Crates.io | uscan |
lib.rs | uscan |
version | 0.1.3 |
source | src |
created_at | 2023-01-23 22:19:11.808942 |
updated_at | 2023-02-26 21:18:15.086938 |
description | A universal source code scanner |
homepage | |
repository | https://github.com/jice-nospam/uscan |
max_upload_size | |
id | 766241 |
size | 27,393 |
A universal source code scanner
/!\ work-in-progress
const LUA_CONFIG: ScannerConfig = ScannerConfig {
keywords: &[
"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in",
"local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while",
],
symbols: &[
"...", "..", "==", "~=", "<=", ">=", "+", "-", "*", "/", "%", "^", "#", "<", ">", "=", "(",
")", "{", "}", "[", "]", ";", ":", ",", ".",
],
single_line_cmt: Some("--"),
multi_line_cmt_start: Some("--[["),
multi_line_cmt_end: Some("]]"),
};
let mut scanner_data = ScannerData::default();
let mut scanner = Scanner::default();
scanner.run(source_code, &LUA_CONFIG, &mut scanner_data)?;
=> you can now use the ScannerData struct in your parser to build your AST :
pub enum TokenType {
Symbol(String),
Identifier(String),
StringLiteral(String),
NumberLiteral(String, Number),
Keyword(String),
Comment(String),
// space
Ignore,
NewLine,
Eof,
Unknown,
}
pub struct ScannerData {
/// complete source code
pub source: Vec<char>,
/// resulting list of tokens
pub token_types: Vec<TokenType>,
/// token start line in the source code
pub token_lines: Vec<usize>,
/// token start offset from its line beginning
pub token_start: Vec<usize>,
/// token length in characters
/// not always = token value's length.
/// for example for TokenType::StringLiteral("aa") the value length is 2 but the token length including the quotes is 4
pub token_len: Vec<usize>,
}