True and False primitives
This commit is contained in:
parent
fcd980f148
commit
f6d047e3b8
@ -53,6 +53,8 @@ impl EvaluatorState {
|
|||||||
SymbolAtom(sym) => unimplemented!(),
|
SymbolAtom(sym) => unimplemented!(),
|
||||||
expr @ StringAtom(_) => expr,
|
expr @ StringAtom(_) => expr,
|
||||||
expr @ NumberAtom(_) => expr,
|
expr @ NumberAtom(_) => expr,
|
||||||
|
True => True,
|
||||||
|
False => False,
|
||||||
Cons(box operator, box operands) => {
|
Cons(box operator, box operands) => {
|
||||||
match operator {
|
match operator {
|
||||||
SymbolAtom(ref sym) => match &sym[..] {
|
SymbolAtom(ref sym) => match &sym[..] {
|
||||||
@ -116,6 +118,8 @@ enum Sexp {
|
|||||||
SymbolAtom(String),
|
SymbolAtom(String),
|
||||||
StringAtom(String),
|
StringAtom(String),
|
||||||
NumberAtom(u64),
|
NumberAtom(u64),
|
||||||
|
True,
|
||||||
|
False,
|
||||||
Cons(Box<Sexp>, Box<Sexp>),
|
Cons(Box<Sexp>, Box<Sexp>),
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
@ -124,6 +128,8 @@ impl Sexp {
|
|||||||
fn print(&self) -> String {
|
fn print(&self) -> String {
|
||||||
use self::Sexp::*;
|
use self::Sexp::*;
|
||||||
match self {
|
match self {
|
||||||
|
&True => format!("#t"),
|
||||||
|
&False => format!("#f"),
|
||||||
&SymbolAtom(ref sym) => format!("{}", sym),
|
&SymbolAtom(ref sym) => format!("{}", sym),
|
||||||
&StringAtom(ref s) => format!("\"{}\"", s),
|
&StringAtom(ref s) => format!("\"{}\"", s),
|
||||||
&NumberAtom(ref n) => format!("{}", n),
|
&NumberAtom(ref n) => format!("{}", n),
|
||||||
@ -179,6 +185,8 @@ fn parse(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
|
|||||||
use self::Token::*;
|
use self::Token::*;
|
||||||
use self::Sexp::*;
|
use self::Sexp::*;
|
||||||
match tokens.next() {
|
match tokens.next() {
|
||||||
|
Some(Word(ref s)) if s == "#f" => Ok(False),
|
||||||
|
Some(Word(ref s)) if s == "#t" => Ok(True),
|
||||||
Some(Word(s)) => Ok(SymbolAtom(s)),
|
Some(Word(s)) => Ok(SymbolAtom(s)),
|
||||||
Some(StringLiteral(s)) => Ok(StringAtom(s)),
|
Some(StringLiteral(s)) => Ok(StringAtom(s)),
|
||||||
Some(LParen) => parse_sexp(tokens),
|
Some(LParen) => parse_sexp(tokens),
|
||||||
|
Loading…
Reference in New Issue
Block a user