Speed sketch beginnings of a Rust implementation of new stripped-down Scheme-like Kraken

This commit is contained in:
2023-02-07 02:07:53 -05:00
parent 3807381ceb
commit 60dad101f8
7 changed files with 715 additions and 0 deletions

27
kr/src/grammar.lalrpop Normal file
View File

@@ -0,0 +1,27 @@
use std::str::FromStr;
use std::rc::Rc;
use crate::ast::Form;
grammar;
pub Term: Form = {
NUM => Form::Int(i32::from_str(<>).unwrap()),
SYM => Form::Symbol(<>.to_owned()),
"(" <ListInside?> ")" => <>.unwrap_or(Form::Nil),
"'" <Term> => Form::Pair(Rc::new(Form::Symbol("quote".to_owned())), Rc::new(<>)),
};
ListInside: Form = {
<Term> => Form::Pair(Rc::new(<>), Rc::new(Form::Nil)),
<h: Term> <t: ListInside> => Form::Pair(Rc::new(h), Rc::new(t)),
<a: Term> "." <d: Term> => Form::Pair(Rc::new(a), Rc::new(d)),
}
match {
"(",
")",
".",
"'",
r"[0-9]+" => NUM,
r"[a-zA-Z+*/_-][\w+*/_-]*" => SYM,
r"(;[^\n]*\n)|\s+" => { }
}