summaryrefslogtreecommitdiff
path: root/dhall_core/src/parser.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-22 00:01:30 +0100
committerNadrieril2019-03-22 00:01:30 +0100
commitfe38fd6a8859447a154a5698a3e21d9203262be2 (patch)
tree814b0db038315f4b193374a9f5f9e672941bb0c3 /dhall_core/src/parser.rs
parent66e7c7750844bc976f23616c4a0103e778bdf4bd (diff)
Parse a lot more of the import types
Diffstat (limited to '')
-rw-r--r--dhall_core/src/parser.rs80
1 files changed, 60 insertions, 20 deletions
diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs
index 865e791..165b393 100644
--- a/dhall_core/src/parser.rs
+++ b/dhall_core/src/parser.rs
@@ -377,11 +377,7 @@ make_parser! {
));
rule!(path<PathBuf>; children!(
[path_component(components..)] => {
- let mut path = PathBuf::new();
- for s in components {
- path.push(s);
- }
- path
+ components.collect()
}
));
@@ -390,33 +386,69 @@ make_parser! {
rule!(parent_path<(FilePrefix, PathBuf)> as local_raw; children!(
[path(p)] => (FilePrefix::Parent, p)
));
-
rule!(here_path<(FilePrefix, PathBuf)> as local_raw; children!(
[path(p)] => (FilePrefix::Here, p)
));
-
rule!(home_path<(FilePrefix, PathBuf)> as local_raw; children!(
[path(p)] => (FilePrefix::Home, p)
));
-
rule!(absolute_path<(FilePrefix, PathBuf)> as local_raw; children!(
[path(p)] => (FilePrefix::Absolute, p)
));
+ rule!(scheme<Scheme>; captured_str!(s) => match s {
+ "http" => Scheme::HTTP,
+ "https" => Scheme::HTTPS,
+ _ => unreachable!(),
+ });
+
+ rule!(http_raw<URL>; children!(
+ [scheme(sch), authority(auth), path(p)] => URL {
+ scheme: sch,
+ authority: auth,
+ path: p,
+ query: None,
+ },
+ [scheme(sch), authority(auth), path(p), query(q)] => URL {
+ scheme: sch,
+ authority: auth,
+ path: p,
+ query: Some(q),
+ },
+ ));
+
+ rule!(authority<String>; captured_str!(s) => s.to_owned());
+
+ rule!(query<String>; captured_str!(s) => s.to_owned());
+
+ // TODO: headers
+ rule!(http<URL>; children!(
+ [http_raw(url)] => url
+ ));
+
+ rule!(env_raw<String>; children!(
+ [bash_environment_variable(s)] => s,
+ [posix_environment_variable(s)] => s,
+ ));
+ rule!(bash_environment_variable<String>; captured_str!(s) => s.to_owned());
+ rule!(posix_environment_variable<String>; captured_str!(s) => s.to_owned());
+
+ rule!(missing_raw<()>; raw_pair!(_) => ());
+
// TODO: other import types
rule!(import_type_raw<ImportLocation>; children!(
- // [missing_raw(_e)] => {
- // ImportLocation::Missing
- // }
- // [env_raw(e)] => {
- // ImportLocation::Env(e)
- // }
- // [http(url)] => {
- // ImportLocation::Remote(url)
- // }
+ [missing_raw(_)] => {
+ ImportLocation::Missing
+ },
+ [env_raw(e)] => {
+ ImportLocation::Env(e)
+ },
+ [http(url)] => {
+ ImportLocation::Remote(url)
+ },
[local_raw((prefix, path))] => {
ImportLocation::Local(prefix, path)
- }
+ },
));
rule!(import_hashed_raw<(ImportLocation, Option<()>)>; children!(
@@ -426,15 +458,23 @@ make_parser! {
rule_group!(expression<ParsedExpr>);
+ rule!(Text_raw<()>; raw_pair!(_) => ());
+
rule!(import_raw<ParsedExpr> as expression; children!(
- // TODO: handle "as Text"
[import_hashed_raw((location, hash))] => {
bx(Expr::Embed(Import {
mode: ImportMode::Code,
hash,
location,
}))
- }
+ },
+ [import_hashed_raw((location, hash)), Text_raw(_)] => {
+ bx(Expr::Embed(Import {
+ mode: ImportMode::RawText,
+ hash,
+ location,
+ }))
+ },
));
rule!(lambda_expression<ParsedExpr> as expression; children!(