diff --git a/lexpr-macros/src/parser.rs b/lexpr-macros/src/parser.rs index 65675f1..5e7e57e 100644 --- a/lexpr-macros/src/parser.rs +++ b/lexpr-macros/src/parser.rs @@ -66,6 +66,19 @@ impl Parser { } _ => Ok(Value::Symbol(c.to_string())), }, + ':' => match self.peek() { + Some(TokenTree::Literal(lit)) => { + let name = string_literal(lit)?; + self.eat_token(); + Ok(Value::Keyword(name)) + }, + Some(TokenTree::Ident(ident)) => { + let name = ident.to_string(); + self.eat_token(); + Ok(Value::Keyword(name)) + }, + _ => Ok(Value::Symbol(c.to_string())), + }, _ => Ok(Value::Symbol(c.to_string())), }, } diff --git a/lexpr/tests/sexp-macro.rs b/lexpr/tests/sexp-macro.rs index 11ffaaf..2aa9e41 100644 --- a/lexpr/tests/sexp-macro.rs +++ b/lexpr/tests/sexp-macro.rs @@ -18,6 +18,7 @@ fn test_symbols() { #[test] fn test_keywords() { assert_eq!(sexp!(#:foo), Value::keyword("foo")); + assert_eq!(sexp!(:foo), Value::keyword("foo")); assert_eq!(sexp!(#:"a-keyword"), Value::keyword("a-keyword")); } @@ -36,6 +37,8 @@ fn test_cons() { sexp! {((a . 256.0))}, Value::list(vec![Value::cons(Value::symbol("a"), Value::from(256.0))]) ); + assert_eq!(sexp!((#:foo)), Value::cons(Value::keyword("foo"), Value::Null)); + assert_eq!(sexp!((:foo)), Value::cons(Value::keyword("foo"), Value::Null)); } #[test]