diff options
author | Alexey Yerin <yyp@disroot.org> | 2024-04-01 21:34:51 +0300 |
---|---|---|
committer | Alexey Yerin <yyp@disroot.org> | 2024-04-01 21:35:25 +0300 |
commit | 5b7571b7d91deef34ef92c8d9cf897320d3c8fab (patch) | |
tree | 4084b9717a2c79fd4ae98e9474e412e0fd43ba2b | |
parent | 49ae43171514e882c795166014edf94da0125033 (diff) |
Update per for-each changes
-rw-r--r-- | cmd/hare-gi/ident.ha | 30 | ||||
-rw-r--r-- | format/fastxml/parser.ha | 76 |
2 files changed, 49 insertions, 57 deletions
diff --git a/cmd/hare-gi/ident.ha b/cmd/hare-gi/ident.ha index 7dae645..65571f4 100644 --- a/cmd/hare-gi/ident.ha +++ b/cmd/hare-gi/ident.ha @@ -6,10 +6,10 @@ use strings; const keywords: [_]str = [ "abort", "align", "alloc", "append", "as", "assert", "bool", "break", - "case", "const", "continue", "defer", "def", "delete", "else", "enum", - "export", "f32", "f64", "false", "fn", "for", "free", "i16", "i32", - "i64", "i8", "if", "insert", "int", "is", "len", "let", "match", "null", - "nullable", "offset", "return", "rune", "size", "static", "str", + "case", "const", "continue", "def", "defer", "delete", "done", "else", + "enum", "export", "f32", "f64", "false", "fn", "for", "free", "i16", + "i32", "i64", "i8", "if", "insert", "int", "is", "len", "let", "match", + "null", "nullable", "offset", "return", "rune", "size", "static", "str", "struct", "switch", "true", "type", "u16", "u32", "u64", "u8", "uint", "uintptr", "union", "use", "vaarg", "vaend", "valist", "vastart", "void", "yield", @@ -27,8 +27,8 @@ fn fix_identifier(s: str) str = { return fmt::bsprintf(buf, "_{}", s); }; - for (let i = 0z; i < len(keywords); i += 1) { - if (keywords[i] == s) { + for (let keyword .. keywords) { + if (s == keyword) { return fmt::bsprintf(buf, "{}_", s); }; }; @@ -42,11 +42,8 @@ fn normalize_signal(in: str) str = { let buf = memio::fixed(buf); let iter = strings::iter(in); - for (true) match (strings::next(&iter)) { - case let r: rune => + for (let r => strings::next(&iter)) { memio::appendrune(&buf, if (r == '-') '_' else r)!; - case => - break; }; return memio::string(&buf)!; }; @@ -57,11 +54,8 @@ fn to_uppercase(in: str) str = { let buf = memio::fixed(buf); let iter = strings::iter(in); - for (true) match (strings::next(&iter)) { - case let r: rune => + for (let r => strings::next(&iter)) { memio::appendrune(&buf, ascii::toupper(r))!; - case => - break; }; return memio::string(&buf)!; }; @@ -76,8 +70,7 @@ fn swap_case(in: str) str = { let iter = strings::iter(in); let prev = '!'; - for (true) match (strings::next(&iter)) { - case let r: rune => + for (let r => strings::next(&iter)) { if (ascii::isupper(r) && !ascii::isupper(prev)) { if (len(memio::string(&buf)!) > 0) { append(parts, @@ -87,8 +80,6 @@ fn swap_case(in: str) str = { }; memio::appendrune(&buf, ascii::tolower(r))!; prev = r; - case void => - break; }; if (len(memio::string(&buf)!) > 0) { @@ -106,8 +97,7 @@ fn swap_case(in: str) str = { ("DBus", "dbus"), ("cairo_t", "cairo_t"), ]; - for (let i = 0z; i < len(tests); i += 1) { - const (in, expected) = tests[i]; + for (let (in, expected) .. tests) { const out = swap_case(in); if (out != expected) { fmt::fatalf("Fail '{}': expected '{}', got '{}'", diff --git a/format/fastxml/parser.ha b/format/fastxml/parser.ha index 8f7705a..f970ac5 100644 --- a/format/fastxml/parser.ha +++ b/format/fastxml/parser.ha @@ -518,48 +518,50 @@ fn quote(par: *parser) (rune | error) = { }; }; -fn want(par: *parser, tok: (rune | str | whitespace)...) (bool | error) = { +fn want(par: *parser, tokens: (rune | str | whitespace)...) (bool | error) = { let hadws = false; - for (let i = 0z; i < len(tok); i += 1) match (tok[i]) { - case let x: rune => - let have = match (scanrune(par)?) { - case io::EOF => - return par.line: syntaxerr; - case let rn: rune => - yield rn; - }; - if (have != x) { - return par.line: syntaxerr; - }; - if (x == '\n') { - par.line += 1; - }; - case let x: str => - let iter = strings::iter(x); - for (true) match (strings::next(&iter)) { - case let rn: rune => - want(par, rn)?; - case void => - break; - }; - case let ws: whitespace => - let n = 0; - for (true; n += 1) match (scanrune(par)?) { - case io::EOF => - break; - case let rn: rune => - if (!ascii::isspace(rn)) { - unreadrune(par, rn); - break; + for (let tok .. tokens) { + match (tok) { + case let x: rune => + let have = match (scanrune(par)?) { + case io::EOF => + return par.line: syntaxerr; + case let rn: rune => + yield rn; }; - if (rn == '\n') { + if (have != x) { + return par.line: syntaxerr; + }; + if (x == '\n') { par.line += 1; }; + case let x: str => + let iter = strings::iter(x); + for (true) match (strings::next(&iter)) { + case let rn: rune => + want(par, rn)?; + case done => + break; + }; + case let ws: whitespace => + let n = 0; + for (true; n += 1) match (scanrune(par)?) { + case io::EOF => + break; + case let rn: rune => + if (!ascii::isspace(rn)) { + unreadrune(par, rn); + break; + }; + if (rn == '\n') { + par.line += 1; + }; + }; + if (ws && n < 1) { + return par.line: syntaxerr; + }; + hadws = n >= 1; }; - if (ws && n < 1) { - return par.line: syntaxerr; - }; - hadws = n >= 1; }; return hadws; }; |