Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a meta-language for formal definitions #69

Merged
merged 12 commits into from
Jan 27, 2025
3 changes: 3 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ jobs:
- name: Build koch
run: nim c -d:nimStrictMode --outdir:bin koch.nim

- name: Build language definitions
run: bin/koch build-defs

- name: Build passtool
run: bin/koch single passtool -d:nimStrictMode -d:release

Expand Down
25 changes: 25 additions & 0 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Commands:
all [args] builds all programs
single <name> [args] builds the single program with the given name
generate [dir] generates the various language-related modules
build-defs verifies the language definitions and generates
the textual representation for them
"""
Programs: seq[(string, string, bool, bool)] = @[
("tester", "tools/tester.nim", true, true),
Expand Down Expand Up @@ -56,6 +58,13 @@ proc compile(file: sink string, name: string, extra: varargs[string]): bool =
args.add file
result = run(nimExe, args)

proc check(file: sink string, extra: varargs[string]): bool =
## Runs the ``check`` command on the given NimSkull `file`.
var args = @["check"]
args.add extra
args.add file
result = run(nimExe, args)

proc saneSplit(s: string): seq[string] =
## Compared to the normal split, returns an empty sequence for an empty
## string.
Expand Down Expand Up @@ -155,6 +164,20 @@ proc generate(args: string): bool =

result = true

proc buildDefs(args: string): bool =
## Handles verifying the language definitions and producing the artifacts
## based on them.
if args.len > 0:
return false

# there's nothing to do with the compiled language definition, making sure
# the macro succeeds is enough
if not check(getCurrentDir() / "languages" / "source.nim"):
echo "Failure"
quit(1)

result = true

proc showHelp(): bool =
## Shows the help text.
echo HelpText
Expand Down Expand Up @@ -184,6 +207,8 @@ while true:
buildSingle(opts.cmdLineRest)
of "generate":
generate(opts.cmdLineRest)
of "build-defs":
buildDefs(opts.cmdLineRest)
of "help":
showHelp()
else:
Expand Down
1 change: 1 addition & 0 deletions languages/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--path:".."
Loading
Loading