hare

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

commit 8d5ba0f61391a8ac1edf46302ac798e0f89f102d
parent 245815c694a4fde576c62367e22c3a5ae18374b0
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  7 Mar 2021 11:23:09 -0500

hare::module: move parse_tags out of types.ha

Diffstat:
Mhare/module/scan.ha | 45+++++++++++++++++++++++++++++++++++++++++++++
Mhare/module/types.ha | 46----------------------------------------------
2 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -1,3 +1,4 @@ +use ascii; use bytes; use crypto::sha256; use encoding::utf8; @@ -10,6 +11,7 @@ use io; use path; use slice; use strings; +use strio; // Scans the files in a directory for eligible build inputs and returns a // [version] which includes all applicable files and their dependencies. @@ -173,3 +175,46 @@ fn have_ident(sl: *[]ast::ident, id: ast::ident) bool = { }; return false; }; + +// Parses a set of build tags, returning void if the string is an invalid tag +// set. The caller must free the return value with [tags_free]. +export fn parse_tags(in: str) ([]tag | void) = { + let tags: []tag = []; + // defer! tags_free(tags); + let iter = strings::iter(in); + for (true) { + let t = tag { ... }; + let m = match (strings::next(&iter)) { + void => break, + r: rune => r, + }; + t.mode = switch (m) { + * => return, + '+' => tag_mode::INCLUSIVE, + '-' => tag_mode::EXCLUSIVE, + }; + let buf = strio::dynamic(); + for (true) match (strings::next(&iter)) { + void => break, + r: rune => { + if (ascii::isalnum(r) || r == '_') { + strio::append_rune(buf, r); + } else { + strings::push(&iter, r); + break; + }; + }, + }; + t.name = strio::finish(buf); + append(tags, t); + }; + return tags; +}; + +// Frees a set of tags. +export fn tags_free(tags: []tag) void = { + for (let i = 0z; i < len(tags); i += 1) { + free(tags[i].name); + }; + free(tags); +}; diff --git a/hare/module/types.ha b/hare/module/types.ha @@ -1,11 +1,8 @@ -use ascii; use fs; use hare::ast; use hare::parse; use io; use path; -use strings; -use strio; // The inclusive/exclusive state for a build tag. export type tag_mode = enum { @@ -19,49 +16,6 @@ export type tag = struct { mode: tag_mode, }; -// Parses a set of build tags, returning void if the string is an invalid tag -// set. The caller must free the return value with [tags_free]. -export fn parse_tags(in: str) ([]tag | void) = { - let tags: []tag = []; - // defer! tags_free(tags); - let iter = strings::iter(in); - for (true) { - let t = tag { ... }; - let m = match (strings::next(&iter)) { - void => break, - r: rune => r, - }; - t.mode = switch (m) { - * => return, - '+' => tag_mode::INCLUSIVE, - '-' => tag_mode::EXCLUSIVE, - }; - let buf = strio::dynamic(); - for (true) match (strings::next(&iter)) { - void => break, - r: rune => { - if (ascii::isalnum(r) || r == '_') { - strio::append_rune(buf, r); - } else { - strings::push(&iter, r); - break; - }; - }, - }; - t.name = strio::finish(buf); - append(tags, t); - }; - return tags; -}; - -// Frees a set of tags. -export fn tags_free(tags: []tag) void = { - for (let i = 0z; i < len(tags); i += 1) { - free(tags[i].name); - }; - free(tags); -}; - // The manifest for a particular module, with some number of inputs, and // versions. export type manifest = struct {