refactor(parser): extract parser stage_location.
@@ -1467,16 +1467,12 @@ pub fn kill_target(i: Input) -> IResult<KillTarget> {
pub fn copy_unit(i: Input) -> IResult<CopyUnit> {
// Parse input like `@my_stage/path/to/dir`
let stage_location = |i| {
- map(at_string, |location| {
- let parsed = location.splitn(2, '/').collect::<Vec<_>>();
- let name = parsed[0].to_string();
- let path = if parsed.len() == 1 {
- "/".to_string()
- } else {
- format!("/{}", parsed[1])
- };
- CopyUnit::StageLocation(StageLocation { name, path })
- })(i)
+ map_res(
+ rule! {
+ #stage_location
+ },
+ |v| Ok(CopyUnit::StageLocation(v)),
+ )(i)
};
// Parse input like `mytable`
@@ -1516,6 +1512,19 @@ pub fn copy_unit(i: Input) -> IResult<CopyUnit> {
)(i)
}
+pub fn stage_location(i: Input) -> IResult<StageLocation> {
+ map_res(at_string, |location| {
+ let parsed = location.splitn(2, '/').collect::<Vec<_>>();
+ let name = parsed[0].to_string();
+ let path = if parsed.len() == 1 {
+ "/".to_string()
+ } else {
+ format!("/{}", parsed[1])
+ };
+ Ok(StageLocation { name, path })
+ })(i)
+}
+
/// Parse input into `UriLocation`
pub fn uri_location(i: Input) -> IResult<UriLocation> {
map_res(
