neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

regexp_defs.h (2798B)


      1 // NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
      2 //
      3 // This is NOT the original regular expression code as written by Henry
      4 // Spencer.  This code has been modified specifically for use with Vim, and
      5 // should not be used apart from compiling Vim.  If you want a good regular
      6 // expression library, get the original code.
      7 //
      8 // NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
      9 
     10 #pragma once
     11 
     12 #include <stdbool.h>
     13 #include <stdint.h>
     14 
     15 #include "nvim/pos_defs.h"
     16 #include "nvim/types_defs.h"
     17 
     18 enum {
     19  /// The number of sub-matches is limited to 10.
     20  /// The first one (index 0) is the whole match, referenced with "\0".
     21  /// The second one (index 1) is the first sub-match, referenced with "\1".
     22  /// This goes up to the tenth (index 9), referenced with "\9".
     23  NSUBEXP = 10,
     24 };
     25 
     26 typedef struct regengine regengine_T;
     27 
     28 /// Structure to be used for multi-line matching.
     29 /// Sub-match "no" starts in line "startpos[no].lnum" column "startpos[no].col"
     30 /// and ends in line "endpos[no].lnum" just before column "endpos[no].col".
     31 /// The line numbers are relative to the first line, thus startpos[0].lnum is
     32 /// always 0.
     33 /// When there is no match, the line number is -1.
     34 typedef struct {
     35  regprog_T *regprog;
     36  lpos_T startpos[NSUBEXP];
     37  lpos_T endpos[NSUBEXP];
     38 
     39  colnr_T rmm_matchcol;  ///< match start without "\zs"
     40  int rmm_ic;
     41  colnr_T rmm_maxcol;  ///< when not zero: maximum column
     42 } regmmatch_T;
     43 
     44 /// Used for "magic_overruled".
     45 typedef enum {
     46  OPTION_MAGIC_NOT_SET,  ///< p_magic not overruled
     47  OPTION_MAGIC_ON,       ///< magic on inside regexp
     48  OPTION_MAGIC_OFF,      ///< magic off inside regexp
     49 } optmagic_T;
     50 
     51 /// Magicness of a pattern, used by regexp code.
     52 /// The order and values matter:
     53 ///  magic <= MAGIC_OFF includes MAGIC_NONE
     54 ///  magic >= MAGIC_ON  includes MAGIC_ALL
     55 typedef enum {
     56  MAGIC_NONE = 1,  ///< "\V" very unmagic
     57  MAGIC_OFF = 2,   ///< "\M" or 'magic' off
     58  MAGIC_ON = 3,    ///< "\m" or 'magic'
     59  MAGIC_ALL = 4,   ///< "\v" very magic
     60 } magic_T;
     61 
     62 /// Structure to be used for single-line matching.
     63 /// Sub-match "no" starts at "startp[no]" and ends just before "endp[no]".
     64 /// When there is no match, the pointer is NULL.
     65 typedef struct {
     66  regprog_T *regprog;
     67  char *startp[NSUBEXP];
     68  char *endp[NSUBEXP];
     69 
     70  colnr_T rm_matchcol;  ///< match start without "\zs"
     71  bool rm_ic;
     72 } regmatch_T;
     73 
     74 /// Structure used to store external references: "\z\(\)" to "\z\1".
     75 /// Use a reference count to avoid the need to copy this around.  When it goes
     76 /// from 1 to zero the matches need to be freed.
     77 typedef struct {
     78  int16_t refcnt;
     79  uint8_t *matches[NSUBEXP];
     80 } reg_extmatch_T;
     81 
     82 /// Flags used by vim_regsub() and vim_regsub_both()
     83 enum {
     84  REGSUB_COPY      = 1,
     85  REGSUB_MAGIC     = 2,
     86  REGSUB_BACKSLASH = 4,
     87 };