diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index e7041de..97b170b 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -761,6 +761,10 @@ namespace util { return ret; } + OSTD_EXPORT ostd::ConstCharRange parse_word( + CsState &cs, ostd::ConstCharRange str + ); + struct ListParser { ostd::ConstCharRange input; ostd::ConstCharRange quote = ostd::ConstCharRange(); diff --git a/src/cs_gen.cc b/src/cs_gen.cc index f94055c..698d27b 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -174,50 +174,9 @@ void GenState::skip_comments() { } } -static ostd::ConstCharRange parseword(ostd::ConstCharRange p) { - for (;;) { - p = ostd::find_one_of(p, ostd::ConstCharRange("\"/;\\()[] \t\r\n")); - if (p.empty()) { - return p; - } - switch (*p) { - case '"': - case ';': - case '\\': - case ' ': - case '\t': - case '\r': - case '\n': - return p; - case '/': - if ((p.size() > 1) && (p[1] == '/')) { - return p; - } - break; - case '[': - p = parseword(p + 1); - if (p.empty() || (*p != ']')) { - return p; - } - break; - case '(': - p = parseword(p + 1); - if (p.empty() || (*p != ')')) { - return p; - } - break; - case ']': - case ')': - return p; - } - ++p; - } - return p; -} - ostd::ConstCharRange GenState::get_word() { auto beg = source; - source = parseword(source); + source = util::parse_word(cs, source); return ostd::slice_until(beg, source); } diff --git a/src/cs_util.cc b/src/cs_util.cc index 413d273..fdc9132 100644 --- a/src/cs_util.cc +++ b/src/cs_util.cc @@ -225,7 +225,9 @@ end: return str + 1; } - static ostd::ConstCharRange cs_parse_word(ostd::ConstCharRange str) { + OSTD_EXPORT ostd::ConstCharRange parse_word( + CsState &cs, ostd::ConstCharRange str + ) { for (;;) { str = ostd::find_one_of(str, ostd::ConstCharRange("\"/;()[] \t\r\n")); if (str.empty()) { @@ -245,15 +247,15 @@ end: } break; case '[': - str = cs_parse_word(str + 1); + str = parse_word(cs, str + 1); if (str.empty() || (*str != ']')) { - return str; + throw CsErrorException(cs, "missing \"]\""); } break; case '(': - str = cs_parse_word(str + 1); + str = parse_word(cs, str + 1); if (str.empty() || (*str != ')')) { - return str; + throw CsErrorException(cs, "missing \")\""); } break; case ']': @@ -345,7 +347,7 @@ endblock: case ']': return false; default: { - ostd::ConstCharRange e = cs_parse_word(input); + ostd::ConstCharRange e = parse_word(p_state, input); quote = item = ostd::slice_until(input, e); input = e; break;