MCPcopy Create free account
hub / github.com/dfinity/ic-repl / partial_parse

Function partial_parse

src/helper.rs:266–314  ·  view source on GitHub ↗
(line: &str, pos: usize, helper: &MyHelper)

Source from the content-addressed store, hash-verified

264}
265
266fn partial_parse(line: &str, pos: usize, helper: &MyHelper) -> Option<(usize, Partial)> {
267 let (start, _) = extract_word(line, pos, None, |c| c == ' ');
268 let iter = Tokenizer::new(&line[start..pos]);
269 let mut tokens = Vec::new();
270 let mut pos_start = 0;
271 for v in iter {
272 let v = v.ok()?;
273 if pos_start == 0
274 && matches!(
275 v.1,
276 Token::Equals | Token::TestEqual | Token::SubEqual | Token::NotEqual
277 )
278 {
279 pos_start = v.2;
280 }
281 let tok = if let Token::Text(id) = v.1 {
282 Token::Id(id)
283 } else {
284 v.1
285 };
286 tokens.push((v.0, tok));
287 }
288 match tokens.as_slice() {
289 [(_, Token::Id(id))] => match str_to_principal(id, helper) {
290 Ok(id) => Some((pos, Partial::Call(id, "".to_string()))),
291 Err(_) => parse_value(&line[..pos], start, pos, helper),
292 },
293 [(_, Token::Id(id)), (pos_tail, Token::Dot)]
294 | [(_, Token::Id(id)), (pos_tail, Token::Dot), (_, _)] => {
295 match str_to_principal(id, helper) {
296 Ok(id) => Some((
297 start + pos_tail,
298 Partial::Call(id, line[start + pos_tail + 1..pos].to_string()),
299 )),
300 Err(_) => parse_value(&line[..pos], start + pos_start, start + pos_tail, helper),
301 }
302 }
303 [.., (_, Token::RSquare)] | [.., (_, Token::Question)] => {
304 parse_value(&line[..pos], start + pos_start, pos, helper)
305 }
306 [.., (pos_tail, Token::Dot)]
307 | [.., (pos_tail, Token::Dot), (_, _)]
308 | [.., (pos_tail, Token::LSquare)]
309 | [.., (pos_tail, Token::LSquare), (_, Token::Decimal(_))] => {
310 parse_value(&line[..pos], start + pos_start, start + pos_tail, helper)
311 }
312 _ => None,
313 }
314}
315fn parse_value(
316 line: &str,
317 start: usize,

Callers 2

completeMethod · 0.85
find_lastest_callFunction · 0.85

Calls 2

str_to_principalFunction · 0.85
parse_valueFunction · 0.85

Tested by

no test coverage detected