Skip to content

Commit

Permalink
unm factorizing + typo
Browse files Browse the repository at this point in the history
  • Loading branch information
pygy committed Jun 12, 2013
1 parent f2a7483 commit 5e47388
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ABOUT
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ LuLPeg, a pure Lua port of LPeg, Roberto Ierusalimschy's
Parsing Expression Grammars library.

Copyright (C) Pierre-Yves Gerardy.
Released under the Romantif WTF Public License (cf. the LICENSE
Released under the Romantic WTF Public License (cf. the LICENSE
file or the end of this file, whichever is present).

See http://www.inf.puc-rio.br/~roberto/lpeg/ for the original.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ LuaJIT in with the JIT compiler turned off is ~50 times slower than LPeg.
## License:

Copyright (C) Pierre-Yves Gerardy.
Released under the Romantif WTF Public License.
Released under the Romantic WTF Public License.

The re.lua module and the test suite (tests/lpeg.*.*.tests.lua) are part of the original LPeg distribution, released under the MIT license.

Expand Down
21 changes: 8 additions & 13 deletions lulpeg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Parsing Expression Grammars library.
--
-- Copyright (C) Pierre-Yves Gerardy.
-- Released under the Romantif WTF Public License (cf. the LICENSE
-- Released under the Romantic WTF Public License (cf. the LICENSE
-- file or the end of this file, whichever is present).
--
-- See http://www.inf.puc-rio.br/~roberto/lpeg/ for the original.
Expand Down Expand Up @@ -1753,12 +1753,11 @@ function sequence(a, b, ...)
end
local
function unm (pt)
if pt == truept then return falsept, true
elseif pt == falsept then return truept, true
elseif pt.ptype == "unm" then return #pt.pattern, true
elseif pt.ptype == "lookahead" then pt = pt.pattern
if pt == truept then return falsept
elseif pt == falsept then return truept
elseif pt.ptype == "unm" then return #pt.pattern
elseif pt.ptype == "lookahead" then return -pt.pattern
end
return pt
end
return {
choice = choice,
Expand Down Expand Up @@ -2371,13 +2370,9 @@ LL.__len = LL_lookahead
LL.L = LL_lookahead
local
function LL_unm(pt)
local as_is
pt, as_is = factorize_unm(pt)
if as_is
then return pt
else
return
constructors.subpt("unm", pt) end
return
factorize_unm(pt)
or constructors.subpt("unm", pt)
end
LL.__unm = LL_unm
local
Expand Down
12 changes: 4 additions & 8 deletions src/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,10 @@ LL.L = LL_lookahead
local
function LL_unm(pt)
-- Simplifications
local as_is
pt, as_is = factorize_unm(pt)
if as_is
then return pt
else
return
--[[DBG]] true and
constructors.subpt("unm", pt) end
return
--[[DBG]] true and
factorize_unm(pt)
or constructors.subpt("unm", pt)
end
LL.__unm = LL_unm

Expand Down
9 changes: 4 additions & 5 deletions src/factorizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ end
local
function unm (pt)
-- [[DP]] print("Factorize Unm")
if pt == truept then return falsept, true
elseif pt == falsept then return truept, true
elseif pt.ptype == "unm" then return #pt.pattern, true
elseif pt.ptype == "lookahead" then pt = pt.pattern
if pt == truept then return falsept
elseif pt == falsept then return truept
elseif pt.ptype == "unm" then return #pt.pattern
elseif pt.ptype == "lookahead" then return -pt.pattern
end
return pt
end

return {
Expand Down

0 comments on commit 5e47388

Please sign in to comment.