fix: quote macro

This commit is contained in:
Roman Godmaire 2024-05-12 15:17:55 -04:00
parent 6c08af02a1
commit 5e98637ae0
3 changed files with 8 additions and 0 deletions

View file

@ -19,6 +19,12 @@ pub(super) fn standard() -> HashMap<String, Value> {
(macro* (name args body) ~(define (,name (fn* ,args ,body))) ) (macro* (name args body) ~(define (,name (fn* ,args ,body))) )
}, },
), ),
(
"quote",
inline! {
(macro* (var) ~^,var)
},
),
] ]
.into_iter() .into_iter()
.map(|(k, v)| (k.to_string(), Value::Node(v))) .map(|(k, v)| (k.to_string(), Value::Node(v)))

View file

@ -211,6 +211,7 @@ pub fn eval_node(env: &Environment, ast_node: Node) -> Result<Node> {
Node::Eval(list) => unquote!(Do, list), Node::Eval(list) => unquote!(Do, list),
Node::Apply(list) => unquote!(Apply, list), Node::Apply(list) => unquote!(Apply, list),
Node::Quote(node) => Ok(Node::Quote(Box::new(unquote(env, *node)?))),
Node::Unquote(_) => eval_node(env, node), Node::Unquote(_) => eval_node(env, node),
node => Ok(node), node => Ok(node),
} }

View file

@ -92,6 +92,7 @@ fn next_token(input: &mut Peekable<Chars>) -> Result<Option<Token>, Error> {
'{' => Token::LeftBrace, '{' => Token::LeftBrace,
'}' => Token::RightBrace, '}' => Token::RightBrace,
'^' => Token::Quote,
'\'' => Token::Quote, '\'' => Token::Quote,
'`' => Token::Quasiquote, '`' => Token::Quasiquote,
'~' => Token::Quasiquote, '~' => Token::Quasiquote,