summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall_core/src/parser.rs4
-rw-r--r--dhall_parser/src/dhall.abnf149
-rw-r--r--dhall_parser/src/dhall.pest.visibility2
3 files changed, 54 insertions, 101 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index b4c1df4..4614673 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -467,7 +467,7 @@ make_parser! {
rule_group!(expression<ParsedExpr>);
- rule!(Text_raw<()>; captured_str!(_) => ());
+ rule!(Text<()>; captured_str!(_) => ());
rule!(import_raw<ParsedExpr> as expression; children!(
[import_hashed_raw((location, hash))] => {
@@ -477,7 +477,7 @@ make_parser! {
location,
}))
},
- [import_hashed_raw((location, hash)), Text_raw(_)] => {
+ [import_hashed_raw((location, hash)), Text(_)] => {
bx(Expr::Embed(Import {
mode: ImportMode::RawText,
hash,
diff --git a/dhall_parser/src/dhall.abnf b/dhall_parser/src/dhall.abnf
index f9ba91e..fa403ba 100644
--- a/dhall_parser/src/dhall.abnf
+++ b/dhall_parser/src/dhall.abnf
@@ -173,10 +173,8 @@ quoted-label = 1*quoted-label-char
; should be checked by implementations. The only place where this restriction applies
; is bound variables.
label-raw = ("`" quoted-label "`" / simple-label)
-label = label-raw whitespace
; An any-label is allowed to be one of the reserved identifiers.
-any-label = label
any-label-raw = label-raw
@@ -295,61 +293,19 @@ merge-raw = %x6d.65.72.67.65
missing-raw = %x6d.69.73.73.69.6e.67
Infinity-raw = %x49.6e.66.69.6e.69.74.79
; Reserved identifiers, only needed for some special cases of parsing
-Optional-raw = %x4f.70.74.69.6f.6e.61.6c
-Text-raw = %x54.65.78.74
-List-raw = %x4c.69.73.74
+Optional = %x4f.70.74.69.6f.6e.61.6c
+Text = %x54.65.78.74
+List = %x4c.69.73.74
Infinity-raw = %x49.6e.66.69.6e.69.74.79
NaN-raw = %x4e.61.4e
Some-raw = %x53.6f.6d.65
-; Whitespaced rules for reserved words, to be used when matching expressions
-if = if-raw nonempty-whitespace
-then = then-raw nonempty-whitespace
-else = else-raw nonempty-whitespace
-let = let-raw nonempty-whitespace
-in = in-raw nonempty-whitespace
-as = as-raw nonempty-whitespace
-using = using-raw nonempty-whitespace
-merge = merge-raw nonempty-whitespace
-Some = Some-raw nonempty-whitespace
-Optional = Optional-raw whitespace
-Text = Text-raw whitespace
-List = List-raw whitespace
-
-
-equal = "=" whitespace
-or = "||" whitespace
-plus = "+" nonempty-whitespace ; To disambiguate `f +2`
-text-append = "++" whitespace
-list-append = "#" whitespace
-and = "&&" whitespace
-times = "*" whitespace
-double-equal = "==" whitespace
-not-equal = "!=" whitespace
-dot = "." whitespace
-bar = "|" whitespace
-comma = "," whitespace
-at = "@" whitespace
-open-parens = "(" whitespace
-close-parens-raw = ")"
-close-parens = ")" whitespace
-open-brace = "{" whitespace
-close-brace-raw = "}"
-close-brace = "}" whitespace
-open-bracket = "[" whitespace
-close-bracket-raw = "]"
-close-bracket = "]" whitespace
-open-angle = "<" whitespace
-close-angle-raw = ">"
-close-angle = ">" whitespace
-colon = ":" nonempty-whitespace ; To disambiguate `env:VARIABLE` from type annotations
-import-alt = "?" nonempty-whitespace ; To disambiguate `http://a/a?a`
-combine = ( %x2227 / "/\" ) whitespace
-combine-types = ( %x2A53 / "//\\" ) whitespace
-prefer = ( %x2AFD / "//" ) whitespace
-lambda = ( %x3BB / "\" ) whitespace
-forall = ( %x2200 / %x66.6f.72.61.6c.6c ) whitespace
-arrow = ( %x2192 / "->" ) whitespace
+combine = %x2227 / "/\"
+combine-types = %x2A53 / "//\\"
+prefer = %x2AFD / "//"
+lambda = %x3BB / "\"
+forall = %x2200 / %x66.6f.72.61.6c.6c
+arrow = %x2192 / "->"
exponent = "e" [ "+" / "-" ] 1*DIGIT
@@ -361,8 +317,7 @@ integer-literal-raw = ( "+" / "-" ) natural-literal-raw
; The implementation should recognize reserved names for builtins and treat them as special
; values instead of variables.
-identifier-raw = any-label-raw [ whitespace at natural-literal-raw ]
-identifier = identifier-raw whitespace
+identifier-raw = any-label-raw [ whitespace "@" whitespace natural-literal-raw ]
; Printable characters other than " ()[]{}<>/\,"
;
@@ -489,7 +444,7 @@ sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
http =
http-raw
- [ whitespace using (import-hashed-raw / open-parens import-hashed-raw whitespace close-parens-raw) ]
+ [ whitespace using-raw nonempty-whitespace (import-hashed-raw / "(" whitespace import-hashed-raw whitespace ")") ]
; Dhall supports unquoted environment variables that are Bash-compliant or
; quoted environment variables that are POSIX-compliant
@@ -564,7 +519,7 @@ import-hashed-raw = import-type-raw [ whitespace hash-raw ]
; "http://example.com"
; "./foo/bar"
; "env:FOO"
-import-raw = import-hashed-raw [ whitespace as Text-raw ]
+import-raw = import-hashed-raw [ whitespace as-raw nonempty-whitespace Text ]
; NOTE: Every rule past this point should only reference rules that end with
; whitespace. This ensures consistent handling of whitespace in the absence of
@@ -587,52 +542,52 @@ expression =
/ annotated-expression
; "\(x : a) -> b"
-lambda-expression = lambda open-parens label colon expression close-parens arrow expression
+lambda-expression = lambda whitespace "(" whitespace label-raw whitespace ":" nonempty-whitespace expression ")" whitespace arrow whitespace expression
; "if a then b else c"
-ifthenelse-expression = if expression then expression else expression
+ifthenelse-expression = if-raw nonempty-whitespace expression then-raw nonempty-whitespace expression else-raw nonempty-whitespace expression
; "let x : t = e1 in e2"
; "let x = e1 in e2"
; "let x = e1 let y = e2 in e3"
-let-expression = 1*let-binding in expression
-let-binding = let label [ colon expression ] equal expression
+let-expression = 1*let-binding in-raw nonempty-whitespace expression
+let-binding = let-raw nonempty-whitespace label-raw whitespace [ ":" nonempty-whitespace expression ] "=" whitespace expression
; "forall (x : a) -> b"
-forall-expression = forall open-parens label colon expression close-parens arrow expression
+forall-expression = forall whitespace "(" whitespace label-raw whitespace ":" nonempty-whitespace expression ")" whitespace arrow whitespace expression
; "a -> b"
-arrow-expression = operator-expression arrow expression
+arrow-expression = operator-expression arrow whitespace expression
; "merge e1 e2 : t"
; "merge e1 e2"
-merge-expression = merge import-expression import-expression [ colon application-expression ]
+merge-expression = merge-raw nonempty-whitespace import-expression import-expression [ ":" nonempty-whitespace application-expression ]
; "[] : List t"
; "[] : Optional t"
; "[x] : Optional t"
-empty-list-or-optional = open-bracket (empty-collection / non-empty-optional)
-empty-collection = close-bracket colon (List / Optional) import-expression
-non-empty-optional = expression close-bracket colon Optional import-expression
+empty-list-or-optional = "[" whitespace (empty-collection / non-empty-optional)
+empty-collection = "]" whitespace ":" nonempty-whitespace (List whitespace / Optional whitespace) import-expression
+non-empty-optional = expression "]" whitespace ":" nonempty-whitespace Optional whitespace import-expression
; "x : t"
-annotated-expression = operator-expression [ colon expression ]
+annotated-expression = operator-expression [ ":" nonempty-whitespace expression ]
operator-expression = import-alt-expression
-import-alt-expression = or-expression *(import-alt or-expression)
-or-expression = plus-expression *(or plus-expression )
-plus-expression = text-append-expression *(plus text-append-expression )
-text-append-expression = list-append-expression *(text-append list-append-expression )
-list-append-expression = and-expression *(list-append and-expression )
-and-expression = combine-expression *(and combine-expression )
-combine-expression = prefer-expression *(combine prefer-expression )
-prefer-expression = combine-types-expression *(prefer combine-types-expression)
-combine-types-expression = times-expression *(combine-types times-expression )
-times-expression = equal-expression *(times equal-expression )
-equal-expression = not-equal-expression *(double-equal not-equal-expression )
-not-equal-expression = application-expression *(not-equal application-expression )
+import-alt-expression = or-expression *("?" nonempty-whitespace or-expression)
+or-expression = plus-expression *("||" whitespace plus-expression )
+plus-expression = text-append-expression *("+" nonempty-whitespace text-append-expression )
+text-append-expression = list-append-expression *("++" whitespace list-append-expression )
+list-append-expression = and-expression *("#" whitespace and-expression )
+and-expression = combine-expression *("&&" whitespace combine-expression )
+combine-expression = prefer-expression *(combine whitespace prefer-expression )
+prefer-expression = combine-types-expression *(prefer whitespace combine-types-expression)
+combine-types-expression = times-expression *(combine-types whitespace times-expression )
+times-expression = equal-expression *("*" whitespace equal-expression )
+equal-expression = not-equal-expression *("==" whitespace not-equal-expression )
+not-equal-expression = application-expression *("!=" whitespace application-expression )
; Import expressions need to be separated by some whitespace, otherwise there
; would be ambiguity: `./ab` could be interpreted as "import the file `./ab`",
@@ -652,17 +607,17 @@ import-expression-raw =
; can't tell from parsing just the period whether "foo." will become "foo.bar"
; (i.e. accessing field `bar` of the record `foo`) or `foo./bar` (i.e. applying
; the function `foo` to the relative path `./bar`)
-selector-expression-raw = primitive-expression-raw *(whitespace dot selector-raw)
+selector-expression-raw = primitive-expression-raw *(whitespace "." whitespace selector-raw)
selector-raw = any-label-raw / labels-raw
-labels-raw = open-brace [ any-label *(comma any-label) ] close-brace-raw
+labels-raw = "{" whitespace [ any-label-raw whitespace *("," whitespace any-label-raw whitespace) ] "}"
primitive-expression-raw =
literal-expression-raw
- / open-brace record-type-or-literal close-brace-raw
- / open-angle union-type-or-literal close-angle-raw
+ / "{" whitespace record-type-or-literal "}"
+ / "<" whitespace union-type-or-literal ">"
/ non-empty-list-literal-raw
/ parenthesized-expression-raw
@@ -701,14 +656,14 @@ record-type-or-literal =
empty-record-literal
/ non-empty-record-type-or-literal
/ empty-record-type
-empty-record-literal = equal
+empty-record-literal = "=" whitespace
empty-record-type = ""
non-empty-record-type-or-literal =
- any-label (non-empty-record-literal / non-empty-record-type)
-non-empty-record-type = colon expression *(comma record-type-entry)
-record-type-entry = any-label colon expression
-non-empty-record-literal = equal expression *(comma record-literal-entry)
-record-literal-entry = any-label equal expression
+ any-label-raw whitespace (non-empty-record-literal / non-empty-record-type)
+non-empty-record-type = ":" nonempty-whitespace expression *("," whitespace record-type-entry)
+record-type-entry = any-label-raw whitespace ":" nonempty-whitespace expression
+non-empty-record-literal = "=" whitespace expression *("," whitespace record-literal-entry)
+record-literal-entry = any-label-raw whitespace "=" whitespace expression
; "< Foo : Integer | Bar : Bool >"
; "< Foo : Integer | Bar = True >"
@@ -717,19 +672,19 @@ union-type-or-literal =
/ empty-union-type
empty-union-type = ""
non-empty-union-type-or-literal =
- any-label
- ( equal expression union-type-entries
- / colon expression [ bar non-empty-union-type-or-literal ]
+ any-label-raw whitespace
+ ( "=" whitespace expression union-type-entries
+ / ":" nonempty-whitespace expression [ "|" whitespace non-empty-union-type-or-literal ]
)
-union-type-entries = *(bar union-type-entry)
-union-type-entry = any-label colon expression
+union-type-entries = *("|" whitespace union-type-entry)
+union-type-entry = any-label-raw whitespace ":" nonempty-whitespace expression
; "[1, 2, 3]"
; `empty-list-or-optional` handles empty lists
-non-empty-list-literal-raw = open-bracket expression *(comma expression) close-bracket-raw
+non-empty-list-literal-raw = "[" whitespace expression *("," whitespace expression) "]"
; "( e )"
-parenthesized-expression-raw = open-parens expression close-parens-raw
+parenthesized-expression-raw = "(" whitespace expression ")"
; All expressions end with trailing whitespace. This just adds a final
diff --git a/dhall_parser/src/dhall.pest.visibility b/dhall_parser/src/dhall.pest.visibility
index da5217a..ae3fa84 100644
--- a/dhall_parser/src/dhall.pest.visibility
+++ b/dhall_parser/src/dhall.pest.visibility
@@ -21,9 +21,7 @@ simple_label
# quoted_label_char
quoted_label
label_raw
-# label
# any_label_raw
-# any_label
double_quote_chunk
double_quote_escaped
double_quote_literal