diff options
author | Nadrieril Feneanar | 2020-03-20 11:26:41 +0000 |
---|---|---|
committer | GitHub | 2020-03-20 11:26:41 +0000 |
commit | 98b067309388d3f7c692dd82634e776113ea342b (patch) | |
tree | 33ed2e15ea5c4873f31b953760b494569ae3b9a7 /dhall/src/syntax | |
parent | cf91173c6e9f57dc9e9dbd9a34dca28d093fa7d9 (diff) | |
parent | 159b2ccede0d5559fe3ff9681ccfff314e608b35 (diff) |
Merge pull request #151 from Nadrieril/rfc-urls2
Parse RFC3986 URLs
Diffstat (limited to '')
-rw-r--r-- | dhall/src/syntax/text/dhall.pest.visibility | 2 | ||||
-rw-r--r-- | dhall/src/syntax/text/parser.rs | 22 |
2 files changed, 22 insertions, 2 deletions
diff --git a/dhall/src/syntax/text/dhall.pest.visibility b/dhall/src/syntax/text/dhall.pest.visibility index 2a89076..b2114ce 100644 --- a/dhall/src/syntax/text/dhall.pest.visibility +++ b/dhall/src/syntax/text/dhall.pest.visibility @@ -120,6 +120,7 @@ home_path absolute_path scheme http_raw +url_path authority # userinfo # host @@ -133,6 +134,7 @@ authority # dec_octet # domain # domainlabel +segment # pchar query # pct_encoded diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 5686300..03211c7 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -551,14 +551,14 @@ impl DhallParser { fn http_raw(input: ParseInput) -> ParseResult<URL<Expr>> { Ok(match_nodes!(input.into_children(); - [scheme(sch), authority(auth), path(p)] => URL { + [scheme(sch), authority(auth), url_path(p)] => URL { scheme: sch, authority: auth, path: p, query: None, headers: None, }, - [scheme(sch), authority(auth), path(p), query(q)] => URL { + [scheme(sch), authority(auth), url_path(p), query(q)] => URL { scheme: sch, authority: auth, path: p, @@ -568,10 +568,28 @@ impl DhallParser { )) } + fn url_path(input: ParseInput) -> ParseResult<FilePath> { + Ok(match_nodes!(input.into_children(); + [path_component(components)..] => { + let mut file_path: Vec<_> = components.collect(); + // An empty path normalizes to "/" + if file_path.is_empty() { + file_path = vec!["".to_owned()]; + } + FilePath { file_path } + } + )) + } + fn authority(input: ParseInput) -> ParseResult<String> { Ok(input.as_str().to_owned()) } + #[alias(path_component)] + fn segment(input: ParseInput) -> ParseResult<String> { + Ok(input.as_str().to_string()) + } + fn query(input: ParseInput) -> ParseResult<String> { Ok(input.as_str().to_owned()) } |