Skip to content

Commit

Permalink
Upgraded LPEG library from version 0.12.2 to version 1.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jun 18, 2016
1 parent 1f5f0e7 commit 58caa37
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 108 deletions.
6 changes: 2 additions & 4 deletions scripting/lpeg/lpcap.c
@@ -1,7 +1,5 @@
#pragma warning( disable : 4244) // conversion from 'int ' to 'short ', possible loss of data

/*
** $Id: lpcap.c,v 1.5 2014/12/12 16:58:47 roberto Exp $
** $Id: lpcap.c,v 1.6 2015/06/15 16:09:57 roberto Exp $
** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
*/

Expand Down Expand Up @@ -133,7 +131,7 @@ static Capture *findback (CapState *cs, Capture *cap) {
continue; /* opening an enclosing capture: skip and get previous */
if (captype(cap) == Cgroup) {
getfromktable(cs, cap->idx); /* get group name */
if (lua_equal(L, -2, -1)) { /* right group? */
if (lp_equal(L, -2, -1)) { /* right group? */
lua_pop(L, 2); /* remove reference name and group name */
return cap;
}
Expand Down
23 changes: 11 additions & 12 deletions scripting/lpeg/lpcode.c
@@ -1,13 +1,12 @@
#pragma warning( disable : 4244) // conversion from 'int ' to 'short ', possible loss of data

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

#include <limits.h>


#ifdef LUA_52
#include "..\..\..\lua52\src\lua.h"
#include "..\..\..\lua52\src\lauxlib.h"
Expand Down Expand Up @@ -438,11 +437,11 @@ typedef struct CompileState {


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

/*
** Choice; optimizations:
** - when p1 is headfail
** - when first(p1) and first(p2) are disjoint; than
** - when p1 is headfail or
** when first(p1) and first(p2) are disjoint, than
** a character not in first(p1) cannot go to p1, and a character
** in first(p1) cannot go to p2 (at it is not in first(p2)).
** (The optimization is not valid if p1 accepts the empty string,
** as then there is no character at all...)
** - when p2 is empty and opt is true; a IPartialCommit can resuse
** - when p2 is empty and opt is true; a IPartialCommit can reuse
** the Choice already active in the stack.
*/
static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
Expand All @@ -678,7 +677,7 @@ static void codechoice (CompileState *compst, TTree *p1, TTree *p2, int opt,
}
else {
/* <p1 / p2> ==
test(fail(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
test(first(p1)) -> L1; choice L1; <p1>; commit L2; L1: <p2>; L2: */
int pcommit;
int test = codetestset(compst, &cs1, e1);
int pchoice = addoffsetinst(compst, IChoice);
Expand Down Expand Up @@ -766,7 +765,7 @@ static void coderep (CompileState *compst, TTree *tree, int opt,
/* L1: test (fail(p1)) -> L2; <p>; jmp L1; L2: */
int jmp;
int test = codetestset(compst, &st, 0);
codegen(compst, tree, opt, test, fullset);
codegen(compst, tree, 0, test, fullset);
jmp = addoffsetinst(compst, IJmp);
jumptohere(compst, test);
jumptothere(compst, jmp, test);
Expand Down
10 changes: 9 additions & 1 deletion scripting/lpeg/lpcode.h
@@ -1,5 +1,5 @@
/*
** $Id: lpcode.h,v 1.6 2013/11/28 14:56:02 roberto Exp $
** $Id: lpcode.h,v 1.7 2015/06/12 18:24:45 roberto Exp $
*/

#if !defined(lpcode_h)
Expand Down Expand Up @@ -30,7 +30,15 @@ int sizei (const Instruction *i);
#define PEnullable 0
#define PEnofail 1

/*
** nofail(t) implies that 't' cannot fail with any input
*/
#define nofail(t) checkaux(t, PEnofail)

/*
** (not nullable(t)) implies 't' cannot match without consuming
** something
*/
#define nullable(t) checkaux(t, PEnullable)

#define fixedlen(t) fixedlenx(t, 0, 0)
Expand Down
3 changes: 2 additions & 1 deletion scripting/lpeg/lpprint.h
@@ -1,5 +1,5 @@
/*
** $Id: lpprint.h,v 1.1 2013/03/21 20:25:12 roberto Exp $
** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $
*/


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

#else

Expand Down

0 comments on commit 58caa37

Please sign in to comment.