New themes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::ops::Op;
|
||||
@@ -88,18 +89,18 @@ fn tokenize(input: &str) -> Vec<Token> {
|
||||
let span = SourceSpan { start: start as u32, end: end as u32 };
|
||||
|
||||
// Normalize shorthand float syntax: .25 -> 0.25, -.5 -> -0.5
|
||||
let word_to_parse = if word.starts_with('.')
|
||||
let word_to_parse: Cow<str> = if word.starts_with('.')
|
||||
&& word.len() > 1
|
||||
&& word.as_bytes()[1].is_ascii_digit()
|
||||
{
|
||||
format!("0{word}")
|
||||
Cow::Owned(format!("0{word}"))
|
||||
} else if word.starts_with("-.")
|
||||
&& word.len() > 2
|
||||
&& word.as_bytes()[2].is_ascii_digit()
|
||||
{
|
||||
format!("-0{}", &word[1..])
|
||||
Cow::Owned(format!("-0{}", &word[1..]))
|
||||
} else {
|
||||
word.clone()
|
||||
Cow::Borrowed(&word)
|
||||
};
|
||||
|
||||
if let Ok(i) = word_to_parse.parse::<i64>() {
|
||||
@@ -121,20 +122,10 @@ fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
|
||||
while i < tokens.len() {
|
||||
match &tokens[i] {
|
||||
Token::Int(n, span) => {
|
||||
let key = n.to_string();
|
||||
if let Some(body) = dict.lock().get(&key).cloned() {
|
||||
ops.extend(body);
|
||||
} else {
|
||||
ops.push(Op::PushInt(*n, Some(*span)));
|
||||
}
|
||||
ops.push(Op::PushInt(*n, Some(*span)));
|
||||
}
|
||||
Token::Float(f, span) => {
|
||||
let key = f.to_string();
|
||||
if let Some(body) = dict.lock().get(&key).cloned() {
|
||||
ops.extend(body);
|
||||
} else {
|
||||
ops.push(Op::PushFloat(*f, Some(*span)));
|
||||
}
|
||||
ops.push(Op::PushFloat(*f, Some(*span)));
|
||||
}
|
||||
Token::Str(s, span) => ops.push(Op::PushStr(Arc::from(s.as_str()), Some(*span))),
|
||||
Token::Word(w, span) => {
|
||||
|
||||
Reference in New Issue
Block a user