diff --git a/edn/Cargo.toml b/edn/Cargo.toml index c8cd57eb..fec4b9b4 100644 --- a/edn/Cargo.toml +++ b/edn/Cargo.toml @@ -14,7 +14,7 @@ chrono = "0.4" itertools = "0.8" num = "0.2" ordered-float = "1.0" -pretty = "0.9" +pretty = "0.2" uuid = { version = "0.8", features = ["v4", "serde"] } serde = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } diff --git a/edn/src/lib.rs b/edn/src/lib.rs index 59632e21..e8baf444 100644 --- a/edn/src/lib.rs +++ b/edn/src/lib.rs @@ -74,14 +74,6 @@ pub type ParseError = peg::error::ParseError; peg::parser!(pub grammar parse() for str { - // Clojure (and thus EDN) regards commas as whitespace, and thus the two-element vectors [1 2] and - // [1,,,,2] are equivalent, as are the maps {:a 1, :b 2} and {:a 1 :b 2}. - rule whitespace() = quiet!{[' ' | '\r' | '\n' | '\t' | ',']} - rule comment() = quiet!{";" (!['\r' | '\n'][_])* ['\r' | '\n']?} - - rule __() = whitespace() / comment()* - - pub rule nil() -> SpannedValue = "nil" { SpannedValue::Nil } pub rule nan() -> SpannedValue = "#f" whitespace()+ "NaN" { SpannedValue::Float(OrderedFloat(NAN)) } @@ -123,12 +115,12 @@ peg::parser!(pub grammar parse() for str { // TODO: standalone characters: \, \newline, \return, \space and \tab. // rule string_standalone_chars() -> - rule string_special_char() -> &'input str = c:$( "\\" $(['\\' | '"' | 'n' | 't' | 'r']) ) { c } - rule string_normal_chars() -> &'input str = c:$(['^' | '"' | '\\' ]+) { c } + rule string_special_char() -> &'input str = "\\" c:$(['\\' | '"' | 'n' | 't' | 'r']) { c } + rule string_normal_chars() -> &'input str = c:$((!['\"' | '\\'][_])+) { c } // This is what we need to do in order to unescape. We can't just match the entire string slice: - // we get a Vec<&str> from rust-peg, where some of the parts might be unescaped special characters, - // and we join it together to form an output string. + // we get a Vec<&str> from rust-peg, where some parts might be unescaped special characters and + // we join it together to form an output string. // E.g., input = r#"\"foo\\\\bar\""# // output = [quote, "foo", backslash, "bar", quote] // result = r#""foo\\bar""# @@ -240,6 +232,13 @@ peg::parser!(pub grammar parse() for str { rule atom() -> ValueAndSpan = v:value() {? if v.is_atom() { Ok(v) } else { Err("expected atom") } } + // Clojure (and thus EDN) regards commas as whitespace, and thus the two-element vectors [1 2] and + // [1,,,,2] are equivalent, as are the maps {:a 1, :b 2} and {:a 1 :b 2}. + rule whitespace() = quiet!{[' ' | '\r' | '\n' | '\t' | ',']} + rule comment() = quiet!{";" (!['\r' | '\n'][_])* ['\r' | '\n']?} + + rule __() = (whitespace() / comment())* + // Transaction entity parser starts here. pub rule op() -> OpType diff --git a/edn/src/pretty_print.rs b/edn/src/pretty_print.rs index 840240ef..07a27c79 100644 --- a/edn/src/pretty_print.rs +++ b/edn/src/pretty_print.rs @@ -56,7 +56,7 @@ impl Value { I: IntoIterator, { let open = open.into(); - let n = open.len() as isize; + let n = open.len();// as isize; let i = vs .into_iter() .map(|v| v.as_doc(allocator))