fighting with lifetimes
This commit is contained in:
parent
2a26316b50
commit
5a64c6623c
10
src/main.rs
10
src/main.rs
|
@ -58,7 +58,7 @@ use crate::base::*;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let src = "
|
let src = "
|
||||||
let \"{foo}\" = bar
|
let \"{foo}bar{baz}\" = \"foo var baz\"
|
||||||
";
|
";
|
||||||
let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
|
let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
|
||||||
if !lex_errs.is_empty() {
|
if !lex_errs.is_empty() {
|
||||||
|
@ -73,13 +73,13 @@ let \"{foo}\" = bar
|
||||||
let (ast, _) = parser()
|
let (ast, _) = parser()
|
||||||
.parse(Stream::from_iter(to_parse).map((0..src.len()).into(), |(t, s)| (t, s)))
|
.parse(Stream::from_iter(to_parse).map((0..src.len()).into(), |(t, s)| (t, s)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("{}", ast);
|
// println!("{}", ast);
|
||||||
|
|
||||||
// let mut ctx = base();
|
let mut ctx = base();
|
||||||
|
|
||||||
// let result = eval(&ast, &mut ctx).unwrap();
|
let result = eval(&ast, &mut ctx).unwrap();
|
||||||
|
|
||||||
// println!("{}", result);
|
println!("{}", result);
|
||||||
|
|
||||||
// struct_scalpel::print_dissection_info::<value::Value>()
|
// struct_scalpel::print_dissection_info::<value::Value>()
|
||||||
// struct_scalpel::print_dissection_info::<parser::Ast>();
|
// struct_scalpel::print_dissection_info::<parser::Ast>();
|
||||||
|
|
|
@ -247,7 +247,7 @@ impl<'src> fmt::Display for PairPattern<'src> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StringMatcher<'src>(Box<dyn Fn(String) -> Option<Vec<(String, String)>> + 'src>);
|
pub struct StringMatcher<'src>(pub Box<dyn Fn(String) -> Option<Vec<(String, String)>> + 'src>);
|
||||||
|
|
||||||
impl PartialEq for StringMatcher<'_> {
|
impl PartialEq for StringMatcher<'_> {
|
||||||
fn eq(&self, _other: &StringMatcher) -> bool {
|
fn eq(&self, _other: &StringMatcher) -> bool {
|
||||||
|
|
16
src/vm.rs
16
src/vm.rs
|
@ -64,6 +64,22 @@ pub fn match_pattern<'src, 'a>(
|
||||||
(Pattern::Boolean(x), Value::Boolean(y)) => match_eq(x, y, ctx),
|
(Pattern::Boolean(x), Value::Boolean(y)) => match_eq(x, y, ctx),
|
||||||
(Pattern::Keyword(x), Value::Keyword(y)) => match_eq(x, y, ctx),
|
(Pattern::Keyword(x), Value::Keyword(y)) => match_eq(x, y, ctx),
|
||||||
(Pattern::String(x), Value::InternedString(y)) => match_eq(x, y, ctx),
|
(Pattern::String(x), Value::InternedString(y)) => match_eq(x, y, ctx),
|
||||||
|
(Pattern::String(x), Value::AllocatedString(y)) => match_eq(&x.to_string(), &**y, ctx),
|
||||||
|
(Pattern::Interpolated(_, StringMatcher(matcher)), Value::InternedString(y)) => {
|
||||||
|
match matcher(y.to_string()) {
|
||||||
|
Some(matches) => {
|
||||||
|
let mut matches = matches
|
||||||
|
.iter()
|
||||||
|
.map(|(word, string)| {
|
||||||
|
(word, Value::AllocatedString(Rc::new(string.clone())))
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
ctx.append(&mut matches);
|
||||||
|
Some(ctx)
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
(Pattern::Word(w), val) => {
|
(Pattern::Word(w), val) => {
|
||||||
ctx.push((w, val.clone()));
|
ctx.push((w, val.clone()));
|
||||||
Some(ctx)
|
Some(ctx)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user