utterance 0.1.4

A parser library for creating readable, natural-language-inspired domain-specific languages.
Documentation
use std::collections::HashSet;

use crate::parser::CustomParseError;
use crate::parser::expectation::StatementKind;
use crate::parser::tree::{ParseContext, TreeFn};

pub type GraphNodeId = usize;

#[derive(Debug)]
pub struct GraphNode<C, E>
where
    C: ParseContext,
    E: Into<CustomParseError> + Clone,
{
    statement_expectation: StatementKind,
    function: TreeFn<C, E>,
    children: HashSet<GraphNodeId>,
}

impl<C, E> GraphNode<C, E>
where
    C: ParseContext,
    E: Into<CustomParseError> + Clone,
{
    pub(crate) fn new(statement_expectation: StatementKind, function: TreeFn<C, E>) -> Self {
        Self {
            statement_expectation,
            function,
            children: HashSet::new(),
        }
    }

    pub(crate) fn push_child(&mut self, child: GraphNodeId) {
        self.children.insert(child);
    }

    pub(crate) fn children(&self) -> impl Iterator<Item = &GraphNodeId> {
        self.children.iter()
    }

    pub(crate) fn statement_expectation(&self) -> &StatementKind {
        &self.statement_expectation
    }

    pub(crate) fn function(&self) -> TreeFn<C, E> {
        self.function
    }
}