summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------dhall-lang0
-rw-r--r--dhall/build.rs8
-rw-r--r--dhall/src/dhall.pest.visibility4
-rw-r--r--dhall/src/syntax/text/parser.rs23
4 files changed, 22 insertions, 13 deletions
diff --git a/dhall-lang b/dhall-lang
-Subproject 3b31dea1ba47f9de041a7288826f07a05a167ba
+Subproject 464b7358545a0d5c10d0aa987fed94bedc7f516
diff --git a/dhall/build.rs b/dhall/build.rs
index 70389bf..981e558 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -414,12 +414,20 @@ fn convert_abnf_to_pest() -> std::io::Result<()> {
rules.remove("url_path");
writeln!(&mut file, "url_path = _{{ path }}")?;
+ // Work around some greediness issue in the grammar.
rules.remove("missing");
writeln!(
&mut file,
r#"missing = {{ "missing" ~ !simple_label_next_char }}"#
)?;
+ // Prefer my nice error message to illegible parse errors.
+ rules.remove("unicode_escape");
+ writeln!(
+ &mut file,
+ r#"unicode_escape = _{{ HEXDIG{{4}} | "{{" ~ HEXDIG+ ~ "}}" }}"#
+ )?;
+
rules.remove("simple_label");
writeln!(
&mut file,
diff --git a/dhall/src/dhall.pest.visibility b/dhall/src/dhall.pest.visibility
index 41aa833..5d3b4c8 100644
--- a/dhall/src/dhall.pest.visibility
+++ b/dhall/src/dhall.pest.visibility
@@ -24,6 +24,10 @@ quoted_label
double_quote_chunk
double_quote_escaped
# unicode_escape
+# unicode_suffix
+# unbraced_escape
+# braced_codepoint
+# braced_escape
double_quote_char
double_quote_literal
single_quote_continue
diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs
index d9e5c3b..27e0382 100644
--- a/dhall/src/syntax/text/parser.rs
+++ b/dhall/src/syntax/text/parser.rs
@@ -217,19 +217,18 @@ impl DhallParser {
"t" => "\t".to_owned(),
// "uXXXX" or "u{XXXXX}"
s => {
- use std::convert::{TryFrom, TryInto};
+ use std::convert::TryInto;
let s = &s[1..];
let s = if &s[0..1] == "{" {
&s[1..s.len() - 1]
} else {
- &s[0..s.len()]
+ s
};
if s.len() > 8 {
Err(input.error(format!(
- "Escape sequences can't have more than 8 chars: \"{}\"",
- s
+ "Escape sequences can't have more than 8 chars"
)))?
}
@@ -242,12 +241,10 @@ impl DhallParser {
// `s` has length 8, so `bytes` has length 4
let bytes: &[u8] = &hex::decode(s).unwrap();
let i = u32::from_be_bytes(bytes.try_into().unwrap());
- let c = char::try_from(i).unwrap();
match i {
- 0xD800..=0xDFFF => {
- let c_ecapsed = c.escape_unicode();
- Err(input.error(format!("Escape sequences can't contain surrogate pairs: \"{}\"", c_ecapsed)))?
- }
+ 0xD800..=0xDFFF => Err(input.error(format!(
+ "Escape sequences can't contain surrogate pairs"
+ )))?,
0x0FFFE..=0x0FFFF
| 0x1FFFE..=0x1FFFF
| 0x2FFFE..=0x2FFFF
@@ -264,12 +261,12 @@ impl DhallParser {
| 0xDFFFE..=0xDFFFF
| 0xEFFFE..=0xEFFFF
| 0xFFFFE..=0xFFFFF
- | 0x10_FFFE..=0x10_FFFF => {
- let c_ecapsed = c.escape_unicode();
- Err(input.error(format!("Escape sequences can't contain non-characters: \"{}\"", c_ecapsed)))?
- }
+ | 0x10_FFFE..=0x10_FFFF => Err(input.error(format!(
+ "Escape sequences can't contain non-characters"
+ )))?,
_ => {}
}
+ let c: char = i.try_into().unwrap();
std::iter::once(c).collect()
}
})