Data Structures | Macros | Typedefs | Functions
regexp.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h"
#include "nvim/garray.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/input.h"
#include "nvim/plines.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
#include "nvim/regexp_bt.c"
#include "nvim/regexp_nfa.c"

Data Structures

struct  parse_state_T
 
struct  regexec_T
 
struct  decomp_T
 
struct  regsubmatch_T
 

Macros

#define Magic(x)   ((int)(x) - 256)
 
#define un_Magic(x)   ((x) + 256)
 
#define is_Magic(x)   ((x) < 0)
 
#define REGMAGIC   0234
 
#define UCHARAT(p)   ((int)(*(char_u *)(p)))
 
#define EMSG_RET_NULL(m)   return (emsg(m), rc_did_emsg = true, (void *)NULL)
 
#define IEMSG_RET_NULL(m)   return (iemsg(m), rc_did_emsg = true, (void *)NULL)
 
#define EMSG_RET_FAIL(m)   return (emsg(m), rc_did_emsg = true, FAIL)
 
#define EMSG2_RET_NULL(m, c)   return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, (void *)NULL)
 
#define EMSG3_RET_NULL(m, c, a)   return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = true, (void *)NULL)
 
#define EMSG2_RET_FAIL(m, c)   return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)
 
#define EMSG_ONE_RET_NULL   EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)
 
#define MAX_LIMIT   (32767L << 16L)
 
#define NOT_MULTI   0
 
#define MULTI_ONE   1
 
#define MULTI_MULT   2
 
#define RA_FAIL   1
 
#define RA_CONT   2
 
#define RA_BREAK   3
 
#define RA_MATCH   4
 
#define RA_NOMATCH   5
 
#define CLASS_ALNUM   0
 
#define CLASS_ALPHA   1
 
#define CLASS_BLANK   2
 
#define CLASS_CNTRL   3
 
#define CLASS_DIGIT   4
 
#define CLASS_GRAPH   5
 
#define CLASS_LOWER   6
 
#define CLASS_PRINT   7
 
#define CLASS_PUNCT   8
 
#define CLASS_SPACE   9
 
#define CLASS_UPPER   10
 
#define CLASS_XDIGIT   11
 
#define CLASS_TAB   12
 
#define CLASS_RETURN   13
 
#define CLASS_BACKSPACE   14
 
#define CLASS_ESCAPE   15
 
#define CLASS_IDENT   16
 
#define CLASS_KEYWORD   17
 
#define CLASS_FNAME   18
 
#define CLASS_NONE   99
 
#define RI_DIGIT   0x01
 
#define RI_HEX   0x02
 
#define RI_OCTAL   0x04
 
#define RI_WORD   0x08
 
#define RI_HEAD   0x10
 
#define RI_ALPHA   0x20
 
#define RI_LOWER   0x40
 
#define RI_UPPER   0x80
 
#define RI_WHITE   0x100
 
#define ri_digit(c)   ((c) < 0x100 && (class_tab[c] & RI_DIGIT))
 
#define ri_hex(c)   ((c) < 0x100 && (class_tab[c] & RI_HEX))
 
#define ri_octal(c)   ((c) < 0x100 && (class_tab[c] & RI_OCTAL))
 
#define ri_word(c)   ((c) < 0x100 && (class_tab[c] & RI_WORD))
 
#define ri_head(c)   ((c) < 0x100 && (class_tab[c] & RI_HEAD))
 
#define ri_alpha(c)   ((c) < 0x100 && (class_tab[c] & RI_ALPHA))
 
#define ri_lower(c)   ((c) < 0x100 && (class_tab[c] & RI_LOWER))
 
#define ri_upper(c)   ((c) < 0x100 && (class_tab[c] & RI_UPPER))
 
#define ri_white(c)   ((c) < 0x100 && (class_tab[c] & RI_WHITE))
 
#define RF_ICASE   1
 
#define RF_NOICASE   2
 
#define RF_HASNL   4
 
#define RF_ICOMBINE   8
 
#define RF_LOOKBH   16
 
#define MAGIC_NONE   1
 
#define MAGIC_OFF   2
 
#define MAGIC_ON   3
 
#define MAGIC_ALL   4
 
#define REG_NOPAREN   0
 
#define REG_PAREN   1
 
#define REG_ZPAREN   2
 
#define REG_NPAREN   3
 
#define REG_MULTI   (rex.reg_match == NULL)
 

Typedefs

