summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2019-04-16 22:23:40 +0200
committerNadrieril2019-04-16 22:23:40 +0200
commite5d40d38735afb4252d6f25ee8f834f9b097e0f7 (patch)
tree5c3cf45d07c71e049eebc0b5a0ba70b0812d0678
parent47d5dbcfffa7842466187197513ffa403a0fdb59 (diff)
Tiny rename to save myself a lot of pain
Diffstat (limited to '')
-rw-r--r--abnf_to_pest/src/lib.rs7
-rw-r--r--dhall_core/src/parser.rs54
-rw-r--r--dhall_generated_parser/src/dhall.pest.visibility2
3 files changed, 34 insertions, 29 deletions
diff --git a/abnf_to_pest/src/lib.rs b/abnf_to_pest/src/lib.rs
index 625798b..d460bf9 100644
--- a/abnf_to_pest/src/lib.rs
+++ b/abnf_to_pest/src/lib.rs
@@ -25,9 +25,9 @@ use abnf::abnf::Rule;
pub use abnf::abnf::{
Alternation, Concatenation, Element, Range, Repeat, Repetition,
};
+use indexmap::map::IndexMap;
use itertools::Itertools;
use pretty::{BoxDoc, Doc};
-use indexmap::map::IndexMap;
trait Pretty {
fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>>;
@@ -116,6 +116,7 @@ impl Pretty for Range {
///
/// Replaces e.g. `if` with `if_`, and `rule-name` with `rule_name`.
/// Also changes `whitespace` to `whitespace_` because of https://github.com/pest-parser/pest/pull/374
+/// Also changes `Some` and `None` to `Some_` and `None_`, because it was such a pain to work around.
pub fn escape_rulename(x: &str) -> String {
let x = x.replace("-", "_");
if x == "if"
@@ -124,6 +125,9 @@ pub fn escape_rulename(x: &str) -> String {
|| x == "let"
|| x == "in"
|| x == "fn"
+ // Not required but such a pain
+ || x == "Some"
+ || x == "None"
// TODO: remove when https://github.com/pest-parser/pest/pull/375 gets into a release
|| x == "whitespace"
{
@@ -147,6 +151,7 @@ fn format_char(x: u32) -> String {
}
/// Allow control over some of the pest properties of the outputted rule
+#[derive(Debug, Clone)]
pub struct PestyRule {
pub silent: bool,
pub elements: Alternation,
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index b463073..c541283 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -511,15 +511,15 @@ make_parser! {
scheme: sch,
authority: auth,
path: p,
- query: Option::None,
- headers: Option::None,
+ query: None,
+ headers: None,
},
[scheme(sch), authority(auth), path(p), query(q)] => URL {
scheme: sch,
authority: auth,
path: p,
- query: Option::Some(q),
- headers: Option::None,
+ query: Some(q),
+ headers: None,
},
));
@@ -530,7 +530,7 @@ make_parser! {
rule!(http<URL>; children!(
[http_raw(url)] => url,
[http_raw(url), import_hashed(ih)] =>
- URL { headers: Option::Some(Box::new(ih)), ..url },
+ URL { headers: Some(Box::new(ih)), ..url },
));
rule!(env<String>; children!(
@@ -566,9 +566,9 @@ make_parser! {
rule!(import_hashed<ImportHashed>; children!(
[import_type(location)] =>
- ImportHashed { location, hash: Option::None },
+ ImportHashed { location, hash: None },
[import_type(location), hash(h)] =>
- ImportHashed { location, hash: Option::Some(h) },
+ ImportHashed { location, hash: Some(h) },
));
token_rule!(Text<()>);
@@ -617,10 +617,10 @@ make_parser! {
spanned(span, Pi("_".into(), rc(typ), rc(body)))
},
[merge(()), expression(x), expression(y), expression(z)] => {
- spanned(span, Merge(rc(x), rc(y), Option::Some(rc(z))))
+ spanned(span, Merge(rc(x), rc(y), Some(rc(z))))
},
[merge(()), expression(x), expression(y)] => {
- spanned(span, Merge(rc(x), rc(y), Option::None))
+ spanned(span, Merge(rc(x), rc(y), None))
},
[expression(e)] => e,
));
@@ -628,9 +628,9 @@ make_parser! {
rule!(let_binding<(Label, Option<ParsedSubExpr<'a>>, ParsedSubExpr<'a>)>;
children!(
[nonreserved_label(name), expression(annot), expression(expr)] =>
- (name, Option::Some(rc(annot)), rc(expr)),
+ (name, Some(rc(annot)), rc(expr)),
[nonreserved_label(name), expression(expr)] =>
- (name, Option::None, rc(expr)),
+ (name, None, rc(expr)),
));
token_rule!(List<()>);
@@ -647,7 +647,7 @@ make_parser! {
rule!(non_empty_optional<ParsedExpr<'a>> as expression; span; children!(
[expression(x), Optional(_), expression(t)] => {
- spanned(span, OldOptionalLit(Option::Some(rc(x)), rc(t)))
+ spanned(span, OldOptionalLit(Some(rc(x)), rc(t)))
}
));
@@ -743,11 +743,11 @@ make_parser! {
},
));
- token_rule!(Some<()>);
+ token_rule!(Some_<()>);
rule!(application_expression<ParsedExpr<'a>> as expression; span; children!(
[expression(e)] => e,
- [Some(()), expression(e), expression(rest)..] => {
+ [Some_(()), expression(e), expression(rest)..] => {
spanned(span, app(NEOptionalLit(rc(e)), rest.map(rc).collect()))
},
[expression(first), expression(rest)..] => {
@@ -787,8 +787,8 @@ make_parser! {
[label(l), natural_literal(idx)] => {
let name = String::from(&l);
spanned(span, match crate::Builtin::parse(name.as_str()) {
- Option::Some(b) => Builtin(b),
- Option::None => match name.as_str() {
+ Some(b) => Builtin(b),
+ None => match name.as_str() {
"True" => BoolLit(true),
"False" => BoolLit(false),
"Type" => Const(crate::Const::Type),
@@ -801,8 +801,8 @@ make_parser! {
[label(l)] => {
let name = String::from(&l);
spanned(span, match crate::Builtin::parse(name.as_str()) {
- Option::Some(b) => Builtin(b),
- Option::None => match name.as_str() {
+ Some(b) => Builtin(b),
+ None => match name.as_str() {
"True" => BoolLit(true),
"False" => BoolLit(false),
"Type" => Const(crate::Const::Type),
@@ -862,10 +862,10 @@ make_parser! {
[empty_union_type(_)] => {
spanned(span, UnionType(BTreeMap::new()))
},
- [non_empty_union_type_or_literal((Option::Some((l, e)), entries))] => {
+ [non_empty_union_type_or_literal((Some((l, e)), entries))] => {
spanned(span, UnionLit(l, e, entries))
},
- [non_empty_union_type_or_literal((Option::None, entries))] => {
+ [non_empty_union_type_or_literal((None, entries))] => {
spanned(span, UnionType(entries))
},
));
@@ -877,7 +877,7 @@ make_parser! {
BTreeMap<Label, Option<ParsedSubExpr<'a>>>)>;
children!(
[label(l), union_literal_variant_value((e, entries))] => {
- (Option::Some((l, e)), entries)
+ (Some((l, e)), entries)
},
[label(l), union_type_or_literal_variant_type((e, rest))] => {
let (x, mut entries) = rest;
@@ -895,8 +895,8 @@ make_parser! {
));
rule!(union_type_entry<(Label, Option<ParsedSubExpr<'a>>)>; children!(
- [label(name), expression(expr)] => (name, Option::Some(rc(expr))),
- [label(name)] => (name, Option::None),
+ [label(name), expression(expr)] => (name, Some(rc(expr))),
+ [label(name)] => (name, None),
));
// TODO: unary union variants
@@ -906,16 +906,16 @@ make_parser! {
BTreeMap<Label, Option<ParsedSubExpr<'a>>>))>;
children!(
[expression(e), non_empty_union_type_or_literal(rest)] => {
- (Option::Some(rc(e)), rest)
+ (Some(rc(e)), rest)
},
[expression(e)] => {
- (Option::Some(rc(e)), (Option::None, BTreeMap::new()))
+ (Some(rc(e)), (None, BTreeMap::new()))
},
[non_empty_union_type_or_literal(rest)] => {
- (Option::None, rest)
+ (None, rest)
},
[] => {
- (Option::None, (Option::None, BTreeMap::new()))
+ (None, (None, BTreeMap::new()))
},
));
diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility
index f881a50..4d8f3db 100644
--- a/dhall_generated_parser/src/dhall.pest.visibility
+++ b/dhall_generated_parser/src/dhall.pest.visibility
@@ -41,7 +41,7 @@ merge
missing
# Infinity
NaN
-Some
+Some_
# keyword
Optional
Text