for backwards compatibility, now a string literal is a sequence of any characters except space.

This commit is contained in:
Krasimir Angelov
2026-09-15 15:05:01 +02:00
parent d7b9d58039
commit e0fe461b3e
3 changed files with 34 additions and 7 deletions
+26 -3
View File
@@ -308,14 +308,13 @@ PgfType PgfInternalMarshaller::match_type(PgfUnmarshaller *u, PgfType ty)
PgfExprParser::PgfExprParser(PgfText *input, size_t byte_pos, PgfUnmarshaller *unmarshaller) PgfExprParser::PgfExprParser(PgfText *input, size_t byte_pos, PgfUnmarshaller *unmarshaller)
{ {
inp = input; inp = input;
pos = (const char*) &inp->text[byte_pos];
ch = ' ';
u = unmarshaller; u = unmarshaller;
token_pos = NULL; token_pos = NULL;
token_value = NULL; token_value = NULL;
bs = NULL; bs = NULL;
token(); reset_pos(byte_pos);
token();
} }
PgfExprParser::~PgfExprParser() PgfExprParser::~PgfExprParser()
@@ -433,6 +432,30 @@ bool PgfExprParser::str_char()
return getc(); return getc();
} }
void PgfExprParser::raw_token()
{
token_tag = PGF_TOKEN_STR;
token_pos = pos;
token_value = NULL;
while (pgf_utf8_is_space(ch)) {
token_pos = pos;
if (!getc()) {
token_tag = PGF_TOKEN_EOF;
return;
}
}
while (!pgf_utf8_is_space(ch)) {
putc(ch);
if (!getc())
break;
}
if (token_value == NULL)
token_tag = PGF_TOKEN_EOF;
}
void PgfExprParser::token() void PgfExprParser::token()
{ {
if (token_value != NULL) if (token_value != NULL)
+2 -1
View File
@@ -175,6 +175,7 @@ public:
bool str_char(); bool str_char();
void token(); void token();
void raw_token();
bool lookahead(int ch); bool lookahead(int ch);
bool parse_bind(); bool parse_bind();
@@ -195,7 +196,7 @@ public:
bool is_str() { return (token_tag == PGF_TOKEN_STR); } bool is_str() { return (token_tag == PGF_TOKEN_STR); }
bool is_ident() { return (token_tag == PGF_TOKEN_IDENT); } bool is_ident() { return (token_tag == PGF_TOKEN_IDENT); }
void ident2str() { token_tag = PGF_TOKEN_STR; } void reset_pos(size_t pos) { this->pos = &inp->text[pos]; this->ch = ' '; }
const PgfText *get_token_value() { return token_value; } const PgfText *get_token_value() { return token_value; }
const char *get_token_pos() { return token_pos; } const char *get_token_pos() { return token_pos; }
+6 -3
View File
@@ -1576,9 +1576,12 @@ void PgfParser::suspend(Cont *cont,Item *item,bool do_predict,ref<PgfSymbolCat>
bu_literal(cont->state, "Int", &eparser, viterbi_prob); bu_literal(cont->state, "Int", &eparser, viterbi_prob);
} else if (eparser.is_flt()) { } else if (eparser.is_flt()) {
bu_literal(cont->state, "Float", &eparser, viterbi_prob); bu_literal(cont->state, "Float", &eparser, viterbi_prob);
} else if (eparser.is_ident()) { } else {
eparser.ident2str(); eparser.reset_pos(cont->state->end.byte_pos);
bu_literal(cont->state, "String", &eparser, viterbi_prob); eparser.raw_token();
if (eparser.is_str()) {
bu_literal(cont->state, "String", &eparser, viterbi_prob);
}
} }
bu_predict(concr->phrasetable1, cont->state, viterbi_prob, 1, sentence->size); bu_predict(concr->phrasetable1, cont->state, viterbi_prob, 1, sentence->size);
} }