robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

bfredlMerge pull request #41212 from bfredl/unmagic8a0eb8f10b

master
2.5 KiB80 linesraw
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
18enum {
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
26typedef 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.
34typedef 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/// Magicness of a pattern, used by regexp code.
45/// The order and values matter:
46///  magic <= MAGIC_OFF includes MAGIC_NONE
47///  magic >= MAGIC_ON  includes MAGIC_ALL
48typedef enum {
49  MAGIC_NONE = 1,  ///< "\V" very unmagic
50  MAGIC_OFF = 2,   ///< "\M" or 'magic' off
51  MAGIC_ON = 3,    ///< "\m" or 'magic'
52  MAGIC_ALL = 4,   ///< "\v" very magic
53} magic_T;
54
55/// Structure to be used for single-line matching.
56/// Sub-match "no" starts at "startp[no]" and ends just before "endp[no]".
57/// When there is no match, the pointer is NULL.
58typedef struct {
59  regprog_T *regprog;
60  char *startp[NSUBEXP];
61  char *endp[NSUBEXP];
62
63  colnr_T rm_matchcol;  ///< match start without "\zs"
64  bool rm_ic;
65} regmatch_T;
66
67/// Structure used to store external references: "\z\(\)" to "\z\1".
68/// Use a reference count to avoid the need to copy this around.  When it goes
69/// from 1 to zero the matches need to be freed.
70typedef struct {
71  int16_t refcnt;
72  uint8_t *matches[NSUBEXP];
73} reg_extmatch_T;
74
75/// Flags used by vim_regsub() and vim_regsub_both()
76enum {
77  REGSUB_COPY      = 1,
78  REGSUB_MAGIC     = 2,
79  REGSUB_BACKSLASH = 4,
80};