I got very confused and started mucking about with "spawn" when in fact all I needed was the "inline" extension type in orcx that allows the interpreter to expose custom constants.
23 lines
825 B
Rust
23 lines
825 B
Rust
use std::ops::RangeInclusive;
|
|
|
|
use orchid_base::{OrcRes, num_to_errv, parse_num};
|
|
use orchid_extension::conv::ToExpr;
|
|
use orchid_extension::lexer::{LexContext, Lexer};
|
|
use orchid_extension::tree::{GenTokTree, x_tok};
|
|
|
|
use super::num_atom::Num;
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct NumLexer;
|
|
impl Lexer for NumLexer {
|
|
const CHAR_FILTER: &'static [RangeInclusive<char>] = &['0'..='9'];
|
|
async fn lex<'a>(all: &'a str, lxcx: &'a LexContext<'a>) -> OrcRes<(&'a str, GenTokTree)> {
|
|
let ends_at = all.find(|c: char| !c.is_ascii_hexdigit() && !"xX._pP".contains(c));
|
|
let (chars, tail) = all.split_at(ends_at.unwrap_or(all.len()));
|
|
match parse_num(chars) {
|
|
Ok(numeric) => Ok((tail, x_tok(Num(numeric)).await.at(lxcx.pos_lt(chars.len(), tail)))),
|
|
Err(e) => Err(num_to_errv(e, lxcx.pos(all), lxcx.src()).await),
|
|
}
|
|
}
|
|
}
|