hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 6a2249c88d8fcb69750199058ccf729bea95bf2d
parent d72e9af96adc1f9d8ba66e59c08f58b80591830d
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sun,  5 Jun 2022 00:19:46 -0400

haredoc: add -T and -X flags

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
MMakefile | 1+
Mcmd/haredoc/env.ha | 40+++++++++++++++++++++++++++++++++++++++-
Mcmd/haredoc/main.ha | 24++++++++++++++++++++----
3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -80,6 +80,7 @@ $(BINOUT)/haredoc: $(BINOUT)/hare $(haredoc_srcs) @mkdir -p $(BINOUT) @printf 'HARE\t%s\n' "$@" @env HAREPATH=. HAREC=$(HAREC) QBE=$(QBE) $(BINOUT)/hare build \ + -D PLATFORM:str='"'"$(PLATFORM)"'"' \ -D HAREPATH:str='"'"$(HAREPATH)"'"' \ -o $(BINOUT)/haredoc ./cmd/haredoc diff --git a/cmd/haredoc/env.ha b/cmd/haredoc/env.ha @@ -6,11 +6,13 @@ use os::exec; use os; use strings; +def PLATFORM: str = "unknown"; + fn default_tags() []module::tag = { // TODO: Once os::exec can handle pipes, we should read the default tags // from $(hare version). return alloc([module::tag { - name = strings::dup("linux"), + name = strings::dup(PLATFORM), mode = module::tag_mode::INCLUSIVE, }, module::tag { name = strings::dup(os::machine()), @@ -18,6 +20,42 @@ fn default_tags() []module::tag = { }]); }; +fn addtags(tags: []module::tag, in: str) ([]module::tag | void) = { + let in = match (module::parsetags(in)) { + case void => + return void; + case let t: []module::tag => + yield t; + }; + defer free(in); + append(tags, in...); + return tags; +}; + +fn deltags(tags: []module::tag, in: str) ([]module::tag | void) = { + if (in == "^") { + module::tags_free(tags); + return []; + }; + let in = match (module::parsetags(in)) { + case void => + return void; + case let t: []module::tag => + yield t; + }; + defer free(in); + for (let i = 0z; i < len(tags); i += 1) { + for (let j = 0z; j < len(in); j += 1) { + if (tags[i].name == in[j].name + && tags[i].mode == in[j].mode) { + free(tags[i].name); + i -= 1; + }; + }; + }; + return tags; +}; + fn default_harepath() str = { return HAREPATH; }; diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -48,11 +48,16 @@ export fn main() void = { }; let template = true; let show_undocumented = false; + let tags = default_tags(); + defer module::tags_free(tags); + const help: [_]getopt::help = [ "reads and formats Hare documentation", ('F', "format", "specify output format (hare, tty, html, or gemtext)"), - ('t', "disable HTML template (requires postprocessing)"), + ('T', "tags...", "set build tags"), + ('X', "tags...", "unset build tags"), ('a', "show undocumented members (only applies to -Fhare and -Ftty)"), + ('t', "disable HTML template (requires postprocessing)"), "[identifiers...]", ]; const cmd = getopt::parse(os::args, help...); @@ -74,6 +79,20 @@ export fn main() void = { case => fmt::fatal("Invalid format", opt.1); }; + case 'T' => + tags = match (addtags(tags, opt.1)) { + case void => + fmt::fatal("Error parsing tags"); + case let t: []module::tag => + yield t; + }; + case 'X' => + tags = match (deltags(tags, opt.1)) { + case void => + fmt::fatal("Error parsing tags"); + case let t: []module::tag => + yield t; + }; case 't' => template = false; case 'a' => @@ -91,9 +110,6 @@ export fn main() void = { let decls: []ast::decl = []; defer free(decls); - let tags = default_tags(); - defer module::tags_free(tags); - let ctx = module::context_init(tags, [], default_harepath()); defer module::context_finish(&ctx);