typedef void(*(* fptr_T) (int *, int)
 

Functions

int re_multiline (const regprog_T *prog) FUNC_ATTR_NONNULL_ALL
 
char_uskip_regexp (char_u *startp, int dirc, int magic, char_u **newp)
 
reg_extmatch_Tref_extmatch (reg_extmatch_T *em)
 
void unref_extmatch (reg_extmatch_T *em)
 
char_uregtilde (char_u *source, int magic, bool preview)
 
int vim_regsub (regmatch_T *rmp, char_u *source, typval_T *expr, char_u *dest, int copy, int magic, int backslash)
 
int vim_regsub_multi (regmmatch_T *rmp, linenr_T lnum, char_u *source, char_u *dest, int copy, int magic, int backslash)
 
char_ureg_submatch (int no)
 
list_Treg_submatch_list (int no)
 
regprog_Tvim_regcomp (char_u *expr_arg, int re_flags)
 
void vim_regfree (regprog_T *prog)
 
bool vim_regexec_prog (regprog_T **prog, bool ignore_case, char_u *line, colnr_T col)
 
bool vim_regexec (regmatch_T *rmp, char_u *line, colnr_T col)
 
bool vim_regexec_nl (regmatch_T *rmp, char_u *line, colnr_T col)
 
long vim_regexec_multi (regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm, int *timed_out) FUNC_ATTR_NONNULL_ARG(1)
 

Macro Definition Documentation

◆ CLASS_ALNUM

#define CLASS_ALNUM   0

◆ CLASS_ALPHA

#define CLASS_ALPHA   1

◆ CLASS_BACKSPACE

#define CLASS_BACKSPACE   14

◆ CLASS_BLANK

#define CLASS_BLANK   2

◆ CLASS_CNTRL

#define CLASS_CNTRL   3

◆ CLASS_DIGIT

#define CLASS_DIGIT   4

◆ CLASS_ESCAPE

#define CLASS_ESCAPE   15

◆ CLASS_FNAME

#define CLASS_FNAME   18

◆ CLASS_GRAPH

#define CLASS_GRAPH   5

◆ CLASS_IDENT

#define CLASS_IDENT   16

◆ CLASS_KEYWORD

#define CLASS_KEYWORD   17

◆ CLASS_LOWER

#define CLASS_LOWER   6

◆ CLASS_NONE

#define CLASS_NONE   99

◆ CLASS_PRINT

#define CLASS_PRINT   7

◆ CLASS_PUNCT

#define CLASS_PUNCT   8

◆ CLASS_RETURN

#define CLASS_RETURN   13

◆ CLASS_SPACE

#define CLASS_SPACE   9

◆ CLASS_TAB

#define CLASS_TAB   12

◆ CLASS_UPPER

#define CLASS_UPPER   10

◆ CLASS_XDIGIT

#define CLASS_XDIGIT   11

◆ EMSG2_RET_FAIL

#define EMSG2_RET_FAIL (   m,
 
)    return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, FAIL)

◆ EMSG2_RET_NULL

#define EMSG2_RET_NULL (   m,
 
)    return (semsg((m), (c) ? "" : "\\"), rc_did_emsg = true, (void *)NULL)

◆ EMSG3_RET_NULL

#define EMSG3_RET_NULL (   m,
  c,
 
)    return (semsg((const char *)(m), (c) ? "" : "\\", (a)), rc_did_emsg = true, (void *)NULL)

◆ EMSG_ONE_RET_NULL

#define EMSG_ONE_RET_NULL   EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL)

◆ EMSG_RET_FAIL

#define EMSG_RET_FAIL (   m)    return (emsg(m), rc_did_emsg = true, FAIL)

◆ EMSG_RET_NULL

#define EMSG_RET_NULL (   m)    return (emsg(m), rc_did_emsg = true, (void *)NULL)

◆ IEMSG_RET_NULL

#define IEMSG_RET_NULL (   m)    return (iemsg(m), rc_did_emsg = true, (void *)NULL)

◆ is_Magic

#define is_Magic (   x)    ((x) < 0)

◆ Magic

#define Magic (   x)    ((int)(x) - 256)

◆ MAGIC_ALL

#define MAGIC_ALL   4

◆ MAGIC_NONE

#define MAGIC_NONE   1

◆ MAGIC_OFF

#define MAGIC_OFF   2

◆ MAGIC_ON

#define MAGIC_ON   3

◆ MAX_LIMIT

#define MAX_LIMIT   (32767L << 16L)

◆ MULTI_MULT

#define MULTI_MULT   2

◆ MULTI_ONE

#define MULTI_ONE   1

◆ NOT_MULTI

#define NOT_MULTI   0

◆ RA_BREAK

#define RA_BREAK   3

◆ RA_CONT

#define RA_CONT   2

◆ RA_FAIL

#define RA_FAIL   1

◆ RA_MATCH

#define RA_MATCH   4

◆ RA_NOMATCH

#define RA_NOMATCH   5

◆ REG_MULTI

#define REG_MULTI   (rex.reg_match == NULL)

◆ REG_NOPAREN

#define REG_NOPAREN   0

◆ REG_NPAREN

#define REG_NPAREN   3

◆ REG_PAREN

#define REG_PAREN   1

◆ REG_ZPAREN

#define REG_ZPAREN   2

◆ REGMAGIC

#define REGMAGIC   0234

◆ RF_HASNL

#define RF_HASNL   4

◆ RF_ICASE

#define RF_ICASE   1

◆ RF_ICOMBINE

#define RF_ICOMBINE   8

◆ RF_LOOKBH

#define RF_LOOKBH   16

◆ RF_NOICASE

#define RF_NOICASE   2

◆ ri_alpha

#define ri_alpha (   c)    ((c) < 0x100 && (class_tab[c] & RI_ALPHA))

◆ RI_ALPHA

#define RI_ALPHA   0x20

◆ ri_digit

#define ri_digit (   c)    ((c) < 0x100 && (class_tab[c] & RI_DIGIT))

◆ RI_DIGIT

#define RI_DIGIT   0x01

◆ ri_head

#define ri_head (   c)    ((c) < 0x100 && (class_tab[c] & RI_HEAD))

◆ RI_HEAD

#define RI_HEAD   0x10

◆ ri_hex

#define ri_hex (   c)    ((c) < 0x100 && (class_tab[c] & RI_HEX))

◆ RI_HEX

#define RI_HEX   0x02

◆ ri_lower

#define ri_lower (   c)    ((c) < 0x100 && (class_tab[c] & RI_LOWER))

◆ RI_LOWER

#define RI_LOWER   0x40

◆ ri_octal

#define ri_octal (   c)    ((c) < 0x100 && (class_tab[c] & RI_OCTAL))

◆ RI_OCTAL

#define RI_OCTAL   0x04

◆ ri_upper

#define ri_upper (   c)    ((c) < 0x100 && (class_tab[c] & RI_UPPER))

◆ RI_UPPER

#define RI_UPPER   0x80

◆ ri_white

#define ri_white (   c)    ((c) < 0x100 && (class_tab[c] & RI_WHITE))

◆ RI_WHITE

#define RI_WHITE   0x100

◆ ri_word

#define ri_word (   c)    ((c) < 0x100 && (class_tab[c] & RI_WORD))

◆ RI_WORD

#define RI_WORD   0x08

◆ UCHARAT

#define UCHARAT (   p)    ((int)(*(char_u *)(p)))

◆ un_Magic

#define un_Magic (   x)    ((x) + 256)

Typedef Documentation

◆ fptr_T

typedef void(*(* fptr_T) (int *, int)

Function Documentation

◆ re_multiline()

int re_multiline ( const regprog_T prog)

◆ ref_extmatch()

reg_extmatch_T* ref_extmatch ( reg_extmatch_T em)

◆ reg_submatch()

char_u* reg_submatch ( int  no)

◆ reg_submatch_list()

list_T* reg_submatch_list ( int  no)

◆ regtilde()

char_u* regtilde ( char_u source,
int  magic,
bool  preview 
)

◆ skip_regexp()

char_u* skip_regexp ( char_u startp,
int  dirc,
int  magic,
char_u **  newp 
)

◆ unref_extmatch()

void unref_extmatch ( reg_extmatch_T em)

◆ vim_regcomp()

regprog_T* vim_regcomp ( char_u expr_arg,
int  re_flags 
)

◆ vim_regexec()

bool vim_regexec ( regmatch_T rmp,
char_u line,
colnr_T  col 
)

◆ vim_regexec_multi()

long vim_regexec_multi ( regmmatch_T rmp,
win_T win,
buf_T buf,
linenr_T  lnum,
colnr_T  col,
proftime_T tm,
int *  timed_out 
)

Match a regexp against multiple lines. "rmp->regprog" must be a compiled regexp as returned by vim_regcomp(). Note: "rmp->regprog" may be freed and changed, even set to NULL. Uses curbuf for line count and 'iskeyword'.

Parameters
winwindow in which to search or NULL
bufbuffer in which to search
lnumnr of line to start looking for match
colcolumn to start looking for match
tmtimeout limit or NULL
timed_outflag is set when timeout limit reached
Returns
zero if there is no match. Return number of lines contained in the match otherwise.

◆ vim_regexec_nl()

bool vim_regexec_nl ( regmatch_T rmp,
char_u line,
colnr_T  col 
)

◆ vim_regexec_prog()

bool vim_regexec_prog ( regprog_T **  prog,
bool  ignore_case,
char_u line,
colnr_T  col 
)

◆ vim_regfree()

void vim_regfree ( regprog_T prog)

◆ vim_regsub()

int vim_regsub ( regmatch_T rmp,
char_u source,
typval_T expr,
char_u dest,
int  copy,
int  magic,
int  backslash 
)

vim_regsub() - perform substitutions after a vim_regexec() or vim_regexec_multi() match.

If "copy" is true really copy into "dest". If "copy" is false nothing is copied, this is just to find out the length of the result.

If "backslash" is true, a backslash will be removed later, need to double them to keep them, and insert a backslash before a CR to avoid it being replaced with a line break later.

Note: The matched text must not change between the call of vim_regexec()/vim_regexec_multi() and vim_regsub()! It would make the back references invalid!

Returns the size of the replacement, including terminating NUL.

◆ vim_regsub_multi()

int vim_regsub_multi ( regmmatch_T rmp,
linenr_T  lnum,
char_u source,
char_u dest,
int  copy,
int  magic,
int  backslash 
)