Fixes some mistakes when updating the grammar.
This commit is contained in:
parent
60c65033b2
commit
9421a5c3bb
3 changed files with 13 additions and 14 deletions
|
@ -14,7 +14,7 @@ chrono = "0.4"
|
||||||
itertools = "0.8"
|
itertools = "0.8"
|
||||||
num = "0.2"
|
num = "0.2"
|
||||||
ordered-float = "1.0"
|
ordered-float = "1.0"
|
||||||
pretty = "0.9"
|
pretty = "0.2"
|
||||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
serde_derive = { version = "1.0", optional = true }
|
serde_derive = { version = "1.0", optional = true }
|
||||||
|
|
|
@ -74,14 +74,6 @@ pub type ParseError = peg::error::ParseError<peg::str::LineCol>;
|
||||||
|
|
||||||
peg::parser!(pub grammar parse() for str {
|
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 nil() -> SpannedValue = "nil" { SpannedValue::Nil }
|
||||||
pub rule nan() -> SpannedValue = "#f" whitespace()+ "NaN" { SpannedValue::Float(OrderedFloat(NAN)) }
|
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: \<char>, \newline, \return, \space and \tab.
|
// TODO: standalone characters: \<char>, \newline, \return, \space and \tab.
|
||||||
// rule string_standalone_chars() ->
|
// rule string_standalone_chars() ->
|
||||||
rule string_special_char() -> &'input str = c:$( "\\" $(['\\' | '"' | 'n' | 't' | 'r']) ) { c }
|
rule string_special_char() -> &'input str = "\\" c:$(['\\' | '"' | 'n' | 't' | 'r']) { c }
|
||||||
rule string_normal_chars() -> &'input str = c:$(['^' | '"' | '\\' ]+) { 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:
|
// 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,
|
// we get a Vec<&str> from rust-peg, where some parts might be unescaped special characters and
|
||||||
// and we join it together to form an output string.
|
// we join it together to form an output string.
|
||||||
// E.g., input = r#"\"foo\\\\bar\""#
|
// E.g., input = r#"\"foo\\\\bar\""#
|
||||||
// output = [quote, "foo", backslash, "bar", quote]
|
// output = [quote, "foo", backslash, "bar", quote]
|
||||||
// result = r#""foo\\bar""#
|
// result = r#""foo\\bar""#
|
||||||
|
@ -240,6 +232,13 @@ peg::parser!(pub grammar parse() for str {
|
||||||
rule atom() -> ValueAndSpan
|
rule atom() -> ValueAndSpan
|
||||||
= v:value() {? if v.is_atom() { Ok(v) } else { Err("expected atom") } }
|
= 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.
|
// Transaction entity parser starts here.
|
||||||
|
|
||||||
pub rule op() -> OpType
|
pub rule op() -> OpType
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl Value {
|
||||||
I: IntoIterator<Item = &'a Value>,
|
I: IntoIterator<Item = &'a Value>,
|
||||||
{
|
{
|
||||||
let open = open.into();
|
let open = open.into();
|
||||||
let n = open.len() as isize;
|
let n = open.len();// as isize;
|
||||||
let i = vs
|
let i = vs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| v.as_doc(allocator))
|
.map(|v| v.as_doc(allocator))
|
||||||
|
|
Loading…
Reference in a new issue