1st commit

This commit is contained in:
du3 2023-12-03 01:28:55 +01:00
commit 8682ec1c2e
5 changed files with 69 additions and 0 deletions

5
README.md Normal file
View File

@ -0,0 +1,5 @@
Cebolla
=======
WIP
Atm it's an awk file and a shell script, they transform a file with curly braces and extension .cepa (like **Allium cepa**) into a hopefully valid Nim file.

8
build.make Normal file
View File

@ -0,0 +1,8 @@
all: install
install:
cp cebolla.sh cebolla
chmod +x cebolla
cp cebolla cebolla.awk $(HOME)/bin
.PHONY: all install

43
cebolla.awk Normal file
View File

@ -0,0 +1,43 @@
BEGIN {
a[1] = ""
gap = ""
sep = " "
indentation_level = 0
skip_main = 0
i = 0
}
/{[ \t]*$/ {
skip_main = 1
if(indentation_level > 0) {
gsub(/^[ \t][ \t]*/, "")
for(i = 0; i < indentation_level; i++) {
$0 = sep $0
}
}
indentation_level++
gsub(/{[ \t]*$/, "")
}
/^[ \t]*}[ \t]*$/ {
indentation_level--
if(indentation_level < 0) {
indentation_level = 0
}
gsub(/^[ \t]*}[ \t]*$/, "")
}
{
if(skip_main) {
skip_main = 0
}
else {
if(indentation_level > 0) {
gsub(/^[ \t][ \t]*/, "")
for(i = 0; i < indentation_level; i++) {
$0 = sep $0
}
}
}
print
}

6
cebolla.sh Normal file
View File

@ -0,0 +1,6 @@
set -x
find . -type f | grep '\.cepa$' | {
while read f ; do
AWKPATH="$AWKPATH:$PATH" awk -f cebolla.awk <$(realpath $f) >$(realpath $f | sed 's/.cepa$/.nim/')
done
}

7
template.make Normal file
View File

@ -0,0 +1,7 @@
all: ceb file.nim
nim c -o:do file.nim
ceb:
cebolla
.PHONY: all ceb