summaryrefslogtreecommitdiff
path: root/dhall_generated_parser
diff options
context:
space:
mode:
authorNadrieril Feneanar2019-08-15 22:03:27 +0200
committerGitHub2019-08-15 22:03:27 +0200
commitb8234f63c27eb83ff54f719bf51bf3c969c36a3b (patch)
treeb04f1b2bec18ad5f24a1619f8e4b6c6bd491b831 /dhall_generated_parser
parenta9804009f405be7e8a89e301f280ee9d51b57e5e (diff)
parentffb5a4c26960960f526719d9b333df80119fef3c (diff)
Merge pull request #103 from Nadrieril/precedence-climbing
Use precedence climbing to parse expressions with operators
Diffstat (limited to 'dhall_generated_parser')
-rw-r--r--dhall_generated_parser/build.rs31
-rw-r--r--dhall_generated_parser/src/dhall.pest.visibility10
2 files changed, 36 insertions, 5 deletions
diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs
index 070aa9c..c562fad 100644
--- a/dhall_generated_parser/build.rs
+++ b/dhall_generated_parser/build.rs
@@ -51,6 +51,37 @@ fn main() -> std::io::Result<()> {
}}"
)?;
+ // Setup grammar for precedence climbing
+ rules.remove("operator_expression");
+ writeln!(&mut file, r##"
+ import_alt = {{ "?" ~ whsp1 }}
+ bool_or = {{ "||" }}
+ natural_plus = {{ "+" ~ whsp1 }}
+ text_append = {{ "++" }}
+ list_append = {{ "#" }}
+ bool_and = {{ "&&" }}
+ natural_times = {{ "*" }}
+ bool_eq = {{ "==" }}
+ bool_ne = {{ "!=" }}
+
+ operator = _{{
+ equivalent |
+ bool_ne |
+ bool_eq |
+ natural_times |
+ combine_types |
+ prefer |
+ combine |
+ bool_and |
+ list_append |
+ text_append |
+ natural_plus |
+ bool_or |
+ import_alt
+ }}
+ operator_expression = {{ application_expression ~ (whsp ~ operator ~ whsp ~ application_expression)* }}
+ "##)?;
+
writeln!(
&mut file,
"final_expression = ${{ SOI ~ complete_expression ~ EOI }}"
diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility
index 6b4c974..6fa5e01 100644
--- a/dhall_generated_parser/src/dhall.pest.visibility
+++ b/dhall_generated_parser/src/dhall.pest.visibility
@@ -84,10 +84,10 @@ Location
# Optional_fold
# Optional_build
# Text_show
-# combine
-# combine_types
-# equivalent
-# prefer
+combine
+combine_types
+equivalent
+prefer
lambda
forall
arrow
@@ -144,7 +144,7 @@ expression
annotated_expression
let_binding
empty_list_literal
-# operator_expression
+operator_expression
import_alt_expression
or_expression
plus_expression