Skip to content

Commit 58caa37

Browse files
committed
Upgraded LPEG library from version 0.12.2 to version 1.0.0.
1 parent 1f5f0e7 commit 58caa37

File tree

7 files changed

+101
-108
lines changed

7 files changed

+101
-108
lines changed

scripting/lpeg/lpcap.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#pragma warning( disable : 4244) // conversion from 'int ' to 'short ', possible loss of data
2-
31
/*
4-
** $Id: lpcap.c,v 1.5 2014/12/12 16:58:47 roberto Exp $
2+
** $Id: lpcap.c,v 1.6 2015/06/15 16:09:57 roberto Exp $
53
** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
64
*/
75

@@ -133,7 +131,7 @@ static Capture *findback (CapState *cs, Capture *cap) {
133131
continue; /* opening an enclosing capture: skip and get previous */
134132
if (captype(cap) == Cgroup) {
135133
getfromktable(cs, cap->idx); /* get group name */
136-
if (lua_equal(L, -2, -1)) { /* right group? */
134+
if (lp_equal(L, -2, -1)) { /* right group? */
137135
lua_pop(L, 2); /* remove reference name and group name */
138136
return cap;
139137
}

scripting/lpeg/lpcode.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma warning( disable : 4244) // conversion from 'int ' to 'short ', possible loss of data
22

33
/*
4-
** $Id: lpcode.c,v 1.21 2014/12/12 17:01:29 roberto Exp $
4+
** $Id: lpcode.c,v 1.23 2015/06/12 18:36:47 roberto Exp $
55
** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
66
*/
77

88
#include <limits.h>
99

10-
1110
#ifdef LUA_52
1211
#include "..\..\..\lua52\src\lua.h"
1312
#include "..\..\..\lua52\src\lauxlib.h"
@@ -438,11 +437,11 @@ typedef struct CompileState {
438437

439438

440439
/*
441-
** code generation is recursive; 'opt' indicates that the code is
442-
** being generated under a 'IChoice' operator jumping to its end
443-
** (that is, the match is "optional").
444-
** 'tt' points to a previous test protecting this code. 'fl' is
445-
** the follow set of the pattern.
440+
** code generation is recursive; 'opt' indicates that the code is being
441+
** generated as the last thing inside an optional pattern (so, if that
442+
** code is optional too, it can reuse the 'IChoice' already in place for
443+
** the outer pattern). 'tt' points to a previous test protecting this
444+
** code (or NOINST). 'fl' is the follow set of the pattern.
446445
*/
447446
static void codegen (CompileState *compst, TTree *tree, int opt, int tt,
448447
const Charset *fl);
@@ -645,13 +644,13 @@ static void codebehind (CompileState *compst, TTree *tree) {
645644

646645
/*
647646
** Choice; optimizations:
648-
** - when p1 is headfail
649-
** - when first(p1) and first(p2) are disjoint; than
647+
** - when p1 is headfail or
648+
** when first(p1) and first(p2) are disjoint, than
650649
** a character not in first(p1) cannot go to p1, and a character
651650
** in first(p1) cannot go to p2 (at it is not in first(p2)).
652651
** (The optimization is not valid if p1 accepts the empty string,
653652
** as then there is no character at all...)
654-
** - when p2 is empty and opt is true; a IPartialCommit can resuse
653+
** - when p2 is empty and opt is true; a IPartialCommit can reuse
655654
** the Choice already active in the stack.
656655
*/
657656
static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
@@ -678,7 +677,7 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
678677
}
679678
else {
680679
/* <p1 / p2> ==
681-
test(fail(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
680+
test(first(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
682681
int pcommit;
683682
int test = codetestset(compst, &cs1, e1);
684683
int pchoice = addoffsetinst(compst, IChoice);
@@ -766,7 +765,7 @@ static void coderep (CompileState *compst, TTree *tree, int opt,
766765
/* L1: test (fail(p1)) -> L2; <p>; jmp L1; L2: */
767766
int jmp;
768767
int test = codetestset(compst, &st, 0);
769-
codegen(compst, tree, opt, test, fullset);
768+
codegen(compst, tree, 0, test, fullset);
770769
jmp = addoffsetinst(compst, IJmp);
771770
jumptohere(compst, test);
772771
jumptothere(compst, jmp, test);

scripting/lpeg/lpcode.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lpcode.h,v 1.6 2013/11/28 14:56:02 roberto Exp $
2+
** $Id: lpcode.h,v 1.7 2015/06/12 18:24:45 roberto Exp $
33
*/
44

55
#if !defined(lpcode_h)
@@ -30,7 +30,15 @@ int sizei (const Instruction *i);
3030
#define PEnullable 0
3131
#define PEnofail 1
3232

33+
/*
34+
** nofail(t) implies that 't' cannot fail with any input
35+
*/
3336
#define nofail(t) checkaux(t, PEnofail)
37+
38+
/*
39+
** (not nullable(t)) implies 't' cannot match without consuming
40+
** something
41+
*/
3442
#define nullable(t) checkaux(t, PEnullable)
3543

3644
#define fixedlen(t) fixedlenx(t, 0, 0)

scripting/lpeg/lpprint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lpprint.h,v 1.1 2013/03/21 20:25:12 roberto Exp $
2+
** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $
33
*/
44

55

@@ -18,6 +18,7 @@ void printtree (TTree *tree, int ident);
1818
void printktable (lua_State *L, int idx);
1919
void printcharset (const byte *st);
2020
void printcaplist (Capture *cap, Capture *limit);
21+
void printinst (const Instruction *op, const Instruction *p);
2122

2223
#else
2324

0 commit comments

Comments
 (0)