hare

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

commit 960455a3f11cf04e3d34c49908621dd36c7b53e1
parent 8b04a59d462176062e60775703f4d17161d918c8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  3 Apr 2021 09:43:19 -0400

hare::module: flesh out ambiguous inputs algorithm

Diffstat:
Mhare/module/scan.ha | 6++++--
Mhare/module/types.ha | 27+++++++++++++++++++++------
2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -152,8 +152,6 @@ fn scan_directory( // as the build input and the other two files are discarded. // // TODO: Improve the documentation which describes this algorithm - // TODO: Loosen requirements for empty basename, and make non-empty - // basename conflict on an equal number of tags for (let i = 0z; i < len(dirs); i += 1) { let name = dirs[i]; @@ -189,6 +187,8 @@ fn scan_directory( // They are more specific superceeded = true; break; + } else if (len(base) != 0) { + return (path, inputs[j].3): ambiguous; }; }; if (!superceeded) { @@ -234,6 +234,8 @@ fn scan_directory( // They are more specific superceeded = true; break; + } else if (len(base) != 0) { + return (path, inputs[j].3): ambiguous; }; }; if (!superceeded) { diff --git a/hare/module/types.ha b/hare/module/types.ha @@ -2,6 +2,7 @@ use fs; use hare::ast; use hare::parse; use io; +use fmt; // The inclusive/exclusive state for a build tag. export type tag_mode = enum { @@ -52,12 +53,26 @@ export type input = struct { // The requested module could not be found. export type module_not_found = void!; +// We are unable to select from two ambiguous options for an input file. +export type ambiguous = (str, str)!; + // All possible error types. -export type error = (fs::error | io::error | parse::error | module_not_found)!; +export type error = ( + fs::error | + io::error | + parse::error | + module_not_found | + ambiguous)!; -export fn errstr(err: error) const str = match (err) { - err: fs::error => fs::errstr(err), - err: io::error => io::errstr(err), - err: parse::error => parse::errstr(err), - module_not_found => "Module not found", +export fn errstr(err: error) const str = { + // Should be more than enough for PATH_MAX * 2 + static let buf: [4096]u8 = [0...]; + return match (err) { + err: fs::error => fs::errstr(err), + err: io::error => io::errstr(err), + err: parse::error => parse::errstr(err), + module_not_found => "Module not found", + amb: ambiguous => fmt::bsprintf(buf, + "Cannot choose between {} and {}", amb.0, amb.1), + }; };