robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
1813661a61
master
1#pragma once 2 3#include <assert.h> 4#include <stdbool.h> 5#include <stddef.h> 6 7#include "klib/kvec.h" 8#include "nvim/mbyte_defs.h" 9 10/// One parsed line 11typedef struct { 12const char * data ;///< Parsed line pointer 13size_t size ;///< Parsed line size 14bool allocated ;///< True if line may be freed. 15}ParserLine ; 16 17/// Line getter type for parser 18/// 19/// Line getter must return {NULL, 0} for EOF. 20typedef void (* ParserLineGetter )(void * cookie ,ParserLine * ret_pline ); 21 22/// Parser position in the input 23typedef struct { 24size_t line ;///< Line index in ParserInputReader.lines. 25size_t col ;///< Byte index in the line. 26}ParserPosition ; 27 28/// Parser state item. 29typedef struct { 30enum { 31kPTopStateParsingCommand = 0 , 32kPTopStateParsingExpression , 33 }type ; 34union { 35struct { 36enum { 37kExprUnknown = 0 , 38 }type ; 39 }expr ; 40 }data ; 41}ParserStateItem ; 42 43/// Structure defining input reader 44typedef struct { 45/// Function used to get next line. 46ParserLineGetter get_line ; 47/// Data for get_line function. 48void * cookie ; 49/// All lines obtained by get_line. 50kvec_withinit_t (ParserLine ,4 )lines ; 51/// Conversion, for :scriptencoding. 52vimconv_T conv ; 53}ParserInputReader ; 54 55/// Highlighted region definition 56/// 57/// Note: one chunk may highlight only one line. 58typedef struct { 59ParserPosition start ;///< Start of the highlight: line and column. 60size_t end_col ;///< End column, points to the start of the next character. 61const char * group ;///< Highlight group. 62}ParserHighlightChunk ; 63 64/// Highlighting defined by a parser 65typedef kvec_withinit_t (ParserHighlightChunk ,16 )ParserHighlight ; 66 67/// Structure defining parser state 68typedef struct { 69/// Line reader. 70ParserInputReader reader ; 71/// Position up to which input was parsed. 72ParserPosition pos ; 73/// Parser state stack. 74kvec_withinit_t (ParserStateItem ,16 )stack ; 75/// Highlighting support. 76ParserHighlight * colors ; 77/// True if line continuation can be used. 78bool can_continuate ; 79}ParserState ;