| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef SYNTAX_SYNTAX_H | ||
| 2 | #define SYNTAX_SYNTAX_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include "command/error.h" | ||
| 8 | #include "syntax/bitset.h" | ||
| 9 | #include "syntax/color.h" | ||
| 10 | #include "util/hashmap.h" | ||
| 11 | #include "util/hashset.h" | ||
| 12 | #include "util/macros.h" | ||
| 13 | #include "util/ptr-array.h" | ||
| 14 | #include "util/string-view.h" | ||
| 15 | |||
| 16 | typedef enum { | ||
| 17 | COND_BUFIS, | ||
| 18 | COND_BUFIS_ICASE, | ||
| 19 | COND_CHAR, | ||
| 20 | COND_CHAR_BUFFER, | ||
| 21 | COND_CHAR1, | ||
| 22 | COND_INLIST, | ||
| 23 | COND_INLIST_BUFFER, | ||
| 24 | COND_RECOLOR, | ||
| 25 | COND_RECOLOR_BUFFER, | ||
| 26 | COND_STR, | ||
| 27 | COND_STR2, | ||
| 28 | COND_STR_ICASE, | ||
| 29 | COND_HEREDOCEND, | ||
| 30 | } ConditionType; | ||
| 31 | |||
| 32 | typedef enum { | ||
| 33 | STATE_INVALID = -1, | ||
| 34 | STATE_EAT, | ||
| 35 | STATE_NOEAT, | ||
| 36 | STATE_NOEAT_BUFFER, | ||
| 37 | STATE_HEREDOCBEGIN, | ||
| 38 | } DefaultActionType; | ||
| 39 | |||
| 40 | typedef struct { | ||
| 41 | struct State *destination; | ||
| 42 | |||
| 43 | // If condition has no emit name this is set to destination state's | ||
| 44 | // emit name or list name (COND_INLIST) | ||
| 45 | const char *emit_name; // Interned | ||
| 46 | |||
| 47 | // Set after all styles have been added (config loaded) | ||
| 48 | const TermStyle *emit_style; | ||
| 49 | } Action; | ||
| 50 | |||
| 51 | typedef struct { | ||
| 52 | HashSet strings; | ||
| 53 | bool used; | ||
| 54 | bool defined; | ||
| 55 | } StringList; | ||
| 56 | |||
| 57 | typedef union { | ||
| 58 | BitSetWord bitset[BITSET_NR_WORDS(256)]; | ||
| 59 | StringView heredocend; | ||
| 60 | const StringList *str_list; | ||
| 61 | char ch; | ||
| 62 | size_t recolor_len; | ||
| 63 | struct { | ||
| 64 | uint8_t len; | ||
| 65 | char buf[31]; | ||
| 66 | } str; | ||
| 67 | } ConditionData; | ||
| 68 | |||
| 69 | typedef struct { | ||
| 70 | ConditionType type; | ||
| 71 | ConditionData u; | ||
| 72 | Action a; | ||
| 73 | } Condition; | ||
| 74 | |||
| 75 | typedef struct { | ||
| 76 | char *name; | ||
| 77 | HashMap states; | ||
| 78 | struct State *start_state; | ||
| 79 | HashMap string_lists; | ||
| 80 | HashMap default_styles; // Interned values | ||
| 81 | bool heredoc; | ||
| 82 | bool used; | ||
| 83 | bool warned_unused_subsyntax; | ||
| 84 | } Syntax; | ||
| 85 | |||
| 86 | typedef struct State { | ||
| 87 | char *name; | ||
| 88 | const char *emit_name; // Interned | ||
| 89 | PointerArray conds; | ||
| 90 | |||
| 91 | bool defined; | ||
| 92 | bool visited; | ||
| 93 | bool copied; | ||
| 94 | |||
| 95 | DefaultActionType type; | ||
| 96 | Action default_action; | ||
| 97 | |||
| 98 | struct { | ||
| 99 | Syntax *subsyntax; | ||
| 100 | PointerArray states; | ||
| 101 | } heredoc; | ||
| 102 | } State; | ||
| 103 | |||
| 104 | typedef struct { | ||
| 105 | State *state; // Borrowed (owned by `Syntax::states`) | ||
| 106 | const char *delim; // Interned | ||
| 107 | size_t len; | ||
| 108 | } HeredocState; | ||
| 109 | |||
| 110 | 2776 | static inline bool is_subsyntax(const Syntax *syn) | |
| 111 | { | ||
| 112 | 2776 | return syn->name[0] == '.'; | |
| 113 | } | ||
| 114 | |||
| 115 | 501 | static inline bool cond_type_has_destination(ConditionType type) | |
| 116 | { | ||
| 117 | 501 | return !(type == COND_RECOLOR || type == COND_RECOLOR_BUFFER); | |
| 118 | } | ||
| 119 | |||
| 120 | StringList *find_string_list(const Syntax *syn, const char *name); | ||
| 121 | State *find_state(const Syntax *syn, const char *name); | ||
| 122 | bool finalize_syntax(HashMap *syntaxes, Syntax *syn, ErrorBuffer *ebuf); | ||
| 123 | void free_syntax(Syntax *syn); | ||
| 124 | |||
| 125 | Syntax *find_any_syntax(const HashMap *syntaxes, const char *name); | ||
| 126 | Syntax *find_syntax(const HashMap *syntaxes, const char *name); | ||
| 127 | void update_state_styles(const Syntax *syn, State *s, const StyleMap *styles); | ||
| 128 | void update_syntax_styles(Syntax *syn, const StyleMap *styles); | ||
| 129 | void update_all_syntax_styles(const HashMap *syntaxes, const StyleMap *styles); | ||
| 130 | void find_unused_subsyntaxes(const HashMap *syntaxes, ErrorBuffer *ebuf); | ||
| 131 | void free_syntaxes(HashMap *syntaxes); | ||
| 132 | void collect_syntax_emit_names(const Syntax *syntax, PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
| 133 | |||
| 134 | #endif | ||
| 135 |