[PATCH hare-scfg] add nomem to errors
Export this patch
---
cmd/demo/main.ha | 4 ++--
format/scfg/scan.ha | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/cmd/demo/main.ha b/cmd/demo/main.ha
index cd6d705..b8a1129 100644
--- a/cmd/demo/main.ha
+++ b/cmd/demo/main.ha
@@ -10,7 +10,7 @@ use strings;
export type invalid_block = !void;
export type invalid_name = !void;
export type unexpected = !void;
-export type error = !(invalid_block | invalid_name | unexpected | scfg::error);
+export type error = !(invalid_block | invalid_name | unexpected | scfg::error | nomem);
export type model = struct {
name: str,
@@ -119,7 +119,7 @@ fn parse_block(a: *app, d: scfg::directive) (void | error) = {
name = strings::dup(d.2[0]),
...
};
- append(a.train.models, m);
+ append(a.train.models, m)?;
a.model_index += 1;
case =>
return invalid_name;
diff --git a/format/scfg/scan.ha b/format/scfg/scan.ha
index 48f6a0a..17b55ff 100644
--- a/format/scfg/scan.ha
+++ b/format/scfg/scan.ha
@@ -42,7 +42,7 @@ export fn directive_finish(d: directive) void = {
// Returns the next directive from a scfg file. The return value is borrowed
// from the [[scanner]]. Use [[directive_dup]] to retain a copy.
-export fn next(sc: *scanner) (directive | done | error) = {
+export fn next(sc: *scanner) (directive | done | error | nomem) = {
for(const line => bufio::scan_line(&sc.scan)?) {
defer sc.lineno += 1;
@@ -87,11 +87,7 @@ export fn next(sc: *scanner) (directive | done | error) = {
continue;
};
- append(sc.params, strings::dup(v));
- };
-
- defer if (has_child) {
- append(sc.blocks, strings::dup(sc.name));
+ append(sc.params, strings::dup(v))?;
};
const l_blocks = len(sc.blocks);
@@ -101,6 +97,10 @@ export fn next(sc: *scanner) (directive | done | error) = {
yield sc.blocks[l_blocks - 1];
};
+ if (has_child) {
+ append(sc.blocks, strings::dup(sc.name))?;
+ };
+
return (
block,
sc.name,
--
2.48.0