Rename schemac compiler to preserves-schemac
This commit is contained in:
parent
b7224d7a4a
commit
60938612c5
|
@ -3,5 +3,5 @@ NIM_FLAGS += --path:$(TUP_CWD)/..
|
|||
: foreach preserves_schema_nim.nim schemaparse.nim |> !nim_bin |> $(BIN_DIR)/%B | $(BIN_DIR)/<%B>
|
||||
|
||||
DOT_FILES = ../../Document.dot ../../Schema.dot
|
||||
: schemac.nim |> !nim_bin |> $(BIN_DIR)/%B | $(DOT_FILES) $(BIN_DIR)/<%B>
|
||||
: preserves_schemac.nim |> !nim_bin |> $(BIN_DIR)/preserves-schemac | $(DOT_FILES) $(BIN_DIR)/<preserves-schemac>
|
||||
: foreach $(DOT_FILES) |> dot -Tsvg -LO %f > %o |> ../../%B-Grammer-Graph.svg
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[hashes, options, os, parseopt, streams, strutils, tables]
|
||||
|
||||
import ../preserves, ./schema, ./schemaparse
|
||||
|
||||
when isMainModule:
|
||||
let outStream = newFileStream(stdout)
|
||||
var
|
||||
inputPath = ""
|
||||
noBundle = false
|
||||
|
||||
for kind, key, arg in getopt():
|
||||
case kind
|
||||
of cmdEnd: discard
|
||||
of cmdArgument:
|
||||
if inputPath != "":
|
||||
quit "only a single path may specified"
|
||||
inputPath = key
|
||||
of cmdLongOption:
|
||||
if arg != "":
|
||||
quit("flag does not take an argument: " & key & " " & arg)
|
||||
case key
|
||||
of "no-bundle": noBundle = true
|
||||
else: quit(key & "flag not recognized")
|
||||
else: quit(key & "flag not recognized")
|
||||
|
||||
if inputPath == "":
|
||||
quit "input file(s) not specified"
|
||||
|
||||
if noBundle:
|
||||
if not fileExists inputPath:
|
||||
quit(inputPath & " does not exist or is not a file")
|
||||
var schema = parsePreservesSchema(readFile(inputPath))
|
||||
write(outStream, schema.toPreserve)
|
||||
|
||||
else:
|
||||
let bundle = Bundle()
|
||||
if not dirExists inputPath:
|
||||
quit "not a directory of schemas: " & inputPath
|
||||
else:
|
||||
for filePath in walkDirRec(inputPath, relative = true):
|
||||
var (dirPath, fileName, fileExt) = splitFile(filePath)
|
||||
if fileExt == ".prs":
|
||||
var
|
||||
scm = parsePreservesSchema(readFile(inputPath / filePath))
|
||||
path: ModulePath
|
||||
for e in split(dirPath, '/'):
|
||||
add(path, Symbol e)
|
||||
add(path, Symbol fileName)
|
||||
bundle.modules[path] = scm
|
||||
if bundle.modules.len == 0:
|
||||
quit "no schemas parsed"
|
||||
else:
|
||||
write(outStream, bundle.toPreserve)
|
||||
|
||||
close(outStream)
|
|
@ -1,47 +0,0 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[hashes, options, os, parseopt, streams, strutils, tables]
|
||||
|
||||
import ../preserves, ./schema, ./schemaparse
|
||||
|
||||
when isMainModule:
|
||||
let outStream = newFileStream(stdout)
|
||||
|
||||
for kind, key, inputPath in getopt():
|
||||
case kind
|
||||
of cmdEnd: discard
|
||||
of cmdArgument:
|
||||
quit "arguments must be prefixed by --schema: or --bundle:"
|
||||
of cmdLongOption:
|
||||
if inputPath == "":
|
||||
quit "long command line options require a path argument"
|
||||
case key
|
||||
|
||||
of "schema":
|
||||
var schema = parsePreservesSchema(readFile(inputPath))
|
||||
write(outStream, schema.toPreserve)
|
||||
|
||||
of "bundle":
|
||||
let bundle = Bundle()
|
||||
if not dirExists inputPath:
|
||||
quit "not a directory of schemas: " & inputPath
|
||||
else:
|
||||
for filePath in walkDirRec(inputPath, relative = true):
|
||||
var (dirPath, fileName, fileExt) = splitFile(filePath)
|
||||
if fileExt == ".prs":
|
||||
var
|
||||
scm = parsePreservesSchema(readFile(inputPath / filePath))
|
||||
path: ModulePath
|
||||
for e in split(dirPath, '/'):
|
||||
add(path, Symbol e)
|
||||
add(path, Symbol fileName)
|
||||
bundle.modules[path] = scm
|
||||
if bundle.modules.len == 0:
|
||||
quit "no schemas parsed"
|
||||
else:
|
||||
write(outStream, bundle.toPreserve)
|
||||
|
||||
else: quit("unhandled option " & key)
|
||||
else: quit("unhandled option " & key)
|
||||
close(outStream)
|
|
@ -1,3 +1,7 @@
|
|||
include_rules
|
||||
NIM_FLAGS_test_samples += -d:upstreamTestfile="$(TUP_CWD)/../../preserves/tests/samples.pr"
|
||||
: foreach t*.nim |> !nim_run |> | ../<test>
|
||||
|
||||
: $(BIN_DIR)/<preserves-schemac> \
|
||||
|> $(BIN_DIR)/preserves-schemac --no-bundle ../../preserves/doc/demo.prs | xxd > %o \
|
||||
|> demo.xxd
|
||||
|
|
Loading…
Reference in New Issue