Validates an argument separator against the expected syntax. `syn` contains the details about the separator syntax that is accepted. `end_ok` indicates whether an `ArgSep::End` is acceptable. This is true for repeated arguments, where `End` terminates the argument sequence, and false for singular arguments, where `End` should only be accepted by `ArgSepSyntax::End`. `is_last` indicates whether
(
md: &Rc<CallableMetadata>,
syn: &ArgSepSyntax,
end_ok: bool,
is_last: bool,
sep: ArgSep,
sep_pos: LineCol,
)
| 42 | /// |
| 43 | /// `sep` and `sep_pos` are the details about the separator being validated. |
| 44 | fn validate_syn_argsep( |
| 45 | md: &Rc<CallableMetadata>, |
| 46 | syn: &ArgSepSyntax, |
| 47 | end_ok: bool, |
| 48 | is_last: bool, |
| 49 | sep: ArgSep, |
| 50 | sep_pos: LineCol, |
| 51 | ) -> Result<()> { |
| 52 | debug_assert!( |
| 53 | (!is_last || sep == ArgSep::End) && (is_last || sep != ArgSep::End), |
| 54 | "Parser can only supply an End separator in the last argument" |
| 55 | ); |
| 56 | |
| 57 | match syn { |
| 58 | ArgSepSyntax::Exactly(exp_sep) => { |
| 59 | debug_assert!(*exp_sep != ArgSep::End, "Use ArgSepSyntax::End"); |
| 60 | if sep == *exp_sep || (sep == ArgSep::End && end_ok) { |
| 61 | Ok(()) |
| 62 | } else { |
| 63 | Err(Error::CallableSyntax(sep_pos, md.as_ref().clone())) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ArgSepSyntax::OneOf(exp_seps) => { |
| 68 | if sep == ArgSep::End { |
| 69 | if end_ok { |
| 70 | return Ok(()); |
| 71 | } |
| 72 | return Err(Error::CallableSyntax(sep_pos, md.as_ref().clone())); |
| 73 | } |
| 74 | |
| 75 | let mut found = false; |
| 76 | for exp_sep in *exp_seps { |
| 77 | debug_assert!(*exp_sep != ArgSep::End, "Use ArgSepSyntax::End"); |
| 78 | if sep == *exp_sep { |
| 79 | found = true; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | if !found { |
| 84 | return Err(Error::CallableSyntax(sep_pos, md.as_ref().clone())); |
| 85 | } |
| 86 | Ok(()) |
| 87 | } |
| 88 | |
| 89 | ArgSepSyntax::End => { |
| 90 | debug_assert!(is_last); |
| 91 | Ok(()) |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /// Pre-allocates one local variable for a command output argument, setting its to its default |
| 97 | /// value. |
no test coverage detected