edn: Allow comments.

EDN supports only one type of comment: initiated by ; and lasting
until the end of the current line or the end of the input stream.
This commit is contained in:
Nick Alexander 2017-01-17 11:25:31 -08:00 committed by Nick Alexander
parent 71a30fe69f
commit 247035cc9b
2 changed files with 12 additions and 2 deletions

View file

@ -25,7 +25,6 @@ use types::Value;
// to trace where the parser is failing // to trace where the parser is failing
// TODO: Support tagged elements // TODO: Support tagged elements
// TODO: Support comments
// TODO: Support discard // TODO: Support discard
#[export] #[export]
@ -137,5 +136,6 @@ value -> Value
list / vector / map / set list / vector / map / set
whitespace = (" " / "\r" / "\n" / "\t") whitespace = (" " / "\r" / "\n" / "\t")
comment = ";" [^\r\n]* ("\r" / "\n")?
__ = whitespace* __ = (whitespace / comment)*

View file

@ -799,6 +799,16 @@ fn test_query_find_title() {
assert_eq!(value(test).unwrap(), reply); assert_eq!(value(test).unwrap(), reply);
} }
#[test]
fn test_comments() {
let result = Ok(Value::Integer(0));
assert_eq!(value("0;"), result);
assert_eq!(value("0;x"), result);
assert_eq!(value("0;\n"), result);
assert_eq!(value("0;x\n"), result);
assert_eq!(value(";\n0"), result);
assert_eq!(value(";\r0"), result);
}
/* /*
// Handy templates for creating test cases follow: // Handy templates for creating test cases follow: