|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- parse.lua: functions to parse words keeping track of the column.
-- These functions are used to parse tree segments (in "%:" lines)
-- and 2D grids (in both "%D 2Dx" and "%D 2D" lines).
-- This file:
-- http://angg.twu.net/dednat5/parse.lua.html
-- http://angg.twu.net/dednat5/parse.lua
-- (find-dn5 "parse.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2011apr07
-- License: GPL3
--
setsubj = function (subj_, pos_)
subj = subj_
pos = pos_ or 3
startcol, endcol = 1, pos
end
getword = function ()
local spaces, word_, newpos = subj:match("( *)([^ ]+)()", pos)
if spaces then
startcol = endcol + #spaces
endcol = endcol + #spaces + #word_ -- change for UTF-8
word = word_
pos = newpos
return word
end
end
getwordasluaexpr = function ()
local expr = getword()
local code = "return "..expr
return assert(loadstring(code))()
end
getrestofline = function ()
local spaces, word_, newpos = subj:match("( *)(.*)()", pos)
if spaces then
startcol = endcol + #spaces
endcol = endcol + #spaces + #word_ -- change for UTF-8
word = word_
pos = newpos
return word
end
end
-- dump-to: tests
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "common.lua"
dofile "parse.lua"
run = function (str)
setsubj(str)
while getword() do PP(startcol, endcol, pos, word) end
end
run "%Dfoo bar plic"
--]==]
-- Local Variables:
-- coding: raw-text-unix
-- ee-anchor-format: "«%s»"
-- End: