From e0fe461b3e7e85165a9188d6f92e59f66a93b82f Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Tue, 15 Sep 2026 15:05:01 +0200 Subject: [PATCH] for backwards compatibility, now a string literal is a sequence of any characters except space. --- src/runtime/c/pgf/expr.cxx | 29 ++++++++++++++++++++++++++--- src/runtime/c/pgf/expr.h | 3 ++- src/runtime/c/pgf/parser.cxx | 9 ++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index 67d7e866e..107386283 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -308,14 +308,13 @@ PgfType PgfInternalMarshaller::match_type(PgfUnmarshaller *u, PgfType ty) PgfExprParser::PgfExprParser(PgfText *input, size_t byte_pos, PgfUnmarshaller *unmarshaller) { inp = input; - pos = (const char*) &inp->text[byte_pos]; - ch = ' '; u = unmarshaller; token_pos = NULL; token_value = NULL; bs = NULL; - token(); + reset_pos(byte_pos); + token(); } PgfExprParser::~PgfExprParser() @@ -433,6 +432,30 @@ bool PgfExprParser::str_char() 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() { if (token_value != NULL) diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index 63f063683..047539913 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -175,6 +175,7 @@ public: bool str_char(); void token(); + void raw_token(); bool lookahead(int ch); bool parse_bind(); @@ -195,7 +196,7 @@ public: bool is_str() { return (token_tag == PGF_TOKEN_STR); } 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 char *get_token_pos() { return token_pos; } diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index 86a5e43bf..ca54677ca 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -1576,9 +1576,12 @@ void PgfParser::suspend(Cont *cont,Item *item,bool do_predict,ref bu_literal(cont->state, "Int", &eparser, viterbi_prob); } else if (eparser.is_flt()) { bu_literal(cont->state, "Float", &eparser, viterbi_prob); - } else if (eparser.is_ident()) { - eparser.ident2str(); - bu_literal(cont->state, "String", &eparser, viterbi_prob); + } else { + eparser.reset_pos(cont->state->end.byte_pos); + 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); }