MCPcopy Create free account
hub / github.com/dev-formata-io/stof / array_value

Function array_value

src/parser/field.rs:168–194  ·  view source on GitHub ↗

Array value.

(input: &'a str, _name: &str, context: &mut ParseContext)

Source from the content-addressed store, hash-verified

166 Err(nom::Err::Error(StofParseError::from(err.to_string())))
167 }
168 }
169}
170
171
172/// Array value.
173fn array_value<'a>(input: &'a str, _name: &str, context: &mut ParseContext) -> IResult<&'a str, Variable, StofParseError> {
174 let (input, _) = char('[')(input)?;
175 let (mut input, _) = whitespace(input)?;
176 let mut values = vector![];
177 let mut default_attrs = FxHashMap::default();
178 loop {
179 let res = value(input, &nanoid!(17), context, &mut default_attrs);
180 match res {
181 Ok((rest, var)) => {
182 input = rest;
183 values.push_back(var.val);
184 },
185 Err(error) => {
186 return Err(error); // not a valid value
187 },
188 }
189
190 let (rest, del) = alt((
191 preceded(whitespace, recognize((tag(","), preceded(whitespace, tag("]"))))),
192 delimited(whitespace, tag(","), whitespace),
193 preceded(whitespace, tag("]"))
194 )).parse(input)?;
195 input = rest;
196 if del.contains(']') { break; } // end of the array
197 }

Callers 1

valueFunction · 0.85

Calls 4

whitespaceFunction · 0.85
defaultFunction · 0.85
valueFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected