w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

lpeg.c File Reference
#include "lpeg.h"
Include dependency graph for lpeg.c:

Go to the source code of this file.

Classes

struct  Stack
 
struct  CompileState
 
struct  StrAux
 

Macros

#define INITBACK   MAXBACK
 
#define getoffset(p)   (((p) + 1)->offset)
 
#define getstackbase(L, ptop)   ((Stack *)lua_touserdata(L, stackidx(ptop)))
 
#define NOINST   -1
 
#define getinstr(cs, i)   ((cs)->p->code[i])
 
#define gethere(compst)   ((compst)->ncode)
 
#define target(code, i)   ((i) + code[i + 1].offset)
 
#define captype(cap)   ((cap)->kind)
 
#define isclosecap(cap)   (captype(cap) == Cclose)
 
#define closeaddr(c)   ((c)->s + (c)->siz - 1)
 
#define isfullcap(cap)   ((cap)->siz != 0)
 
#define getfromktable(cs, v)   lua_rawgeti((cs)->L, ktableidx((cs)->ptop), v)
 
#define pushluaval(cs)   getfromktable(cs, (cs)->cap->idx)
 
#define MAXSTRCAPS   10
 
#define MAXLIM   (INT_MAX / 100)
 

Typedefs

typedef struct Stack Stack
 
typedef struct CompileState CompileState
 
typedef struct StrAux StrAux
 

Functions

void printcharset (const byte *st)
 
static const char * capkind (int kind)
 
static void printjmp (const Instruction *op, const Instruction *p)
 
void printinst (const Instruction *op, const Instruction *p)
 
void printpatt (Instruction *p, int n)
 
static void printcap (Capture *cap)
 
void printcaplist (Capture *cap, Capture *limit)
 
void printtree (TTree *tree, int ident)
 
void printktable (lua_State *L, int idx)
 
static Capturedoublecap (lua_State *L, Capture *cap, int captop, int n, int ptop)
 
static Stackdoublestack (lua_State *L, Stack **stacklimit, int ptop)
 
static int resdyncaptures (lua_State *L, int fr, int curr, int limit)
 
static void adddyncaptures (const char *s, Capture *base, int n, int fd)
 
static int removedyncap (lua_State *L, Capture *capture, int level, int last)
 
const char * match (lua_State *L, const char *o, const char *s, const char *e, Instruction *op, Capture *capture, int ptop)
 
static Opcode charsettype (const byte *cs, int *c)
 
static void cs_complement (Charset *cs)
 
static int cs_equal (const byte *cs1, const byte *cs2)
 
static int cs_disjoint (const Charset *cs1, const Charset *cs2)
 
int tocharset (TTree *tree, Charset *cs)
 
static int callrecursive (TTree *tree, int f(TTree *t), int def)
 
int hascaptures (TTree *tree)
 
int checkaux (TTree *tree, int pred)
 
int fixedlen (TTree *tree)
 
static int getfirst (TTree *tree, const Charset *follow, Charset *firstset)
 
static int headfail (TTree *tree)
 
static int needfollow (TTree *tree)
 
int sizei (const Instruction *i)
 
static void codegen (CompileState *compst, TTree *tree, int opt, int tt, const Charset *fl)
 
void realloccode (lua_State *L, Pattern *p, int nsize)
 
static int nextinstruction (CompileState *compst)
 
static int addinstruction (CompileState *compst, Opcode op, int aux)
 
static int addoffsetinst (CompileState *compst, Opcode op)
 
static void setoffset (CompileState *compst, int instruction, int offset)
 
static int addinstcap (CompileState *compst, Opcode op, int cap, int key, int aux)
 
static void jumptothere (CompileState *compst, int instruction, int target)
 
static void jumptohere (CompileState *compst, int instruction)
 
static void codechar (CompileState *compst, int c, int tt)
 
static void addcharset (CompileState *compst, const byte *cs)
 
static void codecharset (CompileState *compst, const byte *cs, int tt)
 
static int codetestset (CompileState *compst, Charset *cs, int e)
 
static int finaltarget (Instruction *code, int i)
 
static int finallabel (Instruction *code, int i)
 
static void codebehind (CompileState *compst, TTree *tree)
 
static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt, const Charset *fl)
 
static void codeand (CompileState *compst, TTree *tree, int tt)
 
static void codecapture (CompileState *compst, TTree *tree, int tt, const Charset *fl)
 
static void coderuntime (CompileState *compst, TTree *tree, int tt)
 
static void coderep (CompileState *compst, TTree *tree, int opt, const Charset *fl)
 
static void codenot (CompileState *compst, TTree *tree)
 
static void correctcalls (CompileState *compst, int *positions, int from, int to)
 
static void codegrammar (CompileState *compst, TTree *grammar)
 
static void codecall (CompileState *compst, TTree *call)
 
static int codeseq1 (CompileState *compst, TTree *p1, TTree *p2, int tt, const Charset *fl)
 
static void peephole (CompileState *compst)
 
Instructioncompile (lua_State *L, Pattern *p)
 
static int updatecache (CapState *cs, int v)
 
static int pushcapture (CapState *cs)
 
static Capturefindopen (Capture *cap)
 
static void nextcap (CapState *cs)
 
static int pushnestedvalues (CapState *cs, int addextra)
 
static void pushonenestedvalue (CapState *cs)
 
static Capturefindback (CapState *cs, Capture *cap)
 
static int backrefcap (CapState *cs)
 
static int tablecap (CapState *cs)
 
static int querycap (CapState *cs)
 
static int foldcap (CapState *cs)
 
static int functioncap (CapState *cs)
 
static int numcap (CapState *cs)
 
int finddyncap (Capture *cap, Capture *last)
 
int runtimecap (CapState *cs, Capture *close, const char *s, int *rem)
 
static int getstrcaps (CapState *cs, StrAux *cps, int n)
 
static int addonestring (luaL_Buffer *b, CapState *cs, const char *what)
 
static void stringcap (luaL_Buffer *b, CapState *cs)
 
static void substcap (luaL_Buffer *b, CapState *cs)
 
int getcaptures (lua_State *L, const char *s, const char *r, int ptop)
 
static TTreenewgrammar (lua_State *L, int arg)
 
static const char * val2str (lua_State *L, int idx)
 
static void fixonecall (lua_State *L, int postable, TTree *g, TTree *t)
 
static void correctassociativity (TTree *tree)
 
static void finalfix (lua_State *L, int postable, TTree *g, TTree *t)
 
static void newktable (lua_State *L, int n)
 
static int addtoktable (lua_State *L, int idx)
 
static int ktablelen (lua_State *L, int idx)
 
static int concattable (lua_State *L, int idx1, int idx2)
 
static void correctkeys (TTree *tree, int n)
 
static void joinktables (lua_State *L, int p1, TTree *t2, int p2)
 
static void copyktable (lua_State *L, int idx)
 
static void mergektable (lua_State *L, int idx, TTree *stree)
 
static int addtonewktable (lua_State *L, int p, int idx)
 
static int testpattern (lua_State *L, int idx)
 
static Patterngetpattern (lua_State *L, int idx)
 
static int getsize (lua_State *L, int idx)
 
static TTreegettree (lua_State *L, int idx, int *len)
 
static TTreenewtree (lua_State *L, int len)
 
static TTreenewleaf (lua_State *L, int tag)
 
static TTreenewcharset (lua_State *L)
 
static TTreeseqaux (TTree *tree, TTree *sib, int sibsize)
 
static void fillseq (TTree *tree, int tag, int n, const char *s)
 
static TTreenumtree (lua_State *L, int n)
 
static TTreegetpatt (lua_State *L, int idx, int *len)
 
static TTreenewroot1sib (lua_State *L, int tag)
 
static TTreenewroot2sib (lua_State *L, int tag)
 
static int lp_P (lua_State *L)
 
static int lp_seq (lua_State *L)
 
static int lp_choice (lua_State *L)
 
static int lp_star (lua_State *L)
 
static int lp_and (lua_State *L)
 
static int lp_not (lua_State *L)
 
static int lp_sub (lua_State *L)
 
static int lp_set (lua_State *L)
 
static int lp_range (lua_State *L)
 
static int lp_behind (lua_State *L)
 
static int lp_V (lua_State *L)
 
static int capture_aux (lua_State *L, int cap, int labelidx)
 
static TTreeauxemptycap (TTree *tree, int cap)
 
static TTreenewemptycap (lua_State *L, int cap)
 
static TTreenewemptycapkey (lua_State *L, int cap, int idx)
 
static int lp_divcapture (lua_State *L)
 
static int lp_substcapture (lua_State *L)
 
static int lp_tablecapture (lua_State *L)
 
static int lp_groupcapture (lua_State *L)
 
static int lp_foldcapture (lua_State *L)
 
static int lp_simplecapture (lua_State *L)
 
static int lp_poscapture (lua_State *L)
 
static int lp_argcapture (lua_State *L)
 
static int lp_backref (lua_State *L)
 
static int lp_constcapture (lua_State *L)
 
static int lp_matchtime (lua_State *L)
 
static void getfirstrule (lua_State *L, int arg, int postab)
 
static int collectrules (lua_State *L, int arg, int *totalsize)
 
static void buildgrammar (lua_State *L, TTree *grammar, int frule, int n)
 
static int checkloops (TTree *tree)
 
static int verifyerror (lua_State *L, int *passed, int npassed)
 
static int verifyrule (lua_State *L, TTree *tree, int *passed, int npassed, int nb)
 
static void verifygrammar (lua_State *L, TTree *grammar)
 
static void initialrulename (lua_State *L, TTree *grammar, int frule)
 
static Instructionprepcompile (lua_State *L, Pattern *p, int idx)
 
static int lp_printtree (lua_State *L)
 
static int lp_printcode (lua_State *L)
 
static size_t initposition (lua_State *L, size_t len)
 
static int lp_match (lua_State *L)
 
static int lp_setmax (lua_State *L)
 
static int lp_version (lua_State *L)
 
static int lp_type (lua_State *L)
 
int lp_gc (lua_State *L)
 
static void createcat (lua_State *L, const char *catname, int(catf)(int))
 
static int lp_locale (lua_State *L)
 
int luaopen_lpeg (lua_State *L)
 

Variables

static const char * tagnames []
 
static const Instruction giveup = {{IGiveup, 0, 0}}
 
static const Charset fullset_
 
static const Charsetfullset = &fullset_
 
const byte numsiblings []
 
static struct luaL_Reg pattreg []
 
static struct luaL_Reg metareg []
 

Macro Definition Documentation

◆ captype

#define captype (   cap)    ((cap)->kind)

Definition at line 1655 of file lpeg.c.

◆ closeaddr

#define closeaddr (   c)    ((c)->s + (c)->siz - 1)

Definition at line 1659 of file lpeg.c.

◆ getfromktable

#define getfromktable (   cs,
  v 
)    lua_rawgeti((cs)->L, ktableidx((cs)->ptop), v)

Definition at line 1663 of file lpeg.c.

◆ gethere

#define gethere (   compst)    ((compst)->ncode)

Definition at line 1163 of file lpeg.c.

◆ getinstr

#define getinstr (   cs,
  i 
)    ((cs)->p->code[i])

Definition at line 1119 of file lpeg.c.

◆ getoffset

#define getoffset (   p)    (((p) + 1)->offset)

Definition at line 271 of file lpeg.c.

◆ getstackbase

#define getstackbase (   L,
  ptop 
)    ((Stack *)lua_touserdata(L, stackidx(ptop)))

Definition at line 290 of file lpeg.c.

◆ INITBACK

#define INITBACK   MAXBACK

Definition at line 267 of file lpeg.c.

◆ isclosecap

#define isclosecap (   cap)    (captype(cap) == Cclose)

Definition at line 1657 of file lpeg.c.

◆ isfullcap

#define isfullcap (   cap)    ((cap)->siz != 0)

Definition at line 1661 of file lpeg.c.

◆ MAXLIM

#define MAXLIM   (INT_MAX / 100)

Definition at line 3373 of file lpeg.c.

◆ MAXSTRCAPS

#define MAXSTRCAPS   10

Definition at line 1964 of file lpeg.c.

◆ NOINST

#define NOINST   -1

Definition at line 645 of file lpeg.c.

◆ pushluaval

#define pushluaval (   cs)    getfromktable(cs, (cs)->cap->idx)

Definition at line 1665 of file lpeg.c.

◆ target

Typedef Documentation

◆ CompileState

typedef struct CompileState CompileState

◆ Stack

typedef struct Stack Stack

◆ StrAux

typedef struct StrAux StrAux

Function Documentation

◆ addcharset()

static void addcharset ( CompileState compst,
const byte cs 
)
static

Definition at line 1201 of file lpeg.c.

References buff, CHARSETINSTSIZE, gethere, getinstr, i, int(), j, loopset, nextinstruction(), and p.

Referenced by codecharset(), coderep(), and codetestset().

◆ adddyncaptures()

static void adddyncaptures ( const char *  s,
Capture base,
int  n,
int  fd 
)
static

Definition at line 362 of file lpeg.c.

References base, Cclose, Cgroup, Cruntime, i, n, and s.

Referenced by match().

◆ addinstcap()

static int addinstcap ( CompileState compst,
Opcode  op,
int  cap,
int  key,
int  aux 
)
static

Definition at line 1155 of file lpeg.c.

References addinstruction(), aux, getinstr, i, joinkindoff, and key.

Referenced by codecapture(), and coderuntime().

◆ addinstruction()

static int addinstruction ( CompileState compst,
Opcode  op,
int  aux 
)
static

◆ addoffsetinst()

static int addoffsetinst ( CompileState compst,
Opcode  op 
)
static

Definition at line 1133 of file lpeg.c.

References addinstruction(), assert(), getinstr, i, ITestSet, and sizei().

Referenced by codeand(), codecall(), codechoice(), codegrammar(), codenot(), coderep(), and codetestset().

◆ addonestring()

static int addonestring ( luaL_Buffer b,
CapState cs,
const char *  what 
)
static

◆ addtoktable()

static int addtoktable ( lua_State L,
int  idx 
)
static

◆ addtonewktable()

static int addtonewktable ( lua_State L,
int  p,
int  idx 
)
static

Definition at line 2481 of file lpeg.c.

References addtoktable(), idx, L, mergektable(), newktable(), NULL, and p.

Referenced by capture_aux(), getpatt(), lp_matchtime(), lp_V(), and newemptycapkey().

◆ auxemptycap()

static TTree* auxemptycap ( TTree tree,
int  cap 
)
static

Definition at line 2899 of file lpeg.c.

References TTree::cap, sib1, TTree::tag, TCapture, and TTrue.

Referenced by lp_constcapture(), newemptycap(), and newemptycapkey().

◆ backrefcap()

static int backrefcap ( CapState cs)
static

Definition at line 1786 of file lpeg.c.

References curr, findback(), n, pushluaval, and pushnestedvalues().

Referenced by pushcapture().

◆ buildgrammar()

static void buildgrammar ( lua_State L,
TTree grammar,
int  frule,
int  n 
)
static

Definition at line 3109 of file lpeg.c.

References gettree(), i, L, memcpy, mergektable(), n, nd, sib1, sib2, TRule, and TTrue.

Referenced by newgrammar().

◆ callrecursive()

static int callrecursive ( TTree tree,
int   fTTree *t,
int  def 
)
static

Definition at line 761 of file lpeg.c.

References assert(), def, f, key, TTree::key, check-static-inits::result, sib2, TTree::tag, TCall, and TRule.

Referenced by fixedlen(), and hascaptures().

◆ capkind()

static const char* capkind ( int  kind)
static

Definition at line 42 of file lpeg.c.

References kind, and modes.

Referenced by printcap(), printinst(), and printtree().

◆ capture_aux()

static int capture_aux ( lua_State L,
int  cap,
int  labelidx 
)
static

◆ charsettype()

static Opcode charsettype ( const byte cs,
int c 
)
static

Definition at line 669 of file lpeg.c.

References assert(), b, BITSPERCHAR, c, CHARSETSIZE, count, i, IAny, IChar, IFail, and ISet.

Referenced by codecharset(), and codetestset().

◆ checkaux()

int checkaux ( TTree tree,
int  pred 
)

Definition at line 824 of file lpeg.c.

References assert(), PEnofail, PEnullable, sib1, sib2, TTree::tag, TAnd, TAny, TBehind, TCall, TCapture, TChar, TChoice, TFalse, TGrammar, TNot, TOpenCall, TRep, TRule, TRunTime, TSeq, TSet, and TTrue.

Referenced by checkaux().

◆ checkloops()

static int checkloops ( TTree tree)
static

Definition at line 3131 of file lpeg.c.

References assert(), nullable, numsiblings, sib1, sib2, TTree::tag, TGrammar, and TRep.

Referenced by verifygrammar().

◆ codeand()

static void codeand ( CompileState compst,
TTree tree,
int  tt 
)
static

◆ codebehind()

static void codebehind ( CompileState compst,
TTree tree 
)
static

Definition at line 1287 of file lpeg.c.

References addinstruction(), codegen(), fullset, IBehind, TTree::n, NOINST, sib1, and TTree::u.

Referenced by codegen().

◆ codecall()

static void codecall ( CompileState compst,
TTree call 
)
static

Definition at line 1515 of file lpeg.c.

References addoffsetinst(), assert(), c, call, getinstr, IOpenCall, sib2, and TRule.

Referenced by codegen().

◆ codecapture()

static void codecapture ( CompileState compst,
TTree tree,
int  tt,
const Charset fl 
)
static

◆ codechar()

static void codechar ( CompileState compst,
int  c,
int  tt 
)
static

Definition at line 1189 of file lpeg.c.

References addinstruction(), c, getinstr, i, IAny, IChar, and ITestChar.

Referenced by codecharset(), and codegen().

◆ codecharset()

static void codecharset ( CompileState compst,
const byte cs,
int  tt 
)
static

Definition at line 1216 of file lpeg.c.

References addcharset(), addinstruction(), buff, c, charsettype(), codechar(), cs_equal(), getinstr, i, IAny, IChar, ISet, and ITestSet.

Referenced by codegen().

◆ codechoice()

static void codechoice ( CompileState compst,
TTree p1,
TTree p2,
int  opt,
const Charset fl 
)
static

◆ codegen()

◆ codegrammar()

static void codegrammar ( CompileState compst,
TTree grammar 
)
static

◆ codenot()

static void codenot ( CompileState compst,
TTree tree 
)
static

◆ coderep()

◆ coderuntime()

static void coderuntime ( CompileState compst,
TTree tree,
int  tt 
)
static

Definition at line 1388 of file lpeg.c.

References addinstcap(), Cclose, Cgroup, codegen(), fullset, ICloseRunTime, IOpenCapture, TTree::key, and sib1.

Referenced by codegen().

◆ codeseq1()

static int codeseq1 ( CompileState compst,
TTree p1,
TTree p2,
int  tt,
const Charset fl 
)
static

Definition at line 1527 of file lpeg.c.

References codegen(), fixedlen(), fullset, getfirst(), needfollow(), NOINST, p1, and p2.

Referenced by codegen().

◆ codetestset()

static int codetestset ( CompileState compst,
Charset cs,
int  e 
)
static

Definition at line 1242 of file lpeg.c.

References addcharset(), addoffsetinst(), assert(), c, charsettype(), e, getinstr, i, IAny, IChar, IFail, IJmp, ISet, ITestAny, ITestChar, ITestSet, and NOINST.

Referenced by codechoice(), codenot(), and coderep().

◆ collectrules()

◆ compile()

Instruction* compile ( lua_State L,
Pattern p 
)

◆ concattable()

static int concattable ( lua_State L,
int  idx1,
int  idx2 
)
static

Definition at line 2373 of file lpeg.c.

References i, ktablelen(), L, lua_rawgeti(), lua_rawseti(), luaL_error(), and USHRT_MAX.

Referenced by joinktables(), and mergektable().

◆ copyktable()

static void copyktable ( lua_State L,
int  idx 
)
static

Definition at line 2455 of file lpeg.c.

References idx, L, lua_getuservalue(), and lua_setuservalue().

Referenced by lp_star(), and newroot1sib().

◆ correctassociativity()

static void correctassociativity ( TTree tree)
static

Definition at line 2257 of file lpeg.c.

References assert(), memmove, TTree::ps, sib1, sib2, t1, TTree::tag, TChoice, TSeq, and TTree::u.

Referenced by finalfix().

◆ correctcalls()

static void correctcalls ( CompileState compst,
int positions,
int  from,
int  to 
)
static

Definition at line 1472 of file lpeg.c.

References assert(), Pattern::code, finaltarget(), i, ICall, IJmp, IOpenCall, IRet, jumptothere(), n, CompileState::p, sizei(), and to.

Referenced by codegrammar().

◆ correctkeys()

static void correctkeys ( TTree tree,
int  n 
)
static

Definition at line 2393 of file lpeg.c.

References assert(), TTree::cap, Carg, Cnum, TTree::key, n, numsiblings, sib1, sib2, TTree::tag, TCall, TCapture, TOpenCall, TRule, and TRunTime.

Referenced by joinktables(), and mergektable().

◆ createcat()

static void createcat ( lua_State L,
const char *  catname,
int(catf)(int  
)
static

Definition at line 3406 of file lpeg.c.

References i, L, lua_setfield(), newcharset(), setchar(), treebuffer, and UCHAR_MAX.

Referenced by lp_locale().

◆ cs_complement()

static void cs_complement ( Charset cs)
static

Definition at line 716 of file lpeg.c.

References i, and loopset.

Referenced by getfirst().

◆ cs_disjoint()

static int cs_disjoint ( const Charset cs1,
const Charset cs2 
)
static

Definition at line 725 of file lpeg.c.

References Charset::cs, i, and loopset.

Referenced by codechoice(), and coderep().

◆ cs_equal()

static int cs_equal ( const byte cs1,
const byte cs2 
)
static

Definition at line 720 of file lpeg.c.

References i, and loopset.

Referenced by codecharset().

◆ doublecap()

static Capture* doublecap ( lua_State L,
Capture cap,
int  captop,
int  n,
int  ptop 
)
static

Definition at line 297 of file lpeg.c.

References caplistidx, INT_MAX, L, lua_newuserdata(), lua_replace, luaL_error(), memcpy, and n.

Referenced by match().

◆ doublestack()

static Stack* doublestack ( lua_State L,
Stack **  stacklimit,
int  ptop 
)
static

◆ fillseq()

static void fillseq ( TTree tree,
int  tag,
int  n,
const char *  s 
)
static

Definition at line 2580 of file lpeg.c.

References byte, i, n, TTree::n, TTree::ps, s, sib1, sib2, tag, TTree::tag, TSeq, and TTree::u.

Referenced by getpatt(), and numtree().

◆ finalfix()

static void finalfix ( lua_State L,
int  postable,
TTree g,
TTree t 
)
static

◆ finallabel()

static int finallabel ( Instruction code,
int  i 
)
static

Definition at line 1279 of file lpeg.c.

References finaltarget(), i, and target.

Referenced by peephole().

◆ finaltarget()

static int finaltarget ( Instruction code,
int  i 
)
static

Definition at line 1269 of file lpeg.c.

References i, IJmp, and target.

Referenced by correctcalls(), finallabel(), and peephole().

◆ findback()

static Capture* findback ( CapState cs,
Capture cap 
)
static

◆ finddyncap()

int finddyncap ( Capture cap,
Capture last 
)

Definition at line 1906 of file lpeg.c.

References Cruntime, Capture::idx, Capture::kind, and last.

Referenced by removedyncap(), and runtimecap().

◆ findopen()

static Capture* findopen ( Capture cap)
static

Definition at line 1691 of file lpeg.c.

References isclosecap, isfullcap, and n.

Referenced by findback(), and runtimecap().

◆ fixedlen()

int fixedlen ( TTree tree)

◆ fixonecall()

static void fixonecall ( lua_State L,
int  postable,
TTree g,
TTree t 
)
static

Definition at line 2233 of file lpeg.c.

References assert(), g, L, lua_gettable(), lua_pop, lua_rawgeti(), lua_tonumber, luaL_error(), n, sib2, TCall, TRule, and val2str().

Referenced by finalfix().

◆ foldcap()

static int foldcap ( CapState cs)
static

Definition at line 1845 of file lpeg.c.

References idx, isclosecap, isfullcap, L, lua_call, lua_insert, lua_pop, lua_pushvalue(), luaL_error(), n, pushcapture(), and updatecache().

Referenced by pushcapture().

◆ functioncap()

static int functioncap ( CapState cs)
static

Definition at line 1869 of file lpeg.c.

References lua_call, lua_gettop(), LUA_MULTRET, n, pushluaval, pushnestedvalues(), and top.

Referenced by pushcapture().

◆ getcaptures()

int getcaptures ( lua_State L,
const char *  s,
const char *  r,
int  ptop 
)

Definition at line 2161 of file lpeg.c.

References caplistidx, cs, isclosecap, L, lua_pushinteger(), lua_touserdata(), n, pushcapture(), r, and s.

Referenced by lp_match().

◆ getfirst()

static int getfirst ( TTree tree,
const Charset follow,
Charset firstset 
)
static

◆ getfirstrule()

static void getfirstrule ( lua_State L,
int  arg,
int  postab 
)
static

◆ getpatt()

◆ getpattern()

static Pattern* getpattern ( lua_State L,
int  idx 
)
static

Definition at line 2514 of file lpeg.c.

References idx, L, luaL_checkudata(), and PATTERN_T.

Referenced by gettree(), lp_gc(), lp_match(), and lp_printcode().

◆ getsize()

static int getsize ( lua_State L,
int  idx 
)
static

Definition at line 2519 of file lpeg.c.

References idx, L, and lua_rawlen.

Referenced by collectrules(), getpatt(), and gettree().

◆ getstrcaps()

static int getstrcaps ( CapState cs,
StrAux cps,
int  n 
)
static

Definition at line 1972 of file lpeg.c.

References captype, closeaddr, StrAux::cp, Csimple, isclosecap, isfullcap, StrAux::isstring, k, MAXSTRCAPS, n, nextcap(), StrAux::s, and StrAux::u.

Referenced by stringcap().

◆ gettree()

static TTree* gettree ( lua_State L,
int  idx,
int len 
)
static

Definition at line 2524 of file lpeg.c.

References getpattern(), getsize(), idx, L, len, and p.

Referenced by buildgrammar(), and getpatt().

◆ hascaptures()

int hascaptures ( TTree tree)

◆ headfail()

static int headfail ( TTree tree)
static

Definition at line 1005 of file lpeg.c.

References assert(), nofail, sib1, sib2, TTree::tag, TAnd, TAny, TBehind, TCall, TCapture, TChar, TChoice, TFalse, TGrammar, TNot, TRep, TRule, TRunTime, TSeq, TSet, and TTrue.

Referenced by codechoice(), codenot(), and coderep().

◆ initialrulename()

static void initialrulename ( lua_State L,
TTree grammar,
int  frule 
)
static

Definition at line 3248 of file lpeg.c.

References key, L, lua_pushvalue(), lua_rawlen, lua_rawseti(), n, and sib1.

Referenced by newgrammar().

◆ initposition()

static size_t initposition ( lua_State L,
size_t  len 
)
static

Definition at line 3317 of file lpeg.c.

References ii, L, len, luaL_optinteger(), and size_t.

Referenced by lp_match().

◆ joinktables()

static void joinktables ( lua_State L,
int  p1,
TTree t2,
int  p2 
)
static

◆ jumptohere()

static void jumptohere ( CompileState compst,
int  instruction 
)
static

Definition at line 1180 of file lpeg.c.

References gethere, and jumptothere().

Referenced by codeand(), codechoice(), codegrammar(), codenot(), and coderep().

◆ jumptothere()

static void jumptothere ( CompileState compst,
int  instruction,
int  target 
)
static

Definition at line 1171 of file lpeg.c.

References setoffset(), and target.

Referenced by coderep(), correctcalls(), jumptohere(), and peephole().

◆ ktablelen()

static int ktablelen ( lua_State L,
int  idx 
)
static

Definition at line 2361 of file lpeg.c.

References idx, L, lua_istable, and lua_rawlen.

Referenced by concattable(), and joinktables().

◆ lp_and()

static int lp_and ( lua_State L)
static

Definition at line 2787 of file lpeg.c.

References L, newroot1sib(), and TAnd.

◆ lp_argcapture()

static int lp_argcapture ( lua_State L)
static

Definition at line 2982 of file lpeg.c.

References Carg, int(), TTree::key, L, luaL_argcheck, luaL_checkinteger(), n, newemptycap(), and SHRT_MAX.

◆ lp_backref()

static int lp_backref ( lua_State L)
static

Definition at line 2991 of file lpeg.c.

References Cbackref, L, luaL_checkany(), and newemptycapkey().

◆ lp_behind()

static int lp_behind ( lua_State L)
static

◆ lp_choice()

static int lp_choice ( lua_State L)
static

◆ lp_constcapture()

◆ lp_divcapture()

◆ lp_foldcapture()

static int lp_foldcapture ( lua_State L)
static

Definition at line 2965 of file lpeg.c.

References capture_aux(), Cfold, L, LUA_TFUNCTION, and luaL_checktype().

◆ lp_gc()

int lp_gc ( lua_State L)

Definition at line 3399 of file lpeg.c.

References getpattern(), L, p, and realloccode().

◆ lp_groupcapture()

static int lp_groupcapture ( lua_State L)
static

Definition at line 2957 of file lpeg.c.

References capture_aux(), Cgroup, L, and lua_isnoneornil.

◆ lp_locale()

◆ lp_match()

◆ lp_matchtime()

static int lp_matchtime ( lua_State L)
static

Definition at line 3029 of file lpeg.c.

References addtonewktable(), TTree::key, L, LUA_TFUNCTION, luaL_checktype(), newroot1sib(), and TRunTime.

◆ lp_not()

static int lp_not ( lua_State L)
static

Definition at line 2796 of file lpeg.c.

References L, newroot1sib(), and TNot.

◆ lp_P()

static int lp_P ( lua_State L)
static

Definition at line 2698 of file lpeg.c.

References getpatt(), L, lua_settop(), luaL_checkany(), and NULL.

◆ lp_poscapture()

static int lp_poscapture ( lua_State L)
static

Definition at line 2976 of file lpeg.c.

References Cposition, L, and newemptycap().

◆ lp_printcode()

static int lp_printcode ( lua_State L)
static

Definition at line 3303 of file lpeg.c.

References getpattern(), L, NULL, p, prepcompile(), printktable(), and printpatt().

◆ lp_printtree()

static int lp_printtree ( lua_State L)
static

Definition at line 3289 of file lpeg.c.

References c, finalfix(), getpatt(), L, lua_getuservalue(), lua_pop, lua_toboolean(), NULL, printktable(), and printtree().

◆ lp_range()

static int lp_range ( lua_State L)
static

Definition at line 2840 of file lpeg.c.

References byte, c, cutout::l, L, lua_gettop(), luaL_argcheck, luaL_checklstring(), newcharset(), r, setchar(), top, and treebuffer.

◆ lp_seq()

static int lp_seq ( lua_State L)
static

Definition at line 2711 of file lpeg.c.

References getpatt(), L, lua_pushvalue(), newroot2sib(), NULL, TTree::tag, TFalse, TSeq, and TTrue.

◆ lp_set()

static int lp_set ( lua_State L)
static

Definition at line 2828 of file lpeg.c.

References cutout::l, L, luaL_checklstring(), newcharset(), s, setchar(), and treebuffer.

◆ lp_setmax()

static int lp_setmax ( lua_State L)
static

◆ lp_simplecapture()

static int lp_simplecapture ( lua_State L)
static

Definition at line 2971 of file lpeg.c.

References capture_aux(), Csimple, and L.

◆ lp_star()

◆ lp_sub()

static int lp_sub ( lua_State L)
static

◆ lp_substcapture()

static int lp_substcapture ( lua_State L)
static

Definition at line 2947 of file lpeg.c.

References capture_aux(), Csubst, and L.

◆ lp_tablecapture()

static int lp_tablecapture ( lua_State L)
static

Definition at line 2952 of file lpeg.c.

References capture_aux(), Ctable, and L.

◆ lp_type()

static int lp_type ( lua_State L)
static

Definition at line 3390 of file lpeg.c.

References L, lua_pushliteral, lua_pushnil(), and testpattern().

◆ lp_V()

static int lp_V ( lua_State L)
static

Definition at line 2875 of file lpeg.c.

References addtonewktable(), TTree::key, L, lua_isnoneornil, luaL_argcheck, newleaf(), and TOpenCall.

◆ lp_version()

static int lp_version ( lua_State L)
static

Definition at line 3384 of file lpeg.c.

References L, lua_pushstring(), and VERSION.

◆ luaopen_lpeg()

◆ match()

◆ mergektable()

static void mergektable ( lua_State L,
int  idx,
TTree stree 
)
static

Definition at line 2466 of file lpeg.c.

References concattable(), correctkeys(), idx, L, lua_getuservalue(), lua_pop, and n.

Referenced by addtonewktable(), and buildgrammar().

◆ needfollow()

static int needfollow ( TTree tree)
static

Definition at line 1035 of file lpeg.c.

References assert(), sib1, sib2, TTree::tag, TAnd, TAny, TBehind, TCall, TCapture, TChar, TChoice, TFalse, TGrammar, TNot, TRep, TRunTime, TSeq, TSet, and TTrue.

Referenced by codeseq1().

◆ newcharset()

static TTree* newcharset ( lua_State L)
static

Definition at line 2556 of file lpeg.c.

References bytes2slots, CHARSETSIZE, i, L, loopset, newtree(), TTree::tag, treebuffer, and TSet.

Referenced by createcat(), lp_choice(), lp_range(), lp_set(), and lp_sub().

◆ newemptycap()

static TTree* newemptycap ( lua_State L,
int  cap 
)
static

Definition at line 2910 of file lpeg.c.

References auxemptycap(), L, and newtree().

Referenced by lp_argcapture(), and lp_poscapture().

◆ newemptycapkey()

static TTree* newemptycapkey ( lua_State L,
int  cap,
int  idx 
)
static

Definition at line 2918 of file lpeg.c.

References addtonewktable(), auxemptycap(), idx, TTree::key, L, and newtree().

Referenced by lp_backref(), and lp_constcapture().

◆ newgrammar()

◆ newktable()

static void newktable ( lua_State L,
int  n 
)
static

Definition at line 2326 of file lpeg.c.

References L, lua_createtable(), lua_setuservalue(), and n.

Referenced by addtonewktable(), and lp_constcapture().

◆ newleaf()

static TTree* newleaf ( lua_State L,
int  tag 
)
static

Definition at line 2549 of file lpeg.c.

References L, newtree(), tag, and TTree::tag.

Referenced by getpatt(), lp_constcapture(), lp_V(), and numtree().

◆ newroot1sib()

static TTree* newroot1sib ( lua_State L,
int  tag 
)
static

Definition at line 2669 of file lpeg.c.

References copyktable(), getpatt(), L, memcpy, newtree(), s1, sib1, tag, and TTree::tag.

Referenced by capture_aux(), lp_and(), lp_behind(), lp_divcapture(), lp_matchtime(), and lp_not().

◆ newroot2sib()

static TTree* newroot2sib ( lua_State L,
int  tag 
)
static

Definition at line 2684 of file lpeg.c.

References getpatt(), joinktables(), L, memcpy, newtree(), TTree::ps, s1, s2, sib1, sib2, tag, TTree::tag, and TTree::u.

Referenced by lp_choice(), and lp_seq().

◆ newtree()

◆ nextcap()

static void nextcap ( CapState cs)
static

Definition at line 1705 of file lpeg.c.

References isclosecap, isfullcap, and n.

Referenced by getstrcaps(), numcap(), and pushcapture().

◆ nextinstruction()

static int nextinstruction ( CompileState compst)
static

◆ numcap()

static int numcap ( CapState cs)
static

Definition at line 1882 of file lpeg.c.

References idx, lua_pop, lua_pushvalue(), lua_replace, luaL_error(), n, nextcap(), and pushnestedvalues().

Referenced by pushcapture().

◆ numtree()

static TTree* numtree ( lua_State L,
int  n 
)
static

Definition at line 2598 of file lpeg.c.

References fillseq(), L, n, nd, newleaf(), newtree(), NULL, sib1, TTree::tag, TAny, TNot, and TTrue.

Referenced by getpatt(), main(), and mktexupd().

◆ peephole()

◆ prepcompile()

static Instruction* prepcompile ( lua_State L,
Pattern p,
int  idx 
)
static

Definition at line 3281 of file lpeg.c.

References compile(), finalfix(), idx, L, lua_getuservalue(), lua_pop, NULL, and p.

Referenced by lp_match(), and lp_printcode().

◆ printcap()

static void printcap ( Capture cap)
static

Definition at line 127 of file lpeg.c.

References capkind(), Capture::idx, Capture::kind, printf(), Capture::s, and Capture::siz.

Referenced by printcaplist().

◆ printcaplist()

void printcaplist ( Capture cap,
Capture limit 
)

Definition at line 133 of file lpeg.c.

References limit, NULL, printcap(), printf(), and Capture::s.

Referenced by match().

◆ printcharset()

void printcharset ( const byte st)

Definition at line 27 of file lpeg.c.

References first, i, printf(), testchar, and UCHAR_MAX.

Referenced by printinst(), and printtree().

◆ printinst()

◆ printjmp()

static void printjmp ( const Instruction op,
const Instruction p 
)
static

Definition at line 52 of file lpeg.c.

References offset, p, and printf().

Referenced by printinst().

◆ printktable()

void printktable ( lua_State L,
int  idx 
)

◆ printpatt()

void printpatt ( Instruction p,
int  n 
)

Definition at line 117 of file lpeg.c.

References n, p, printinst(), and sizei().

Referenced by lp_printcode().

◆ printtree()

void printtree ( TTree tree,
int  ident 
)

◆ pushcapture()

◆ pushnestedvalues()

static int pushnestedvalues ( CapState cs,
int  addextra 
)
static

◆ pushonenestedvalue()

static void pushonenestedvalue ( CapState cs)
static

Definition at line 1751 of file lpeg.c.

References lua_pop, n, and pushnestedvalues().

Referenced by querycap(), and tablecap().

◆ querycap()

static int querycap ( CapState cs)
static

Definition at line 1829 of file lpeg.c.

References idx, lua_gettable(), lua_isnil, lua_pop, pushonenestedvalue(), and updatecache().

Referenced by pushcapture().

◆ realloccode()

void realloccode ( lua_State L,
Pattern p,
int  nsize 
)

Definition at line 1099 of file lpeg.c.

References f, L, lua_getallocf(), luaL_error(), NULL, and p.

Referenced by compile(), lp_gc(), and nextinstruction().

◆ removedyncap()

static int removedyncap ( lua_State L,
Capture capture,
int  level,
int  last 
)
static

Definition at line 382 of file lpeg.c.

References finddyncap(), L, last, level, lua_gettop(), lua_settop(), and top.

Referenced by match().

◆ resdyncaptures()

static int resdyncaptures ( lua_State L,
int  fr,
int  curr,
int  limit 
)
static

Definition at line 339 of file lpeg.c.

References curr, L, limit, lua_isboolean, lua_remove, lua_settop(), lua_toboolean(), lua_tointeger, luaL_error(), and res.

Referenced by match().

◆ runtimecap()

int runtimecap ( CapState cs,
Capture close,
const char *  s,
int rem 
)

◆ seqaux()

static TTree* seqaux ( TTree tree,
TTree sib,
int  sibsize 
)
static

Definition at line 2568 of file lpeg.c.

References memcpy, TTree::ps, sib1, sib2, TTree::tag, TSeq, and TTree::u.

Referenced by lp_star().

◆ setoffset()

static void setoffset ( CompileState compst,
int  instruction,
int  offset 
)
static

Definition at line 1144 of file lpeg.c.

References getinstr, and offset.

Referenced by jumptothere().

◆ sizei()

◆ stringcap()

◆ substcap()

static void substcap ( luaL_Buffer b,
CapState cs 
)
static

Definition at line 2039 of file lpeg.c.

References addonestring(), b, closeaddr, curr, isclosecap, isfullcap, luaL_addlstring(), and next.

Referenced by addonestring(), and pushcapture().

◆ tablecap()

static int tablecap ( CapState cs)
static

◆ testpattern()

static int testpattern ( lua_State L,
int  idx 
)
static

◆ tocharset()

int tocharset ( TTree tree,
Charset cs 
)

Definition at line 735 of file lpeg.c.

References assert(), i, loopset, TTree::n, setchar(), TTree::tag, TAny, TChar, treebuffer, TSet, TTree::u, and UCHAR_MAX.

Referenced by coderep(), getfirst(), lp_choice(), and lp_sub().

◆ updatecache()

static int updatecache ( CapState cs,
int  v 
)
static

Definition at line 1673 of file lpeg.c.

References getfromktable, idx, lua_replace, and v.

Referenced by foldcap(), querycap(), and stringcap().

◆ val2str()

static const char* val2str ( lua_State L,
int  idx 
)
static

Definition at line 2219 of file lpeg.c.

References idx, k, L, lua_pushfstring(), lua_tostring, luaL_typename, and NULL.

Referenced by collectrules(), finalfix(), fixonecall(), verifyerror(), and verifygrammar().

◆ verifyerror()

static int verifyerror ( lua_State L,
int passed,
int  npassed 
)
static

Definition at line 3156 of file lpeg.c.

References i, j, L, lua_rawgeti(), luaL_error(), and val2str().

Referenced by verifyrule().

◆ verifygrammar()

static void verifygrammar ( lua_State L,
TTree grammar 
)
static

Definition at line 3224 of file lpeg.c.

References assert(), checkloops(), L, lua_rawgeti(), luaL_error(), MAXRULES, sib1, sib2, TRule, TTrue, val2str(), and verifyrule().

Referenced by newgrammar().

◆ verifyrule()

static int verifyrule ( lua_State L,
TTree tree,
int passed,
int  npassed,
int  nb 
)
static

Variable Documentation

◆ fullset

const Charset* fullset = &fullset_
static

◆ fullset_

const Charset fullset_
static
Initial value:
=
{{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}}

Definition at line 649 of file lpeg.c.

◆ giveup

const Instruction giveup = {{IGiveup, 0, 0}}
static

Definition at line 273 of file lpeg.c.

Referenced by match().

◆ metareg

struct luaL_Reg metareg[]
static
Initial value:
= {
{"__mul", lp_seq},
{"__add", lp_choice},
{"__pow", lp_star},
{"__gc", lp_gc},
{"__len", lp_and},
{"__div", lp_divcapture},
{"__unm", lp_not},
{"__sub", lp_sub},
}
#define NULL
Definition: ftobjs.h:61
static int lp_divcapture(lua_State *L)
Definition: lpeg.c:2929
static int lp_seq(lua_State *L)
Definition: lpeg.c:2711
static int lp_not(lua_State *L)
Definition: lpeg.c:2796
static int lp_star(lua_State *L)
Definition: lpeg.c:2751
static int lp_sub(lua_State *L)
Definition: lpeg.c:2806
static int lp_and(lua_State *L)
Definition: lpeg.c:2787
int lp_gc(lua_State *L)
Definition: lpeg.c:3399
static int lp_choice(lua_State *L)
Definition: lpeg.c:2730

Definition at line 3415 of file lpeg.c.

Referenced by luaopen_lpeg().

◆ numsiblings

const byte numsiblings[]
Initial value:
= {
0, 0, 0,
0, 0,
1,
2, 2,
1, 1,
0, 0, 2, 1,
1,
1, 1
}

Definition at line 2201 of file lpeg.c.

Referenced by checkloops(), correctkeys(), finalfix(), hascaptures(), and printtree().

◆ pattreg

struct luaL_Reg pattreg[]
static
Initial value:
= {
{"ptree", lp_printtree},
{"pcode", lp_printcode},
{"match", lp_match},
{"B", lp_behind},
{"V", lp_V},
{"Cc", lp_constcapture},
{"Cmt", lp_matchtime},
{"Cb", lp_backref},
{"Carg", lp_argcapture},
{"Cp", lp_poscapture},
{"Cs", lp_substcapture},
{"Ct", lp_tablecapture},
{"Cf", lp_foldcapture},
{"Cg", lp_groupcapture},
{"P", lp_P},
{"S", lp_set},
{"R", lp_range},
{"locale", lp_locale},
{"version", lp_version},
{"setmaxstack", lp_setmax},
{"type", lp_type},
}
static int lp_groupcapture(lua_State *L)
Definition: lpeg.c:2957
static int lp_substcapture(lua_State *L)
Definition: lpeg.c:2947
static int lp_foldcapture(lua_State *L)
Definition: lpeg.c:2965
static int lp_backref(lua_State *L)
Definition: lpeg.c:2991
static int lp_printcode(lua_State *L)
Definition: lpeg.c:3303
static int lp_match(lua_State *L)
Definition: lpeg.c:3335
static int lp_matchtime(lua_State *L)
Definition: lpeg.c:3029
static int lp_P(lua_State *L)
Definition: lpeg.c:2698
static int lp_setmax(lua_State *L)
Definition: lpeg.c:3375
static int lp_simplecapture(lua_State *L)
Definition: lpeg.c:2971
static int lp_set(lua_State *L)
Definition: lpeg.c:2828
static int lp_range(lua_State *L)
Definition: lpeg.c:2840
static int lp_V(lua_State *L)
Definition: lpeg.c:2875
static int lp_constcapture(lua_State *L)
Definition: lpeg.c:3001
static int lp_type(lua_State *L)
Definition: lpeg.c:3390
static int lp_version(lua_State *L)
Definition: lpeg.c:3384
static int lp_behind(lua_State *L)
Definition: lpeg.c:2859
static int lp_printtree(lua_State *L)
Definition: lpeg.c:3289
static int lp_locale(lua_State *L)
Definition: lpeg.c:3415
static int lp_poscapture(lua_State *L)
Definition: lpeg.c:2976
static int lp_argcapture(lua_State *L)
Definition: lpeg.c:2982
static int lp_tablecapture(lua_State *L)
Definition: lpeg.c:2952

Definition at line 3415 of file lpeg.c.

Referenced by luaopen_lpeg().

◆ tagnames

const char* tagnames[]
static
Initial value:
= {
"char", "set", "any",
"true", "false",
"rep",
"seq", "choice",
"not", "and",
"call", "opencall", "rule", "grammar",
"behind",
"capture", "run-time"
}

Definition at line 150 of file lpeg.c.

Referenced by printtree().