rustre_parser/parser/
ext_nodes.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::*;

/// Parses `extern node`, `extern function`, `unsafe extern node` and `unsafe extern function`
///
/// This function accepts anything that matches at least one token ; the keyword "`unsafe`" will be
/// matched even if it isn't followed by `node` or `function`
fn parse_ext_node_type<'slice, 'src>(input: Input<'slice, 'src>) -> IResult<'slice, 'src> {
    join((
        opt(t(Unsafe)),
        t(Extern),
        expect(
            alt((t(Node), t(Function))),
            "expected `node` or `function` after `extern`",
        ),
    ))(input)
}

pub fn parse_ext_node_decl<'slice, 'src>(input: Input<'slice, 'src>) -> IResult<'slice, 'src> {
    node(
        ExternalNodeDeclNode,
        join((
            parse_ext_node_type,
            expect(ident::parse_id_any, "missing external node name"),
            expect(
                nodes::parse_params_and_returns,
                "missing signature (params and returned values)",
            ),
            opt(t(Semicolon)),
        )),
    )(input)
}