Define lambda shorthand

trunk
Alona EM 2021-12-17 04:15:53 +00:00
parent 1780796b5f
commit 69b7714892
3 changed files with 236 additions and 156 deletions

View File

@ -7,6 +7,7 @@ grammar<'s>();
pub(crate) Tree: Tree = { pub(crate) Tree: Tree = {
"(" <Tree+> ")" => Tree::Branch(<>), "(" <Tree+> ")" => Tree::Branch(<>),
"(" "define" <Sym> <BTree> ")" => Tree::Define(<>), "(" "define" <Sym> <BTree> ")" => Tree::Define(<>),
"(" "define" "(" <name:Sym> <args:RcSlice<Sym>> ")" <body:Rc<Tree>> ")" => Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body)))),
"(" "if" <Tree> <Tree> <Tree> ")" => Tree::If(Box::new([<>])), "(" "if" <Tree> <Tree> <Tree> ")" => Tree::If(Box::new([<>])),
"(" "lambda (" <RcSlice<Sym>> ")" <Rc<Tree>> ")" => Tree::Lambda(Lambda(<>)), "(" "lambda (" <RcSlice<Sym>> ")" <Rc<Tree>> ")" => Tree::Lambda(Lambda(<>)),
Literal => Tree::Leaf(<>), Literal => Tree::Leaf(<>),

View File

