parser_defs.h (2020B)
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 11 typedef struct { 12 const char *data; ///< Parsed line pointer 13 size_t size; ///< Parsed line size 14 bool 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. 20 typedef void (*ParserLineGetter)(void *cookie, ParserLine *ret_pline); 21 22 /// Parser position in the input 23 typedef struct { 24 size_t line; ///< Line index in ParserInputReader.lines. 25 size_t col; ///< Byte index in the line. 26 } ParserPosition; 27 28 /// Parser state item. 29 typedef struct { 30 enum { 31 kPTopStateParsingCommand = 0, 32 kPTopStateParsingExpression, 33 } type; 34 union { 35 struct { 36 enum { 37 kExprUnknown = 0, 38 } type; 39 } expr; 40 } data; 41 } ParserStateItem; 42 43 /// Structure defining input reader 44 typedef struct { 45 /// Function used to get next line. 46 ParserLineGetter get_line; 47 /// Data for get_line function. 48 void *cookie; 49 /// All lines obtained by get_line. 50 kvec_withinit_t(ParserLine, 4) lines; 51 /// Conversion, for :scriptencoding. 52 vimconv_T conv; 53 } ParserInputReader; 54 55 /// Highlighted region definition 56 /// 57 /// Note: one chunk may highlight only one line. 58 typedef struct { 59 ParserPosition start; ///< Start of the highlight: line and column. 60 size_t end_col; ///< End column, points to the start of the next character. 61 const char *group; ///< Highlight group. 62 } ParserHighlightChunk; 63 64 /// Highlighting defined by a parser 65 typedef kvec_withinit_t(ParserHighlightChunk, 16) ParserHighlight; 66 67 /// Structure defining parser state 68 typedef struct { 69 /// Line reader. 70 ParserInputReader reader; 71 /// Position up to which input was parsed. 72 ParserPosition pos; 73 /// Parser state stack. 74 kvec_withinit_t(ParserStateItem, 16) stack; 75 /// Highlighting support. 76 ParserHighlight *colors; 77 /// True if line continuation can be used. 78 bool can_continuate; 79 } ParserState;