From f434e3fd016b30e2f8661f3b77feaaa3c67a3406 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 5 Mar 2019 21:33:50 +0100 Subject: Add literal_expression_raw back --- dhall/src/parser.rs | 57 +++++++++++++++++----------------- dhall_parser/src/dhall.pest.visibility | 2 +- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/dhall/src/parser.rs b/dhall/src/parser.rs index a2a3016..57af7b8 100644 --- a/dhall/src/parser.rs +++ b/dhall/src/parser.rs @@ -454,22 +454,6 @@ rule!(single_quote_continue>; }, ); -named!(natural; - raw_pair!(pair) => { - pair.as_str().trim() - .parse() - .map_err(|e: std::num::ParseIntError| custom_parse_error(&pair, format!("{}", e)))? - } -); - -named!(integer; - raw_pair!(pair) => { - pair.as_str().trim() - .parse() - .map_err(|e: std::num::ParseIntError| custom_parse_error(&pair, format!("{}", e)))? - } -); - rule!(let_binding<(&'a str, Option>, BoxExpr<'a>)>; children!(name: str, annot?: expression, expr: expression) => (name, annot, expr) ); @@ -530,10 +514,6 @@ rule!(non_empty_union_type_or_literal rule!(empty_union_type<()>; children!() => ()); rule_group!(expression>; - double_quote_literal, - single_quote_literal, - natural_literal_raw, - integer_literal_raw, identifier_raw, lambda_expression, ifthenelse_expression, @@ -560,6 +540,7 @@ rule_group!(expression>; application_expression, selector_expression_raw, + literal_expression_raw, empty_record_type, empty_record_literal, non_empty_record_type_or_literal, @@ -569,27 +550,36 @@ rule_group!(expression>; ); // TODO: parse escapes and interpolation -rule!(double_quote_literal>; +rule!(double_quote_literal; children!(strs*: raw_str) => { - bx(Expr::TextLit(strs.collect())) + strs.collect() } ); -rule!(single_quote_literal>; +rule!(single_quote_literal; children!(eol: raw_str, contents: single_quote_continue) => { contents.push(eol); - bx(Expr::TextLit(contents.into_iter().rev().collect())) + contents.into_iter().rev().collect() } ); -rule!(natural_literal_raw>; - self!(n: natural) => bx(Expr::NaturalLit(n)) +rule!(natural_literal_raw; + raw_pair!(pair) => { + pair.as_str().trim() + .parse() + .map_err(|e: std::num::ParseIntError| custom_parse_error(&pair, format!("{}", e)))? + } ); -rule!(integer_literal_raw>; - self!(n: integer) => bx(Expr::IntegerLit(n)) + +rule!(integer_literal_raw; + raw_pair!(pair) => { + pair.as_str().trim() + .parse() + .map_err(|e: std::num::ParseIntError| custom_parse_error(&pair, format!("{}", e)))? + } ); rule!(identifier_raw>; - children!(name: str, idx?: natural) => { + children!(name: str, idx?: natural_literal_raw) => { match Builtin::parse(name) { Some(b) => bx(Expr::Builtin(b)), None => match name { @@ -686,6 +676,14 @@ rule!(selector_expression_raw>; } ); +rule!(literal_expression_raw>; + 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)), + children!(s: single_quote_literal) => bx(Expr::TextLit(s)), + children!(e: expression) => e, +); + rule!(empty_record_type>; children!() => bx(Expr::Record(BTreeMap::new())) ); @@ -716,6 +714,7 @@ rule!(union_type_or_literal>; } }, ); + rule!(non_empty_list_literal_raw>; children!(items*: expression) => { bx(Expr::ListLit(None, items.map(|x| *x).collect())) diff --git a/dhall_parser/src/dhall.pest.visibility b/dhall_parser/src/dhall.pest.visibility index e9bf241..b3a2660 100644 --- a/dhall_parser/src/dhall.pest.visibility +++ b/dhall_parser/src/dhall.pest.visibility @@ -153,7 +153,7 @@ selector_expression_raw selector_raw labels_raw # primitive_expression_raw -# literal_expression_raw +literal_expression_raw # record_type_or_literal empty_record_literal empty_record_type -- cgit v1.2.3