@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.19.6" // auto-generated: "lalrpop 0.19.6"
// sha3: 753fb4f6236f2d88546d1b9a3c423a0af234f3c971035520e33d7e7510538 // sha3: 779020ca179c7d99169ea2a3dc209511d4dc5bfa2f6290c09a821c6f93ced8c
use crate::{Tree, Literal, Lambda}; use crate::{Tree, Literal, Lambda};
use std::rc::Rc; use std::rc::Rc;
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]
@ -39,75 +39,87 @@ mod __parse__Tree {
} }
const __ACTION: &[i8] = &[ const __ACTION: &[i8] = &[
// State 0 // State 0
17, 18, 2, 0, 0, 0, 0, 19, 20, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 1 // State 1
17, 18, 2, 0, 4, 5, 6, 19, 20, 20, 21, 2, 0, 4, 5, 6, 22, 23,
// State 2 // State 2
17, 18, 2, 23, 0, 0, 0, 19, 20, 20, 21, 2, 26, 0, 0, 0, 22, 23,
// State 3 // State 3
0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 8, 0, 0, 0, 0, 0, 23,
// State 4 // State 4
17, 18, 2, 0, 0, 0, 0, 19, 20, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 5 // State 5
0, 0, 0, -10, 0, 0, 0, 0, 20, 0, 0, 0, -10, 0, 0, 0, 0, 23,
// State 6 // State 6
17, 18, 2, 0, 0, 0, 0, 19, 20, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 7 // State 7
17, 18, 2, 0, 0, 0, 0, 19, 20, 0, 0, 0, 0, 0, 0, 0, 0, 23,
// State 8 // State 8
0, 0, 0, -11, 0, 0, 0, 0, 20, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 9 // State 9
17, 18, 2, 0, 0, 0, 0, 19, 20, 0, 0, 0, -11, 0, 0, 0, 0, 23,
// State 10 // State 10
17, 18, 2, 0, 0, 0, 0, 19, 20, 0, 0, 0, -10, 0, 0, 0, 0, 23,
// State 11 // State 11
-7, -7, -7, -7, 0, 0, 0, -7, -7, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 12 // State 12
-21, -21, -21, -21, 0, 0, 0, -21, -21, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 13 // State 13
-6, -6, -6, -6, 0, 0, 0, -6, -6, 20, 21, 2, 0, 0, 0, 0, 22, 23,
// State 14 // State 14
-5, -5, -5, -5, 0, 0, 0, -5, -5, -7, -7, -7, -7, 0, 0, 0, -7, -7,
// State 15 // State 15
0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 16
-3, -3, -3, -3, 0, 0, 0, -3, -3,
// State 17
-2, -2, -2, -2, 0, 0, 0, -2, -2,
// State 18
-8, -8, -8, -8, 0, 0, 0, -8, -8,
// State 19
-12, -12, -12, -12, 0, 0, 0, -12, -12,
// State 20
-22, -22, -22, -22, 0, 0, 0, -22, -22, -22, -22, -22, -22, 0, 0, 0, -22, -22,
// State 16
-6, -6, -6, -6, 0, 0, 0, -6, -6,
// State 17
-5, -5, -5, -5, 0, 0, 0, -5, -5,
// State 18
0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 19
-3, -3, -3, -3, 0, 0, 0, -3, -3,
// State 20
-2, -2, -2, -2, 0, 0, 0, -2, -2,
// State 21 // State 21
-23, -23, -23, -23, 0, 0, 0, -23, -23, -8, -8, -8, -8, 0, 0, 0, -8, -8,
// State 22 // State 22
-17, -17, -17, -17, 0, 0, 0, -17, -17, -12, -12, -12, -12, 0, 0, 0, -12, -12,
// State 23 // State 23
0, 0, 0, 11, 0, 0, 0, 0, 0, -23, -23, -23, -23, 0, 0, 0, -23, -23,
// State 24 // State 24
0, 0, 0, -15, 0, 0, 0, 0, -15, -24, -24, -24, -24, 0, 0, 0, -24, -24,
// State 25 // State 25
0, 0, 0, 30, 0, 0, 0, 0, 0, -17, -17, -17, -17, 0, 0, 0, -17, -17,
// State 26 // State 26
0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0,
// State 27 // State 27
0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, -15,
// State 28 // State 28
0, 0, 0, -16, 0, 0, 0, 0, -16, 0, 0, 0, 33, 0, 0, 0, 0, 0,
// State 29 // State 29
-18, -18, -18, -18, 0, 0, 0, -18, -18, 0, 0, 0, -1, 0, 0, 0, 0, 0,
// State 30 // State 30
0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0,
// State 31 // State 31
0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, -16,
// State 32 // State 32
0, 0, 0, -9, 0, 0, 0, 0, 0, -18, -18, -18, -18, 0, 0, 0, -18, -18,
// State 33 // State 33
-19, -19, -19, -19, 0, 0, 0, -19, -19, 0, 0, 0, 14, 0, 0, 0, 0, 0,
// State 34 // State 34
0, 0, 0, 38, 0, 0, 0, 0, 0,
// State 35
0, 0, 0, 39, 0, 0, 0, 0, 0,
// State 36
0, 0, 0, -9, 0, 0, 0, 0, 0,
// State 37
-20, -20, -20, -20, 0, 0, 0, -20, -20, -20, -20, -20, -20, 0, 0, 0, -20, -20,
// State 38
-21, -21, -21, -21, 0, 0, 0, -21, -21,
// State 39
0, 0, 0, 41, 0, 0, 0, 0, 0,
// State 40
-19, -19, -19, -19, 0, 0, 0, -19, -19,
]; ];
fn __action(state: i8, integer: usize) -> i8 { fn __action(state: i8, integer: usize) -> i8 {
__ACTION[(state as usize) * 9 + integer] __ACTION[(state as usize) * 9 + integer]
@ -136,35 +148,35 @@ mod __parse__Tree {
// State 10 // State 10
0, 0,
// State 11 // State 11
-7, 0,
// State 12 // State 12
-21, 0,
// State 13 // State 13
-6, 0,
// State 14 // State 14
-5, -7,
// State 15 // State 15
-24, -22,
// State 16 // State 16
-3, -6,
// State 17 // State 17
-2, -5,
// State 18 // State 18
-8, -25,
// State 19 // State 19
-12, -3,
// State 20 // State 20
0, -2,
// State 21 // State 21
0, -8,
// State 22 // State 22
-17, -12,
// State 23 // State 23
0, 0,
// State 24 // State 24
0, 0,
// State 25 // State 25
0, -17,
// State 26 // State 26
0, 0,
// State 27 // State 27
@ -172,43 +184,62 @@ mod __parse__Tree {
// State 28 // State 28
0, 0,
// State 29 // State 29
-18, 0,
// State 30 // State 30
0, 0,
// State 31 // State 31
0, 0,
// State 32 // State 32
0, -18,
// State 33 // State 33
-19, 0,
// State 34 // State 34
0,
// State 35
0,
// State 36
0,
// State 37
-20, -20,
// State 38
-21,
// State 39
0,
// State 40
-19,
]; ];
fn __goto(state: i8, nt: usize) -> i8 { fn __goto(state: i8, nt: usize) -> i8 {
match nt { match nt {
0 => 25, 0 => 28,
1 => 11, 1 => 14,
2 => 26, 2 => 29,
3 => 12, 3 => 15,
4 => 13, 4 => 16,
5 => 31, 5 => match state {
6 => 23, 13 => 39,
_ => 35,
},
6 => match state {
10 => 33,
_ => 26,
},
7 => match state { 7 => match state {
3 => 6, 3 => 6,
5 => 24, 7 => 10,
8 => 28, 5 | 10 => 27,
_ => 14, 9 => 31,
_ => 17,
}, },
9 => 8, 9 => 9,
10 => match state { 10 => match state {
7 => 9, 8 => 11,
0 => 15, 0 => 18,
1 => 20, 1 => 23,
2 => 21, 2 => 24,
6 => 27, 6 => 30,
9 => 30, 11 => 34,
10 => 32, 12..=13 => 36,
_ => 7, _ => 8,
}, },
11 => 2, 11 => 2,
_ => 0, _ => 0,
@ -486,6 +517,9 @@ mod __parse__Tree {
__reduce22(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>) __reduce22(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>)
} }
23 => { 23 => {
__reduce23(input, __lookahead_start, __symbols, core::marker::PhantomData::<(&(), &())>)
}
24 => {
// __Tree = Tree => ActionFn(0); // __Tree = Tree => ActionFn(0);
let __sym0 = __pop_Variant9(__symbols); let __sym0 = __pop_Variant9(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
@ -637,11 +671,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// BTree = Box<Tree> => ActionFn(6); // BTree = Box<Tree> => ActionFn(7);
let __sym0 = __pop_Variant1(__symbols); let __sym0 = __pop_Variant1(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action6::<>(input, __sym0); let __nt = super::__action7::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant1(__nt), __end)); __symbols.push((__start, __Symbol::Variant1(__nt), __end));
(1, 0) (1, 0)
} }
@ -655,11 +689,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Bool = "#t" => ActionFn(12); // Bool = "#t" => ActionFn(13);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action12::<>(input, __sym0); let __nt = super::__action13::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant2(__nt), __end)); __symbols.push((__start, __Symbol::Variant2(__nt), __end));
(1, 1) (1, 1)
} }
@ -673,11 +707,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Bool = "#f" => ActionFn(13); // Bool = "#f" => ActionFn(14);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action13::<>(input, __sym0); let __nt = super::__action14::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant2(__nt), __end)); __symbols.push((__start, __Symbol::Variant2(__nt), __end));
(1, 1) (1, 1)
} }
@ -691,11 +725,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Box<Tree> = Tree => ActionFn(14); // Box<Tree> = Tree => ActionFn(15);
let __sym0 = __pop_Variant9(__symbols); let __sym0 = __pop_Variant9(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action14::<>(input, __sym0); let __nt = super::__action15::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant1(__nt), __end)); __symbols.push((__start, __Symbol::Variant1(__nt), __end));
(1, 2) (1, 2)
} }
@ -709,11 +743,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Literal = Sym => ActionFn(7); // Literal = Sym => ActionFn(8);
let __sym0 = __pop_Variant7(__symbols); let __sym0 = __pop_Variant7(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action7::<>(input, __sym0); let __nt = super::__action8::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant3(__nt), __end)); __symbols.push((__start, __Symbol::Variant3(__nt), __end));
(1, 3) (1, 3)
} }
@ -727,11 +761,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Literal = Num => ActionFn(8); // Literal = Num => ActionFn(9);
let __sym0 = __pop_Variant4(__symbols); let __sym0 = __pop_Variant4(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action8::<>(input, __sym0); let __nt = super::__action9::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant3(__nt), __end)); __symbols.push((__start, __Symbol::Variant3(__nt), __end));
(1, 3) (1, 3)
} }
@ -745,11 +779,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Literal = Bool => ActionFn(9); // Literal = Bool => ActionFn(10);
let __sym0 = __pop_Variant2(__symbols); let __sym0 = __pop_Variant2(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action9::<>(input, __sym0); let __nt = super::__action10::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant3(__nt), __end)); __symbols.push((__start, __Symbol::Variant3(__nt), __end));
(1, 3) (1, 3)
} }
@ -763,11 +797,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(11); // Num = r#"[0-9]+(\\.[0-9]+)?"# => ActionFn(12);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action11::<>(input, __sym0); let __nt = super::__action12::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant4(__nt), __end)); __symbols.push((__start, __Symbol::Variant4(__nt), __end));
(1, 4) (1, 4)
} }
@ -781,11 +815,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Rc<Tree> = Tree => ActionFn(15); // Rc<Tree> = Tree => ActionFn(16);
let __sym0 = __pop_Variant9(__symbols); let __sym0 = __pop_Variant9(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action15::<>(input, __sym0); let __nt = super::__action16::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant5(__nt), __end)); __symbols.push((__start, __Symbol::Variant5(__nt), __end));
(1, 5) (1, 5)
} }
@ -799,10 +833,10 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// RcSlice<Sym> = => ActionFn(23); // RcSlice<Sym> = => ActionFn(24);
let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default();
let __end = __start.clone(); let __end = __start.clone();
let __nt = super::__action23::<>(input, &__start, &__end); let __nt = super::__action24::<>(input, &__start, &__end);
__symbols.push((__start, __Symbol::Variant6(__nt), __end)); __symbols.push((__start, __Symbol::Variant6(__nt), __end));
(0, 6) (0, 6)
} }
@ -816,11 +850,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// RcSlice<Sym> = Sym+ => ActionFn(24); // RcSlice<Sym> = Sym+ => ActionFn(25);
let __sym0 = __pop_Variant8(__symbols); let __sym0 = __pop_Variant8(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action24::<>(input, __sym0); let __nt = super::__action25::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant6(__nt), __end)); __symbols.push((__start, __Symbol::Variant6(__nt), __end));
(1, 6) (1, 6)
} }
@ -834,11 +868,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(10); // Sym = r#"[A-Za-z!$%&*+\\-./:<=>?@^_~][A-Za-z!$%&*+\\-./:<=>?@^_~0-9]*"# => ActionFn(11);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action10::<>(input, __sym0); let __nt = super::__action11::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant7(__nt), __end)); __symbols.push((__start, __Symbol::Variant7(__nt), __end));
(1, 7) (1, 7)
} }
@ -852,10 +886,10 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Sym* = => ActionFn(19); // Sym* = => ActionFn(20);
let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default();
let __end = __start.clone(); let __end = __start.clone();
let __nt = super::__action19::<>(input, &__start, &__end); let __nt = super::__action20::<>(input, &__start, &__end);
__symbols.push((__start, __Symbol::Variant8(__nt), __end)); __symbols.push((__start, __Symbol::Variant8(__nt), __end));
(0, 8) (0, 8)
} }
@ -869,11 +903,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Sym* = Sym+ => ActionFn(20); // Sym* = Sym+ => ActionFn(21);
let __sym0 = __pop_Variant8(__symbols); let __sym0 = __pop_Variant8(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action20::<>(input, __sym0); let __nt = super::__action21::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant8(__nt), __end)); __symbols.push((__start, __Symbol::Variant8(__nt), __end));
(1, 8) (1, 8)
} }
@ -887,11 +921,11 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Sym+ = Sym => ActionFn(21); // Sym+ = Sym => ActionFn(22);
let __sym0 = __pop_Variant7(__symbols); let __sym0 = __pop_Variant7(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action21::<>(input, __sym0); let __nt = super::__action22::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant8(__nt), __end)); __symbols.push((__start, __Symbol::Variant8(__nt), __end));
(1, 9) (1, 9)
} }
@ -905,13 +939,13 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Sym+ = Sym+, Sym => ActionFn(22); // Sym+ = Sym+, Sym => ActionFn(23);
assert!(__symbols.len() >= 2); assert!(__symbols.len() >= 2);
let __sym1 = __pop_Variant7(__symbols); let __sym1 = __pop_Variant7(__symbols);
let __sym0 = __pop_Variant8(__symbols); let __sym0 = __pop_Variant8(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym1.2.clone(); let __end = __sym1.2.clone();
let __nt = super::__action22::<>(input, __sym0, __sym1); let __nt = super::__action23::<>(input, __sym0, __sym1);
__symbols.push((__start, __Symbol::Variant8(__nt), __end)); __symbols.push((__start, __Symbol::Variant8(__nt), __end));
(2, 9) (2, 9)
} }
@ -969,19 +1003,21 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(3); // Tree = "(", "define", "(", Sym, RcSlice<Sym>, ")", Rc<Tree>, ")" => ActionFn(3);
assert!(__symbols.len() >= 6); assert!(__symbols.len() >= 8);
let __sym7 = __pop_Variant0(__symbols);
let __sym6 = __pop_Variant5(__symbols);
let __sym5 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant0(__symbols);
let __sym4 = __pop_Variant9(__symbols); let __sym4 = __pop_Variant6(__symbols);
let __sym3 = __pop_Variant9(__symbols); let __sym3 = __pop_Variant7(__symbols);
let __sym2 = __pop_Variant9(__symbols); let __sym2 = __pop_Variant0(__symbols);
let __sym1 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym5.2.clone(); let __end = __sym7.2.clone();
let __nt = super::__action3::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); let __nt = super::__action3::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6, __sym7);
__symbols.push((__start, __Symbol::Variant9(__nt), __end)); __symbols.push((__start, __Symbol::Variant9(__nt), __end));
(6, 10) (8, 10)
} }
pub(crate) fn __reduce19< pub(crate) fn __reduce19<
'input, 'input,
@ -993,12 +1029,12 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Tree = "(", "lambda (", RcSlice<Sym>, ")", Rc<Tree>, ")" => ActionFn(4); // Tree = "(", "if", Tree, Tree, Tree, ")" => ActionFn(4);
assert!(__symbols.len() >= 6); assert!(__symbols.len() >= 6);
let __sym5 = __pop_Variant0(__symbols); let __sym5 = __pop_Variant0(__symbols);
let __sym4 = __pop_Variant5(__symbols); let __sym4 = __pop_Variant9(__symbols);
let __sym3 = __pop_Variant0(__symbols); let __sym3 = __pop_Variant9(__symbols);
let __sym2 = __pop_Variant6(__symbols); let __sym2 = __pop_Variant9(__symbols);
let __sym1 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols);
let __sym0 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
@ -1017,13 +1053,19 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Tree = Literal => ActionFn(5); // Tree = "(", "lambda (", RcSlice<Sym>, ")", Rc<Tree>, ")" => ActionFn(5);
let __sym0 = __pop_Variant3(__symbols); assert!(__symbols.len() >= 6);
let __sym5 = __pop_Variant0(__symbols);
let __sym4 = __pop_Variant5(__symbols);
let __sym3 = __pop_Variant0(__symbols);
let __sym2 = __pop_Variant6(__symbols);
let __sym1 = __pop_Variant0(__symbols);
let __sym0 = __pop_Variant0(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym5.2.clone();
let __nt = super::__action5::<>(input, __sym0); let __nt = super::__action5::<>(input, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5);
__symbols.push((__start, __Symbol::Variant9(__nt), __end)); __symbols.push((__start, __Symbol::Variant9(__nt), __end));
(1, 10) (6, 10)
} }
pub(crate) fn __reduce21< pub(crate) fn __reduce21<
'input, 'input,
@ -1035,13 +1077,13 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Tree+ = Tree => ActionFn(17); // Tree = Literal => ActionFn(6);
let __sym0 = __pop_Variant9(__symbols); let __sym0 = __pop_Variant3(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action17::<>(input, __sym0); let __nt = super::__action6::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant10(__nt), __end)); __symbols.push((__start, __Symbol::Variant9(__nt), __end));
(1, 11) (1, 10)
} }
pub(crate) fn __reduce22< pub(crate) fn __reduce22<
'input, 'input,
@ -1053,13 +1095,31 @@ mod __parse__Tree {
_: core::marker::PhantomData<(&'input (), &'s ())>, _: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// Tree+ = Tree+, Tree => ActionFn(18); // Tree+ = Tree => ActionFn(18);
let __sym0 = __pop_Variant9(__symbols);
let __start = __sym0.0.clone();
let __end = __sym0.2.clone();
let __nt = super::__action18::<>(input, __sym0);
__symbols.push((__start, __Symbol::Variant10(__nt), __end));
(1, 11)
}
pub(crate) fn __reduce23<
'input,
's,
>(
input: &'input str,
__lookahead_start: Option<&usize>,
__symbols: &mut alloc::vec::Vec<(usize,__Symbol<'input>,usize)>,
_: core::marker::PhantomData<(&'input (), &'s ())>,
) -> (usize, usize)
{
// Tree+ = Tree+, Tree => ActionFn(19);
assert!(__symbols.len() >= 2); assert!(__symbols.len() >= 2);
let __sym1 = __pop_Variant9(__symbols); let __sym1 = __pop_Variant9(__symbols);
let __sym0 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant10(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym1.2.clone(); let __end = __sym1.2.clone();
let __nt = super::__action18::<>(input, __sym0, __sym1); let __nt = super::__action19::<>(input, __sym0, __sym1);
__symbols.push((__start, __Symbol::Variant10(__nt), __end)); __symbols.push((__start, __Symbol::Variant10(__nt), __end));
(2, 11) (2, 11)
} }
@ -1140,6 +1200,25 @@ fn __action2<
fn __action3< fn __action3<
'input, 'input,
's, 's,
>(
input: &'input str,
(_, _, _): (usize, &'input str, usize),
(_, _, _): (usize, &'input str, usize),
(_, _, _): (usize, &'input str, usize),
(_, name, _): (usize, String, usize),
(_, args, _): (usize, Rc<[String]>, usize),
(_, _, _): (usize, &'input str, usize),
(_, body, _): (usize, Rc<Tree>, usize),
(_, _, _): (usize, &'input str, usize),
) -> Tree
{
Tree::Define(name, Box::new(Tree::Lambda(Lambda(args, body))))
}
#[allow(unused_variables)]
fn __action4<
'input,
's,
>( >(
input: &'input str, input: &'input str,
(_, _, _): (usize, &'input str, usize), (_, _, _): (usize, &'input str, usize),
@ -1154,7 +1233,7 @@ fn __action3<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action4< fn __action5<
'input, 'input,
's, 's,
>( >(
@ -1171,7 +1250,7 @@ fn __action4<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action5< fn __action6<
'input, 'input,
's, 's,
>( >(
@ -1183,7 +1262,7 @@ fn __action5<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action6< fn __action7<
'input, 'input,
's, 's,
>( >(
@ -1195,7 +1274,7 @@ fn __action6<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action7< fn __action8<
'input, 'input,
's, 's,
>( >(
@ -1207,7 +1286,7 @@ fn __action7<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action8< fn __action9<
'input, 'input,
's, 's,
>( >(
@ -1219,7 +1298,7 @@ fn __action8<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action9< fn __action10<
'input, 'input,
's, 's,
>( >(
@ -1231,7 +1310,7 @@ fn __action9<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action10< fn __action11<
'input, 'input,
's, 's,
>( >(
@ -1243,7 +1322,7 @@ fn __action10<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action11< fn __action12<
'input, 'input,
's, 's,
>( >(
@ -1255,7 +1334,7 @@ fn __action11<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action12< fn __action13<
'input, 'input,
's, 's,
>( >(
@ -1267,7 +1346,7 @@ fn __action12<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action13< fn __action14<
'input, 'input,
's, 's,
>( >(
@ -1279,7 +1358,7 @@ fn __action13<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action14< fn __action15<
'input, 'input,
's, 's,
>( >(
@ -1291,7 +1370,7 @@ fn __action14<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action15< fn __action16<
'input, 'input,
's, 's,
>( >(
@ -1303,7 +1382,7 @@ fn __action15<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action16< fn __action17<
'input, 'input,
's, 's,
>( >(
@ -1315,7 +1394,7 @@ fn __action16<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action17< fn __action18<
'input, 'input,
's, 's,
>( >(
@ -1327,7 +1406,7 @@ fn __action17<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action18< fn __action19<
'input, 'input,
's, 's,
>( >(
@ -1340,7 +1419,7 @@ fn __action18<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action19< fn __action20<
'input, 'input,
's, 's,
>( >(
@ -1353,7 +1432,7 @@ fn __action19<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action20< fn __action21<
'input, 'input,
's, 's,
>( >(
@ -1365,7 +1444,7 @@ fn __action20<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action21< fn __action22<
'input, 'input,
's, 's,
>( >(
@ -1377,7 +1456,7 @@ fn __action21<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action22< fn __action23<
'input, 'input,
's, 's,
>( >(
@ -1390,7 +1469,7 @@ fn __action22<
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action23< fn __action24<
'input, 'input,
's, 's,
>( >(
@ -1401,20 +1480,20 @@ fn __action23<
{ {
let __start0 = __lookbehind.clone(); let __start0 = __lookbehind.clone();
let __end0 = __lookahead.clone(); let __end0 = __lookahead.clone();
let __temp0 = __action19( let __temp0 = __action20(
input, input,
&__start0, &__start0,
&__end0, &__end0,
); );
let __temp0 = (__start0, __temp0, __end0); let __temp0 = (__start0, __temp0, __end0);
__action16( __action17(
input, input,
__temp0, __temp0,
) )
} }
#[allow(unused_variables)] #[allow(unused_variables)]
fn __action24< fn __action25<
'input, 'input,
's, 's,
>( >(
@ -1424,12 +1503,12 @@ fn __action24<
{ {
let __start0 = __0.0.clone(); let __start0 = __0.0.clone();
let __end0 = __0.2.clone(); let __end0 = __0.2.clone();
let __temp0 = __action20( let __temp0 = __action21(
input, input,
__0, __0,
); );
let __temp0 = (__start0, __temp0, __end0); let __temp0 = (__start0, __temp0, __end0);
__action16( __action17(
input, input,
__temp0, __temp0,
) )

View File

@ -152,7 +152,7 @@ fn main() {
rl.add_history_entry(&line); rl.add_history_entry(&line);
let tree = grammar::TreeParser::new().parse(&line).unwrap(); let tree = grammar::TreeParser::new().parse(&line).unwrap();
dbg!(&tree); // dbg!(&tree);
println!("< {:?}", eval(&tree, &mut env)) println!("< {:?}", eval(&tree, &mut env))
} }
} }