luau-syntax 0.732.0

Luau lexer, parser, AST, CST, and source utilities
Documentation
use super::*;

impl<'ast, 'name> Parser<'_, 'ast, 'name, '_>
where
    'name: 'ast,
{
    pub(in crate::parser) fn cst_node(
        &self,
        cst: impl FnOnce() -> CstNode<'ast>,
    ) -> Option<CstNode<'ast>> {
        self.cst.node(cst)
    }

    pub(in crate::parser) fn alloc_expression_with_cst(
        &mut self,
        expression: ExpressionInit<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> Expression<'ast> {
        let expression = self.alloc_expression(expression);
        self.cst.insert(expression, cst);
        expression
    }

    pub(in crate::parser) fn attach_expression_cst(
        &mut self,
        expression: Expression<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> Expression<'ast> {
        self.cst.insert(expression, cst);
        expression
    }

    pub(in crate::parser) fn parsed_statement_from_node(
        &mut self,
        statement: Statement<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> ParsedStatement<'ast> {
        self.cst.insert(statement, cst);
        ParsedStatement { statement }
    }

    pub(in crate::parser) fn alloc_function_with_cst(
        &mut self,
        function: Function<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> &'ast mut Function<'ast> {
        let function = self.arena.alloc(function);
        self.cst.insert(&*function, cst);
        function
    }

    pub(in crate::parser) fn alloc_type_with_cst(
        &mut self,
        location: Location,
        annotation: TypeKind<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> Type<'ast> {
        let annotation = self.arena.alloc_type(location, annotation);
        self.cst.insert(annotation, cst);
        annotation
    }

    pub(in crate::parser) fn alloc_type_pack_with_cst(
        &mut self,
        location: Location,
        annotation: TypePackKind<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> TypePack<'ast> {
        let annotation = self.arena.alloc_type_pack(location, annotation);
        self.cst.insert(annotation, cst);
        annotation
    }

    pub(in crate::parser) fn alloc_generic_type_with_cst(
        &mut self,
        generic: GenericType<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> &'ast GenericType<'ast> {
        let generic = self.arena.alloc_generic_type(generic);
        self.cst.insert(generic, cst);
        generic
    }

    pub(in crate::parser) fn alloc_generic_type_pack_with_cst(
        &mut self,
        generic: GenericTypePack<'ast>,
        cst: impl Into<Option<CstNode<'ast>>>,
    ) -> &'ast GenericTypePack<'ast> {
        let generic = self.arena.alloc_generic_type_pack(generic);
        self.cst.insert(generic, cst);
        generic
    }
}