Replace the terrible code generation shell script with a Lua script.

This commit is contained in:
David Given 2022-07-17 18:15:09 +02:00
parent 90c6f0274a
commit 2558d00d17
3 changed files with 28 additions and 28 deletions

View file

@ -13,14 +13,12 @@ local cgglexer = flex {
normalrule { normalrule {
name = "keywords", name = "keywords",
ins = { ins = {
"./cvtkeywords", "./make_enterkeyw_c.lua",
"util/cmisc+ed",
"./keywords", "./keywords",
matching(filenamesof(cggparser), "%.h$")
}, },
outleaves = { "enterkeyw.c" }, outleaves = { "enterkeyw.c" },
commands = { commands = {
"%{ins[1]} %{ins[2]} %{ins[3]} %{ins[4]} %{outs[1]}" "$LUA %{ins[1]} < %{ins[2]} > %{outs[1]}"
} }
} }

View file

@ -1,24 +0,0 @@
#!/bin/sh
: '$Id$'
grep '^#' $3 >tokendefs
$1 -s $2 > $4 <<'!Funky!Stuff!'
g/^#/d
1,$s/\([^ ]*\)[ ][ ]*\(.*\)/ sy_p=lookup("\1",symkeyw,newsymbol);sy_p->sy_value.syv_keywno=\2;/
1i
#include "lookup.h"
.
.r tokendefs
a
void enterkeyw(void) {
register symbol *sy_p;
.
$a
}
.
1,$p
!Funky!Stuff!
rm tokendefs

26
util/ncgg/make_enterkeyw_c.lua Executable file
View file

@ -0,0 +1,26 @@
print([[
#include "param.h"
#include "lookup.h"
#include "varinfo.h"
#include "instruct.h"
#include "set.h"
#include "expr.h"
#include "iocc.h"
#include "y.tab.h"
void enterkeyw(void) {
]])
for line in io.stdin:lines() do
if not line:find("^#") then
local _, _, w1, w2 = line:find("^(%g+)%s+(%g+)$")
print(string.format([[
lookup("%s", symkeyw, newsymbol)->sy_value.syv_keywno = %s;
]], w1, w2))
end
end
print([[
}
]])