Skip to main content

pm_parser_constant_insert

Function pm_parser_constant_insert 

Source
pub unsafe extern "C" fn pm_parser_constant_insert(
    parser: *mut pm_parser_t,
    start: *const u8,
    length: usize,
) -> pm_constant_id_t
Expand description

Add a constant to the parser’s constant pool, for naming a node that was not parsed from the source. If the constant is already in the pool, its existing id is returned. Otherwise the parser copies the bytes, so they only need to remain valid for the duration of the call.

Adding a constant makes the pool larger, so a cache with one entry per constant built beforehand from pm_parser_constants_size and pm_parser_constant_at does not cover it. Build such caches after adding any constants.

@param parser the parser whose constant pool we want to add to @param start a pointer to the start of the string to add @param length the length of the string to add @returns the id of the constant