summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall/src/parser.rs16
-rw-r--r--dhall_parser/build.rs10
-rw-r--r--dhall_parser/src/dhall.abnf10
-rw-r--r--dhall_parser/src/dhall.pest.visibility2
4 files changed, 34 insertions, 4 deletions
diff --git a/dhall/src/parser.rs b/dhall/src/parser.rs
index 57af7b8..7bdc085 100644
--- a/dhall/src/parser.rs
+++ b/dhall/src/parser.rs
@@ -562,6 +562,18 @@ rule!(single_quote_literal<String>;
}
);
+rule!(double_literal_raw<f64>;
+ raw_pair!(pair) => {
+ pair.as_str().trim()
+ .parse()
+ .map_err(|e: std::num::ParseFloatError| custom_parse_error(&pair, format!("{}", e)))?
+ }
+);
+
+rule!(minus_infinity_literal<()>; children!() => ());
+rule!(plus_infinity_literal<()>; children!() => ());
+rule!(NaN_raw<()>; children!() => ());
+
rule!(natural_literal_raw<usize>;
raw_pair!(pair) => {
pair.as_str().trim()
@@ -677,6 +689,10 @@ rule!(selector_expression_raw<BoxExpr<'a>>;
);
rule!(literal_expression_raw<BoxExpr<'a>>;
+ children!(n: double_literal_raw) => bx(Expr::DoubleLit(n)),
+ children!(n: minus_infinity_literal) => bx(Expr::DoubleLit(std::f64::NEG_INFINITY)),
+ children!(n: plus_infinity_literal) => bx(Expr::DoubleLit(std::f64::INFINITY)),
+ children!(n: NaN_raw) => bx(Expr::DoubleLit(std::f64::NAN)),
children!(n: natural_literal_raw) => bx(Expr::NaturalLit(n)),
children!(n: integer_literal_raw) => bx(Expr::IntegerLit(n)),
children!(s: double_quote_literal) => bx(Expr::TextLit(s)),
diff --git a/dhall_parser/build.rs b/dhall_parser/build.rs
index 3ca36b5..743aa2d 100644
--- a/dhall_parser/build.rs
+++ b/dhall_parser/build.rs
@@ -38,8 +38,14 @@ fn main() -> std::io::Result<()> {
let mut file = File::create(pest_path)?;
writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?;
writeln!(&mut file, "{}", abnf_to_pest(&data, &rule_settings)?)?;
- writeln!(&mut file, "keyword_raw = _{{ let_raw | in_raw | if_raw | then_raw | else_raw }}")?;
- writeln!(&mut file, "final_expression = {{ SOI ~ complete_expression ~ EOI }}")?;
+ writeln!(&mut file, "keyword_raw = _{{
+ let_raw | in_raw | if_raw | then_raw
+ | else_raw | Infinity_raw | NaN_raw
+ }}")?;
+ writeln!(
+ &mut file,
+ "final_expression = {{ SOI ~ complete_expression ~ EOI }}"
+ )?;
Ok(())
}
diff --git a/dhall_parser/src/dhall.abnf b/dhall_parser/src/dhall.abnf
index e311aa6..76af24b 100644
--- a/dhall_parser/src/dhall.abnf
+++ b/dhall_parser/src/dhall.abnf
@@ -279,6 +279,7 @@ Optional-raw = %x4f.70.74.69.6f.6e.61.6c
Text-raw = %x54.65.78.74
List-raw = %x4c.69.73.74
Infinity-raw = %x49.6e.66.69.6e.69.74.79
+NaN-raw = %x4e.61.4e
; Whitespaced rules for reserved words, to be used when matching expressions
if = if-raw nonempty-whitespace
@@ -648,7 +649,11 @@ literal-expression-raw =
/ integer-literal-raw
; "-Infinity"
- / "-" Infinity-raw
+ / minus-infinity-literal
+ ; "Infinity"
+ / plus-infinity-literal
+ ; "NaN"
+ / NaN-raw
; '"ABC"'
/ text-literal-raw
@@ -657,6 +662,9 @@ literal-expression-raw =
; "x@2"
/ identifier-raw
+minus-infinity-literal = "-" Infinity-raw
+plus-infinity-literal = Infinity-raw
+
; "{ foo = 1 , bar = True }"
; "{ foo : Integer, bar : Bool }"
record-type-or-literal =
diff --git a/dhall_parser/src/dhall.pest.visibility b/dhall_parser/src/dhall.pest.visibility
index b3a2660..08171b3 100644
--- a/dhall_parser/src/dhall.pest.visibility
+++ b/dhall_parser/src/dhall.pest.visibility
@@ -37,7 +37,7 @@ single_quote_literal
# Optional_raw
# Text_raw
# List_raw
-Infinity_raw
+# Infinity_raw
# if_
# then
# else_