expose word parsing into API and unify with parser
parent
9995fcf2e1
commit
cd515a4cff
|
@ -761,6 +761,10 @@ namespace util {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSTD_EXPORT ostd::ConstCharRange parse_word(
|
||||||
|
CsState &cs, ostd::ConstCharRange str
|
||||||
|
);
|
||||||
|
|
||||||
struct ListParser {
|
struct ListParser {
|
||||||
ostd::ConstCharRange input;
|
ostd::ConstCharRange input;
|
||||||
ostd::ConstCharRange quote = ostd::ConstCharRange();
|
ostd::ConstCharRange quote = ostd::ConstCharRange();
|
||||||
|
|
|
@ -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() {
|
ostd::ConstCharRange GenState::get_word() {
|
||||||
auto beg = source;
|
auto beg = source;
|
||||||
source = parseword(source);
|
source = util::parse_word(cs, source);
|
||||||
return ostd::slice_until(beg, source);
|
return ostd::slice_until(beg, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,9 @@ end:
|
||||||
return str + 1;
|
return str + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ostd::ConstCharRange cs_parse_word(ostd::ConstCharRange str) {
|
OSTD_EXPORT ostd::ConstCharRange parse_word(
|
||||||
|
CsState &cs, ostd::ConstCharRange str
|
||||||
|
) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
str = ostd::find_one_of(str, ostd::ConstCharRange("\"/;()[] \t\r\n"));
|
str = ostd::find_one_of(str, ostd::ConstCharRange("\"/;()[] \t\r\n"));
|
||||||
if (str.empty()) {
|
if (str.empty()) {
|
||||||
|
@ -245,15 +247,15 @@ end:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '[':
|
case '[':
|
||||||
str = cs_parse_word(str + 1);
|
str = parse_word(cs, str + 1);
|
||||||
if (str.empty() || (*str != ']')) {
|
if (str.empty() || (*str != ']')) {
|
||||||
return str;
|
throw CsErrorException(cs, "missing \"]\"");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '(':
|
case '(':
|
||||||
str = cs_parse_word(str + 1);
|
str = parse_word(cs, str + 1);
|
||||||
if (str.empty() || (*str != ')')) {
|
if (str.empty() || (*str != ')')) {
|
||||||
return str;
|
throw CsErrorException(cs, "missing \")\"");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
|
@ -345,7 +347,7 @@ endblock:
|
||||||
case ']':
|
case ']':
|
||||||
return false;
|
return false;
|
||||||
default: {
|
default: {
|
||||||
ostd::ConstCharRange e = cs_parse_word(input);
|
ostd::ConstCharRange e = parse_word(p_state, input);
|
||||||
quote = item = ostd::slice_until(input, e);
|
quote = item = ostd::slice_until(input, e);
|
||||||
input = e;
|
input = e;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue