|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/VisCapts1.lua.html
-- http://anggtwu.net/LUA/VisCapts1.lua
-- (find-angg "LUA/VisCapts1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/VisCapts1.lua"))
-- (find-LATEX "2024visualizing-captures.tex")
-- «.WPGramLine» (to "WPGramLine")
-- «.WPGramLine-tests» (to "WPGramLine-tests")
require "ELpeg1" -- (find-angg "LUA/ELpeg1.lua")
require "MapAST2" -- (find-angg "LUA/MapAST2.lua")
bigstr = [=[
<Stmt> -> <Id> = <Expr> ;
<Stmt> -> \T{\{} \; <StmtList> \; \T{\}}
<Stmt> -> \T{if} \; \T{(} \; <Expr> \; \T{)} \; <Stmt>
<StmtList> -> <Stmt>
<StmtList> -> <StmtList> <Stmt>
<Expr> -> <Id>
<Expr> -> <Num>
<Expr> -> <Expr> \; <Optr> \; <Expr>
<Id> -> \T{x}
<Id> -> \T{y}
<Num> -> \T{0}
<Num> -> \T{1}
<Num> -> \T{9}
<Optr> -> \T{>}
<Optr> -> \T{+}
]=]
-- __ ______ ____ _ _
-- \ \ / / _ \ / ___|_ __ __ _ _ __ ___ | | (_)_ __ ___
-- \ \ /\ / /| |_) | | _| '__/ _` | '_ ` _ \| | | | '_ \ / _ \
-- \ V V / | __/| |_| | | | (_| | | | | | | |___| | | | | __/
-- \_/\_/ |_| \____|_| \__,_|_| |_| |_|_____|_|_| |_|\___|
--
-- «WPGramLine» (to ".WPGramLine")
WPGramLine = Class {
type = "WPGramLine",
from = function (line)
local a,b = line:match("(.*)->(.*)")
a,b = bitrim(a),bitrim(b)
return WPGramLine {a,b}
end,
__tostring = function (wgl) return mytostring(wgl) end,
__index = {
L = function (wgl) return WPGram_parse(wgl[1]) end,
R = function (wgl) return WPGram_parse(wgl[2]) end,
LR = function (wgl) return mkast("GramLine", wgl:L(), wgl:R()) end,
},
}
gr,V,VA,VE,PE = Gram.new()
VA["<>"] = P"<" * ((1-S"<>")^1):C() * P">"
VA.Co = ((1-V["<>"])^1):C()
VA["."] = (V["<>"] + V.Co)^1
WPGram_gr = gr
WPGram_parse0 = WPGram_gr:compile(".")
WPGram_parse = function (s) return WPGram_parse0:match(s) end
fmts["GramLine"] = "<1> &\\to& <2> \\\\"
-- «WPGramLine-tests» (to ".WPGramLine-tests")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "VisCapts1.lua"
lines = splitlines(bigstr)
for _,li in ipairs(lines) do
local wgl = WPGramLine.from(li)
print(wgl)
end
wgl = WPGramLine.from(lines[1])
= wgl
= wgl:R()
= wgl:LR()
= wgl:LR():totex()
= totex(wgl:LR())
o = wgl:R()
= o
= o:totex()
= o:show {em=1}
* (etv)
--]==]
-- __ ______ ____
-- \ \ / / _ \ / ___|_ __ __ _ _ __ ___
-- \ \ /\ / /| |_) | | _| '__/ _` | '_ ` _ \
-- \ V V / | __/| |_| | | | (_| | | | | | |
-- \_/\_/ |_| \____|_| \__,_|_| |_| |_|
--
-- «.WPGram» (to "WPGram")
-- «WPGram» (to ".WPGram")
WPGram = Class {
type = "WPGram",
__index = {
},
}
-- «.WPGram-tests» (to "WPGram-tests")
-- «WPGram-tests» (to ".WPGram-tests")
-- (find-angg "LUA/ParseTikz1.lua")
-- (find-angg "LUA/MapAST2.lua" "totex")
-- (c2m231introp 5 "gramatica-fig")
-- (c2m231introa "gramatica-fig")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "VisCapts1.lua"
= gr:cm0("Ang", "<Foo>")
lines = splitlines(bigstr)
for _,li in ipairs(lines) do
local wgl = WPGramLine.from(li)
print(wgl)
end
for _,li in ipairs(lines) do
local a,b = li:match("(.*)->(.*)")
a,b = bitrim(a),bitrim(b)
-- print(li)
print(a,b)
end
--]]
-- Local Variables:
-- coding: utf-8-unix
-- End: