diff --git a/README.md b/README.md index 9bc162d..5deec35 100644 --- a/README.md +++ b/README.md @@ -35,21 +35,21 @@ Below there is a brief summary of the new functions provided by LpegLabel: - + - + - - - + - +
FunctionDescription
lpeglabelrec.T (l)
lpeglabel.T (l) Throws a label l to signal an error
lpeglabelrec.Rec (p1, p2, l1 [, l2, ..., ln])
lpeglabel.Rec (p1, p2, l1 [, l2, ..., ln]) Specifies a recovery pattern p2 for p1, when the matching of p1 gives one of the labels l1, ..., ln.
%{l}Syntax of relabelrec module. Equivalent to lpeglabelrec.T(l) + Syntax of relabel module. Equivalent to lpeglabel.T(l)
p1 //{l1 [, l2, ..., ln} p2Syntax of relabelrec module. Equivalent to lpeglabelrec.Rec(p1, p2, l1, ..., ln) + Syntax of relabel module. Equivalent to lpeglabel.Rec(p1, p2, l1, ..., ln)
relabelrec.calcline(subject, i)
relabel.calcline(subject, i) Calculates line and column information regarding position i of the subject
relabelrec.setlabels (tlabel)
relabel.setlabels (tlabel) Allows to specicify a table with mnemonic labels.
@@ -58,14 +58,14 @@ Below there is a brief summary of the new functions provided by LpegLabel: ### Functions -#### lpeglabelrec.T(l) +#### lpeglabel.T(l) Returns a pattern that throws the label `l`. A label must be an integer between 1 and 255. -#### lpeglabelrec.Rec(p1, p2, l1, ..., ln) +#### lpeglabel.Rec(p1, p2, l1, ..., ln) Returns a *recovery pattern*. If the matching of `p1` gives one of the labels `l1, ..., ln`, @@ -76,23 +76,23 @@ Otherwise, the result of the matching of `p1` is the pattern's result. #### %{l} -Syntax of *relabelrec* module. Equivalent to `lpeg.T(l)`. +Syntax of *relabel* module. Equivalent to `lpeg.T(l)`. #### p1 //{l1, ..., ln} p2 -Syntax of *relabelrec* module. Equivalent to `lpeglabelrec.Rec(p1, p2, l1, ..., ln)`. +Syntax of *relabel* module. Equivalent to `lpeglabel.Rec(p1, p2, l1, ..., ln)`. The `//{}` operator is left-associative. -#### relabelrec.calcline (subject, i) +#### relabel.calcline (subject, i) Returns line and column information regarding position i of the subject. -#### relabelrec.setlabels (tlabel) +#### relabel.setlabels (tlabel) Allows to specicify a table with labels. They keys of `tlabel` must be integers between 1 and 255, @@ -118,8 +118,8 @@ table and to return the index associated with each error message. ```lua -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local terror = {} @@ -176,7 +176,7 @@ the regular matching. For example, in the example below we expect to match rule `A`, but when a failure occur the label 42 is thrown and then we will try to match the recovery pattern `recp`: ```lua -local m = require'lpeglabelrec' +local m = require'lpeglabel' local recp = m.P"oast" @@ -223,8 +223,8 @@ When the matching of an identifier fails, a defaul value ('NONE') is provided. ```lua -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local terror = {} @@ -311,14 +311,14 @@ print(mymatch(grec, "one\n two123, \nthree,")) -- Error at line 3 (col 6): expecting an identifier ``` -##### *relabelrec* syntax +##### *relabel* syntax Below we describe again a grammar that matches a list of identifiers, -now using the syntax supported by *relabelrec*, where `//{}` is the +now using the syntax supported by *relabel*, where `//{}` is the recovery operator, and `%{}` is the throw operator: ```lua -local re = require 'relabelrec' +local re = require 'relabel' local errinfo = { {"errUndef", "undefined"}, @@ -428,8 +428,8 @@ task to build manually the recovery grammar `grec`. In the next example we will show how to build the recovery grammar in a more automatic way. ```lua -local m = require"lpeglabelrec" -local re = require"relabelrec" +local m = require"lpeglabel" +local re = require"relabel" local labels = { {"ExpTermFirst", "expected an expression"}, @@ -566,8 +566,8 @@ In the example below we also throw an error when the grammar does not match the whole subject. ```lua -local m = require"lpeglabelrec" -local re = require"relabelrec" +local m = require"lpeglabel" +local re = require"relabel" local num = m.R("09")^1 / tonumber local op = m.S("+-") diff --git a/examples/expRec.lua b/examples/expRec.lua index 5c5fd7d..52bd40a 100644 --- a/examples/expRec.lua +++ b/examples/expRec.lua @@ -1,5 +1,5 @@ -local m = require"lpeglabelrec" -local re = require"relabelrec" +local m = require"lpeglabel" +local re = require"relabel" local labels = { {"ExpTermFirst", "expected an expression"}, diff --git a/examples/expRecAut.lua b/examples/expRecAut.lua index f870d73..b8280a7 100644 --- a/examples/expRecAut.lua +++ b/examples/expRecAut.lua @@ -1,5 +1,5 @@ -local m = require"lpeglabelrec" -local re = require"relabelrec" +local m = require"lpeglabel" +local re = require"relabel" local num = m.R("09")^1 / tonumber local op = m.S("+-") diff --git a/examples/listId1.lua b/examples/listId1.lua index dee46e9..b7943c1 100644 --- a/examples/listId1.lua +++ b/examples/listId1.lua @@ -1,5 +1,5 @@ -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local id = m.R'az'^1 diff --git a/examples/listId2.lua b/examples/listId2.lua index 46f0063..3ee89da 100644 --- a/examples/listId2.lua +++ b/examples/listId2.lua @@ -1,5 +1,5 @@ -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local terror = {} diff --git a/examples/listId2Rec2.lua b/examples/listId2Rec2.lua index c6705dd..3506095 100644 --- a/examples/listId2Rec2.lua +++ b/examples/listId2Rec2.lua @@ -1,5 +1,5 @@ -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local terror = {} diff --git a/examples/listId2Rec2Cap.lua b/examples/listId2Rec2Cap.lua index 1c22c88..32a4113 100644 --- a/examples/listId2Rec2Cap.lua +++ b/examples/listId2Rec2Cap.lua @@ -1,5 +1,5 @@ -local m = require'lpeglabelrec' -local re = require'relabelrec' +local m = require'lpeglabel' +local re = require'relabel' local terror = {} diff --git a/examples/listIdRe1.lua b/examples/listIdRe1.lua index 3988a3b..3098c66 100644 --- a/examples/listIdRe1.lua +++ b/examples/listIdRe1.lua @@ -1,4 +1,4 @@ -local re = require 'relabelrec' +local re = require 'relabel' local g = re.compile[[ S <- Id List diff --git a/examples/listIdRe2.lua b/examples/listIdRe2.lua index 6bab6ba..58ddedd 100644 --- a/examples/listIdRe2.lua +++ b/examples/listIdRe2.lua @@ -1,4 +1,4 @@ -local re = require 'relabelrec' +local re = require 'relabel' local errinfo = { {"errUndef", "undefined"}, diff --git a/examples/tiny.lua b/examples/tiny.lua index 784e031..734536c 100644 --- a/examples/tiny.lua +++ b/examples/tiny.lua @@ -1,4 +1,4 @@ -local re = require 'relabelrec' +local re = require 'relabel' local terror = {} diff --git a/examples/typedlua/tllexer.lua b/examples/typedlua/tllexer.lua index d6033ec..96f296d 100644 --- a/examples/typedlua/tllexer.lua +++ b/examples/typedlua/tllexer.lua @@ -1,6 +1,6 @@ local tllexer = {} -local lpeg = require "lpeglabelrec" +local lpeg = require "lpeglabel" lpeg.locale(lpeg) local tlerror = require "tlerror" diff --git a/examples/typedlua/tlparser.lua b/examples/typedlua/tlparser.lua index fe4fd5e..a301fa6 100644 --- a/examples/typedlua/tlparser.lua +++ b/examples/typedlua/tlparser.lua @@ -1,6 +1,6 @@ local tlparser = {} -local lpeg = require "lpeglabelrec" +local lpeg = require "lpeglabel" lpeg.locale(lpeg) local tllexer = require "tllexer" diff --git a/lptree.c b/lptree.c index e15198e..6633035 100644 --- a/lptree.c +++ b/lptree.c @@ -1348,8 +1348,8 @@ static struct luaL_Reg metareg[] = { }; -int luaopen_lpeglabelrec (lua_State *L); /* labeled failure */ -int luaopen_lpeglabelrec (lua_State *L) { /* labeled failure */ +int luaopen_lpeglabel (lua_State *L); /* labeled failure */ +int luaopen_lpeglabel (lua_State *L) { /* labeled failure */ luaL_newmetatable(L, PATTERN_T); lua_pushnumber(L, MAXBACK); /* initialize maximum backtracking */ lua_setfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX); diff --git a/makefile b/makefile index 414651e..5728b38 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -LIBNAME = lpeglabelrec +LIBNAME = lpeglabel LUADIR = ../lua/ COPT = -O2 @@ -29,24 +29,24 @@ FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o # For Linux linux: - make lpeglabelrec.so "DLLFLAGS = -shared -fPIC" + make lpeglabel.so "DLLFLAGS = -shared -fPIC" # For Mac OS macosx: - make lpeglabelrec.so "DLLFLAGS = -bundle -undefined dynamic_lookup" + make lpeglabel.so "DLLFLAGS = -bundle -undefined dynamic_lookup" -lpeglabelrec.so: $(FILES) - env $(CC) $(DLLFLAGS) $(FILES) -o lpeglabelrec.so +lpeglabel.so: $(FILES) + env $(CC) $(DLLFLAGS) $(FILES) -o lpeglabel.so $(FILES): makefile -test: test.lua testlabel.lua testerrors.lua relabel.lua lpeglabelrec.so +test: test.lua testlabel.lua testerrors.lua relabel.lua lpeglabel.so lua test.lua lua testlabel.lua lua testerrors.lua clean: - rm -f $(FILES) lpeglabelrec.so + rm -f $(FILES) lpeglabel.so lpcap.o: lpcap.c lpcap.h lptypes.h diff --git a/relabel.lua b/relabel.lua index af1a440..cf76e89 100644 --- a/relabel.lua +++ b/relabel.lua @@ -6,7 +6,7 @@ local pcall = pcall local setmetatable = setmetatable local unpack, tinsert, concat = table.unpack or unpack, table.insert, table.concat local rep = string.rep -local m = require"lpeglabelrec" +local m = require"lpeglabel" -- 'm' will be used to parse expressions, and 'mm' will be used to -- create expressions; that is, 're' runs on 'm', creating patterns diff --git a/test.lua b/test.lua index 18ab20f..d5922ac 100755 --- a/test.lua +++ b/test.lua @@ -4,7 +4,7 @@ -- require"strict" -- just to be pedantic -local m = require"lpeglabelrec" +local m = require"lpeglabel" -- for general use @@ -1110,7 +1110,7 @@ checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) -- Tests for 're' module ------------------------------------------------------------------- -local re = require "relabelrec" +local re = require "relabel" local match, compile = re.match, re.compile diff --git a/testlabel.lua b/testlabel.lua index d9bac64..9fcdcfc 100644 --- a/testlabel.lua +++ b/testlabel.lua @@ -1,4 +1,4 @@ -local m = require 'lpeglabelrec' +local m = require 'lpeglabel' local p, r, l, s, serror @@ -363,7 +363,7 @@ assert(r == nil and l == 5 and serror == s) print("+") -local re = require 'relabelrec' +local re = require 'relabel' g = re.compile[['a' //{4,9} [a-z] ]] diff --git a/testrelabelparser.lua b/testrelabelparser.lua index 3f3ad41..5a43621 100644 --- a/testrelabelparser.lua +++ b/testrelabelparser.lua @@ -1,4 +1,4 @@ -local re = require 'relabelrec' +local re = require 'relabel' function testerror(repatt, msg) msg = msg:match("^%s*(.-)%s*$") -- trim