skullbrain-parser 0.1.0

Parses skullbrain tokens into a concrete syntax tree (CST).
Documentation
use super::*;

impl<'input, D: Diagnostics, C: ConcreteSyntaxTreeBuilder> ParserState<'input, D, C> {
    pub(super) fn parse_possible_call_expr_or_ident_only(&mut self) {
        let checkpoint_before_ident = self.checkpoint();

        self.parse_ident();
        self.skip_trivia();

        // Treat this as a call
        if self.is_possible_call() {
            self.parse_parathesis_comma_separated_expression();
            self.start_node_at(checkpoint_before_ident, SyntaxKind::CallExpr);
            self.finish_node();
        }
    }

    fn is_possible_call(&mut self) -> bool {
        self.peek().is_some_and(|i| {
            i.kind()
                .is(&TokenKind::Punctuation(PunctuationKind::OpenParen))
        })
    }
}

#[cfg(test)]
mod test {
    use crate::syntax::ConcreteSyntaxTreeBuilder;

    #[test]
    fn test_call_expr() {
        crate::test::create_parsing_test("calls/*.skull", |state| {
            state.start_node(crate::SyntaxKind::Unknown);
            state.parse_possible_call_expr_or_ident_only();
            state.finish_node();
        });
    }
}