diff options
| author | gingerBill <bill@gingerbill.org> | 2018-05-28 21:25:08 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-05-28 21:25:08 +0100 |
| commit | ccbb6df7494a250466be3fcb8455f25eb1e79ef5 (patch) | |
| tree | 0127ef7980b1063fe49ef02035d8a69e54c1e1b9 /src/parser.cpp | |
| parent | 6eb505a6774ef1a801cd24e9adc75f1de738ca6e (diff) | |
Handle multiple +build package tags with '!' (nots)
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 92 |
1 files changed, 55 insertions, 37 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 5331302a6..697ccb2ec 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4217,6 +4217,22 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod } } +String build_tag_get_token(String s, String *out) { + s = string_trim_whitespace(s); + isize n = 0; + while (n < s.len) { + Rune rune = 0; + isize width = gb_utf8_decode(&s[n], s.len-n, &rune); + if (rune_is_whitespace(rune)) { + *out = substring(s, n+width, s.len); + return substring(s, 0, n); + } + n += width; + } + out->len = 0; + return s; +} + bool parse_build_tag(Token token_for_pos, String s) { String const prefix = str_lit("+build"); GB_ASSERT(string_starts_with(s, prefix)); @@ -4226,49 +4242,51 @@ bool parse_build_tag(Token token_for_pos, String s) { return true; } - auto platforms = array_make<String>(heap_allocator()); - defer (array_free(&platforms)); + bool any_correct = false; - isize n = 0; - while (n < s.len) { - Rune rune = 0; - isize width = gb_utf8_decode(&s[n], s.len, &rune); - if (rune_is_whitespace(rune)) { - String f = substring(s, 0, n); - array_add(&platforms, f); - s = substring(s, n+width, s.len); - n = 0; - continue; - } else if (n+width == s.len) { - String f = substring(s, 0, n+width); - array_add(&platforms, f); - break; + do { + String p = build_tag_get_token(s, &s); + if (p.len == 0) break; + bool is_notted = false; + if (p[0] == '!') { + is_notted = true; + p = substring(p, 1, p.len); + if (p.len == 0) { + error(token_for_pos, "Expected a build platform after '!'"); + break; + } } - n += width; - } - - bool any_correct = false; - for_array(i, platforms) { - String p = platforms[i]; - TargetOsKind os = get_target_os_from_string(p); - TargetArchKind arch = get_target_arch_from_string(p); - if (os != TargetOs_Invalid) { - GB_ASSERT(arch == TargetArch_Invalid); - any_correct = true; - if (os == build_context.target_os) { - return true; + if (p.len > 0) { + TargetOsKind os = get_target_os_from_string(p); + TargetArchKind arch = get_target_arch_from_string(p); + if (os != TargetOs_Invalid) { + GB_ASSERT(arch == TargetArch_Invalid); + any_correct = true; + if (is_notted) { + if (os != build_context.target_os) { + return true; + } + } else if (os == build_context.target_os) { + return true; + } + } else if (arch != TargetArch_Invalid) { + any_correct = true; + if (is_notted) { + if (arch != build_context.target_arch) { + return true; + } + } else if (arch == build_context.target_arch) { + return true; + } } - } else if (arch != TargetArch_Invalid) { - any_correct = true; - if (arch == build_context.target_arch) { - return true; + if (os == TargetOs_Invalid && arch == TargetArch_Invalid) { + error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p)); + break; } } - if (os == TargetOs_Invalid && arch == TargetArch_Invalid) { - error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p)); - } - } + } while (s.len > 0); + if (any_correct) { return false; } |