org_rust_parser/object/
target.rs

1use crate::constants::{LANGLE, NEWLINE, RANGLE};
2use crate::node_pool::NodeID;
3use crate::types::{Cursor, MatchError, ParseOpts, Parseable, Parser, Result};
4
5#[derive(Debug, Copy, Clone)]
6pub struct Target<'a>(pub &'a str);
7
8impl<'a> Parseable<'a> for Target<'a> {
9    fn parse(
10        parser: &mut Parser<'a>,
11        mut cursor: Cursor<'a>,
12        parent: Option<NodeID>,
13        parse_opts: ParseOpts,
14    ) -> Result<NodeID> {
15        let start = cursor.index;
16        cursor.word("<<")?;
17        if cursor.peek(1)?.is_ascii_whitespace() {
18            return Err(MatchError::InvalidLogic);
19        }
20
21        let inner_target_match =
22            cursor.fn_until(|chr: u8| chr == NEWLINE || chr == RANGLE || chr == LANGLE)?;
23        cursor.index = inner_target_match.end;
24        cursor.word(">>")?;
25
26        let ret_id = parser.alloc(Self(inner_target_match.obj), start, cursor.index, parent);
27
28        parser.pool[ret_id].id_target = Some(parser.generate_target(inner_target_match.obj));
29        Ok(ret_id)
30    }
31}