diff options
Diffstat (limited to 'src/nvim/syntax.c')
-rw-r--r-- | src/nvim/syntax.c | 300 |
1 files changed, 92 insertions, 208 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7d39a61b69..854e120466 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -81,6 +81,16 @@ static garray_T highlight_ga; /* highlight groups for 'highlight' option */ #define MAX_HL_ID 20000 /* maximum value for a highlight ID. */ +/* different types of offsets that are possible */ +#define SPO_MS_OFF 0 /* match start offset */ +#define SPO_ME_OFF 1 /* match end offset */ +#define SPO_HS_OFF 2 /* highl. start offset */ +#define SPO_HE_OFF 3 /* highl. end offset */ +#define SPO_RS_OFF 4 /* region start offset */ +#define SPO_RE_OFF 5 /* region end offset */ +#define SPO_LC_OFF 6 /* leading context offset */ +#define SPO_COUNT 7 + /* Flags to indicate an additional string for highlight name completion. */ static int include_none = 0; /* when 1 include "nvim/None" */ static int include_default = 0; /* when 1 include "nvim/default" */ @@ -97,40 +107,6 @@ static int hl_attr_table[] = {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, 0}; -static int get_attr_entry(garray_T *table, attrentry_T *aep); -static void syn_unadd_group(void); -static void set_hl_attr(int idx); -static void highlight_list_one(int id); -static int highlight_list_arg(int id, int didh, int type, int iarg, - char_u *sarg, - char *name); -static int syn_add_group(char_u *name); -static int syn_list_header(int did_header, int outlen, int id); -static int hl_has_settings(int idx, int check_link); -static void highlight_clear(int idx); - - -/* - * An attribute number is the index in attr_table plus ATTR_OFF. - */ -#define ATTR_OFF (HL_ALL + 1) - - -#define SYN_NAMELEN 50 /* maximum length of a syntax name */ - -/* different types of offsets that are possible */ -#define SPO_MS_OFF 0 /* match start offset */ -#define SPO_ME_OFF 1 /* match end offset */ -#define SPO_HS_OFF 2 /* highl. start offset */ -#define SPO_HE_OFF 3 /* highl. end offset */ -#define SPO_RS_OFF 4 /* region start offset */ -#define SPO_RE_OFF 5 /* region end offset */ -#define SPO_LC_OFF 6 /* leading context offset */ -#define SPO_COUNT 7 - -static char *(spo_name_tab[SPO_COUNT]) = -{"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; - /* * The patterns that are being searched for are stored in a syn_pattern. * A match item consists of one pattern. @@ -162,6 +138,87 @@ typedef struct syn_pattern { int sp_startcol; /* next match in sp_line_id line */ } synpat_T; + +typedef struct syn_cluster_S { + char_u *scl_name; /* syntax cluster name */ + char_u *scl_name_u; /* uppercase of scl_name */ + short *scl_list; /* IDs in this syntax cluster */ +} syn_cluster_T; + +/* + * For the current state we need to remember more than just the idx. + * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. + * (The end positions have the column number of the next char) + */ +typedef struct state_item { + int si_idx; /* index of syntax pattern or + KEYWORD_IDX */ + int si_id; /* highlight group ID for keywords */ + int si_trans_id; /* idem, transparency removed */ + int si_m_lnum; /* lnum of the match */ + int si_m_startcol; /* starting column of the match */ + lpos_T si_m_endpos; /* just after end posn of the match */ + lpos_T si_h_startpos; /* start position of the highlighting */ + lpos_T si_h_endpos; /* end position of the highlighting */ + lpos_T si_eoe_pos; /* end position of end pattern */ + int si_end_idx; /* group ID for end pattern or zero */ + int si_ends; /* if match ends before si_m_endpos */ + int si_attr; /* attributes in this state */ + long si_flags; /* HL_HAS_EOL flag in this state, and + * HL_SKIP* for si_next_list */ + int si_seqnr; /* sequence number */ + int si_cchar; /* substitution character for conceal */ + short *si_cont_list; /* list of contained groups */ + short *si_next_list; /* nextgroup IDs after this item ends */ + reg_extmatch_T *si_extmatch; /* \z(...\) matches from start + * pattern */ +} stateitem_T; + +/* + * Struct to reduce the number of arguments to get_syn_options(), it's used + * very often. + */ +typedef struct { + int flags; /* flags for contained and transparent */ + int keyword; /* TRUE for ":syn keyword" */ + int *sync_idx; /* syntax item for "grouphere" argument, NULL + if not allowed */ + char has_cont_list; /* TRUE if "cont_list" can be used */ + short *cont_list; /* group IDs for "contains" argument */ + short *cont_in_list; /* group IDs for "containedin" argument */ + short *next_list; /* group IDs for "nextgroup" argument */ +} syn_opt_arg_T; + +typedef struct { + proftime_T total; + int count; + int match; + proftime_T slowest; + proftime_T average; + int id; + char_u *pattern; +} time_entry_T; + +struct name_list { + int flag; + char *name; +}; + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "syntax.c.generated.h" +#endif + +/* + * An attribute number is the index in attr_table plus ATTR_OFF. + */ +#define ATTR_OFF (HL_ALL + 1) + + +#define SYN_NAMELEN 50 /* maximum length of a syntax name */ + +static char *(spo_name_tab[SPO_COUNT]) = +{"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; + /* The sp_off_flags are computed like this: * offset from the start of the matched text: (1 << SPO_XX_OFF) * offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) @@ -198,12 +255,6 @@ static int current_flags = 0; static int current_seqnr = 0; static int current_sub_char = 0; -typedef struct syn_cluster_S { - char_u *scl_name; /* syntax cluster name */ - char_u *scl_name_u; /* uppercase of scl_name */ - short *scl_list; /* IDs in this syntax cluster */ -} syn_cluster_T; - /* * Methods of combining two clusters */ @@ -265,35 +316,6 @@ static int keepend_level = -1; static char msg_no_items[] = N_("No Syntax items defined for this buffer"); -/* - * For the current state we need to remember more than just the idx. - * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. - * (The end positions have the column number of the next char) - */ -typedef struct state_item { - int si_idx; /* index of syntax pattern or - KEYWORD_IDX */ - int si_id; /* highlight group ID for keywords */ - int si_trans_id; /* idem, transparency removed */ - int si_m_lnum; /* lnum of the match */ - int si_m_startcol; /* starting column of the match */ - lpos_T si_m_endpos; /* just after end posn of the match */ - lpos_T si_h_startpos; /* start position of the highlighting */ - lpos_T si_h_endpos; /* end position of the highlighting */ - lpos_T si_eoe_pos; /* end position of end pattern */ - int si_end_idx; /* group ID for end pattern or zero */ - int si_ends; /* if match ends before si_m_endpos */ - int si_attr; /* attributes in this state */ - long si_flags; /* HL_HAS_EOL flag in this state, and - * HL_SKIP* for si_next_list */ - int si_seqnr; /* sequence number */ - int si_cchar; /* substitution character for conceal */ - short *si_cont_list; /* list of contained groups */ - short *si_next_list; /* nextgroup IDs after this item ends */ - reg_extmatch_T *si_extmatch; /* \z(...\) matches from start - * pattern */ -} stateitem_T; - #define KEYWORD_IDX -1 /* value of si_idx for keywords */ #define ID_LIST_ALL (short *)-1 /* valid of si_cont_list for containing all but contained groups */ @@ -301,21 +323,6 @@ typedef struct state_item { static int next_seqnr = 0; /* value to use for si_seqnr */ /* - * Struct to reduce the number of arguments to get_syn_options(), it's used - * very often. - */ -typedef struct { - int flags; /* flags for contained and transparent */ - int keyword; /* TRUE for ":syn keyword" */ - int *sync_idx; /* syntax item for "grouphere" argument, NULL - if not allowed */ - char has_cont_list; /* TRUE if "cont_list" can be used */ - short *cont_list; /* group IDs for "contains" argument */ - short *cont_in_list; /* group IDs for "containedin" argument */ - short *next_list; /* group IDs for "nextgroup" argument */ -} syn_opt_arg_T; - -/* * The next possible match in the current line for any pattern is remembered, * to avoid having to try for a match in each column. * If next_match_idx == -1, not tried (in this line) yet. @@ -360,115 +367,10 @@ static int current_line_id = 0; /* unique number for current line */ #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] -static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); -static int syn_match_linecont(linenr_T lnum); -static void syn_start_line(void); -static void syn_update_ends(int startofline); -static void syn_stack_alloc(void); -static int syn_stack_cleanup(void); -static void syn_stack_free_entry(synblock_T *block, synstate_T *p); -static synstate_T *syn_stack_find_entry(linenr_T lnum); -static synstate_T *store_current_state(void); -static void load_current_state(synstate_T *from); -static void invalidate_current_state(void); -static int syn_stack_equal(synstate_T *sp); -static void validate_current_state(void); -static int syn_finish_line(int syncing); -static int syn_current_attr(int syncing, int displaying, int *can_spell, - int keep_state); -static int did_match_already(int idx, garray_T *gap); -static stateitem_T *push_next_match(stateitem_T *cur_si); -static void check_state_ends(void); -static void update_si_attr(int idx); -static void check_keepend(void); -static void update_si_end(stateitem_T *sip, int startcol, int force); -static short *copy_id_list(short *list); -static int in_id_list(stateitem_T *item, short *cont_list, - struct sp_syn *ssp, - int contained); -static void push_current_state(int idx); -static void pop_current_state(void); -static void syn_clear_time(syn_time_T *tt); -static void syntime_clear(void); -static int syn_compare_syntime(const void *v1, const void *v2); -static void syntime_report(void); static int syn_time_on = FALSE; # define IF_SYN_TIME(p) (p) -static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf); -static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, - lpos_T *hl_endpos, long *flagsp, lpos_T *end_endpos, - int *end_idx, reg_extmatch_T *start_ext); -static void clear_syn_state(synstate_T *p); -static void clear_current_state(void); - -static void limit_pos(lpos_T *pos, lpos_T *limit); -static void limit_pos_zero(lpos_T *pos, lpos_T *limit); -static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, - synpat_T *spp, int idx, - int extra); -static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, - synpat_T *spp, int idx, - int extra); -static char_u *syn_getcurline(void); -static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, - syn_time_T *st); -static int check_keyword_id(char_u *line, int startcol, int *endcol, - long *flags, short **next_list, - stateitem_T *cur_si, - int *ccharp); -static keyentry_T *match_keyword(char_u *keyword, hashtab_T *ht, - stateitem_T *cur_si); -static void syn_cmd_case(exarg_T *eap, int syncing); -static void syn_cmd_spell(exarg_T *eap, int syncing); -static void syntax_sync_clear(void); -static void syn_remove_pattern(synblock_T *block, int idx); -static void syn_clear_pattern(synblock_T *block, int i); -static void syn_clear_cluster(synblock_T *block, int i); -static void syn_cmd_clear(exarg_T *eap, int syncing); -static void syn_cmd_conceal(exarg_T *eap, int syncing); -static void syn_clear_one(int id, int syncing); -static void syn_cmd_on(exarg_T *eap, int syncing); -static void syn_cmd_enable(exarg_T *eap, int syncing); -static void syn_cmd_reset(exarg_T *eap, int syncing); -static void syn_cmd_manual(exarg_T *eap, int syncing); -static void syn_cmd_off(exarg_T *eap, int syncing); -static void syn_cmd_onoff(exarg_T *eap, char *name); -static void syn_cmd_list(exarg_T *eap, int syncing); -static void syn_lines_msg(void); -static void syn_match_msg(void); -static void syn_stack_free_block(synblock_T *block); -static void syn_list_one(int id, int syncing, int link_only); -static void syn_list_cluster(int id); -static void put_id_list(char_u *name, short *list, int attr); -static void put_pattern(char *s, int c, synpat_T *spp, int attr); -static int syn_list_keywords(int id, hashtab_T *ht, int did_header, - int attr); -static void syn_clear_keyword(int id, hashtab_T *ht); -static void clear_keywtab(hashtab_T *ht); -static void add_keyword(char_u *name, int id, int flags, - short *cont_in_list, short *next_list, - int conceal_char); -static char_u *get_group_name(char_u *arg, char_u **name_end); -static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, - int *conceal_char); -static void syn_cmd_include(exarg_T *eap, int syncing); -static void syn_cmd_keyword(exarg_T *eap, int syncing); -static void syn_cmd_match(exarg_T *eap, int syncing); -static void syn_cmd_region(exarg_T *eap, int syncing); -static int syn_compare_stub(const void *v1, const void *v2); -static void syn_cmd_cluster(exarg_T *eap, int syncing); -static int syn_scl_name2id(char_u *name); -static int syn_scl_namen2id(char_u *linep, int len); -static int syn_check_cluster(char_u *pp, int len); -static int syn_add_cluster(char_u *name); -static void init_syn_patterns(void); -static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); -static void syn_cmd_sync(exarg_T *eap, int syncing); -static int get_id_list(char_u **arg, int keylen, short **list); -static void syn_combine_list(short **clstr1, short **clstr2, - int list_op); -static void syn_incl_toplevel(int id, int *flagsp); + /* * Start the syntax recognition for a line. This function is normally called @@ -3518,12 +3420,6 @@ static void syn_match_msg(void) static int last_matchgroup; -struct name_list { - int flag; - char *name; -}; - -static void syn_list_flags(struct name_list *nl, int flags, int attr); /* * List one syntax item, for ":syntax" or "syntax list syntax_name". @@ -5788,16 +5684,6 @@ char_u *get_syntime_arg(expand_T *xp, int idx) return NULL; } -typedef struct { - proftime_T total; - int count; - int match; - proftime_T slowest; - proftime_T average; - int id; - char_u *pattern; -} time_entry_T; - static int syn_compare_syntime(const void *v1, const void *v2) { const time_entry_T *s1 = v1; @@ -7688,8 +7574,6 @@ int highlight_changed(void) return OK; } -static void highlight_list(void); -static void highlight_list_two(int cnt, int attr); /* * Handle command line completion for :highlight command. |