forked from GitHub/gf-core
bugfix: pgf_read_expr no longer requires a semicolon at the end of an abstract expression
This commit is contained in:
@@ -141,10 +141,8 @@ struct PgfExprParser {
|
|||||||
int next_char;
|
int next_char;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const char pgf_expr_lpar[] = "(";
|
static const char pgf_expr_lpar[] = "(";
|
||||||
static const char pgf_expr_rpar[] = ")";
|
static const char pgf_expr_rpar[] = ")";
|
||||||
static const char pgf_expr_semic[] = ";";
|
|
||||||
|
|
||||||
static char
|
static char
|
||||||
pgf_expr_parser_next(PgfExprParser* parser)
|
pgf_expr_parser_next(PgfExprParser* parser)
|
||||||
@@ -168,6 +166,7 @@ pgf_expr_parser_lookahead(PgfExprParser* parser)
|
|||||||
do {
|
do {
|
||||||
c = pgf_expr_parser_next(parser);
|
c = pgf_expr_parser_next(parser);
|
||||||
if (!gu_ok(parser->err)) {
|
if (!gu_ok(parser->err)) {
|
||||||
|
gu_exn_clear(parser->err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} while (isspace(c));
|
} while (isspace(c));
|
||||||
@@ -178,9 +177,6 @@ pgf_expr_parser_lookahead(PgfExprParser* parser)
|
|||||||
case ')':
|
case ')':
|
||||||
str = pgf_expr_rpar;
|
str = pgf_expr_rpar;
|
||||||
break;
|
break;
|
||||||
case ';':
|
|
||||||
str = pgf_expr_semic;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
if (isalpha(c)) {
|
if (isalpha(c)) {
|
||||||
GuPool* tmp_pool = gu_new_pool();
|
GuPool* tmp_pool = gu_new_pool();
|
||||||
@@ -189,7 +185,7 @@ pgf_expr_parser_lookahead(PgfExprParser* parser)
|
|||||||
gu_buf_push(chars, char, c);
|
gu_buf_push(chars, char, c);
|
||||||
c = pgf_expr_parser_next(parser);
|
c = pgf_expr_parser_next(parser);
|
||||||
if (!gu_ok(parser->err)) {
|
if (!gu_ok(parser->err)) {
|
||||||
return NULL;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parser->next_char = (unsigned char) c;
|
parser->next_char = (unsigned char) c;
|
||||||
@@ -235,6 +231,8 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
|||||||
if (la == pgf_expr_rpar) {
|
if (la == pgf_expr_rpar) {
|
||||||
pgf_expr_parser_consume(parser);
|
pgf_expr_parser_consume(parser);
|
||||||
return expr;
|
return expr;
|
||||||
|
} else {
|
||||||
|
gu_raise(parser->err, PgfExn);
|
||||||
}
|
}
|
||||||
} else if (pgf_expr_parser_token_is_id(la)) {
|
} else if (pgf_expr_parser_token_is_id(la)) {
|
||||||
pgf_expr_parser_consume(parser);
|
pgf_expr_parser_consume(parser);
|
||||||
@@ -252,9 +250,8 @@ pgf_expr_parser_expr(PgfExprParser* parser)
|
|||||||
{
|
{
|
||||||
PgfExpr expr = pgf_expr_parser_term(parser);
|
PgfExpr expr = pgf_expr_parser_term(parser);
|
||||||
if (gu_variant_is_null(expr))
|
if (gu_variant_is_null(expr))
|
||||||
{
|
|
||||||
return expr;
|
return expr;
|
||||||
}
|
|
||||||
while (true) {
|
while (true) {
|
||||||
PgfExpr arg = pgf_expr_parser_term(parser);
|
PgfExpr arg = pgf_expr_parser_term(parser);
|
||||||
if (gu_variant_is_null(arg)) {
|
if (gu_variant_is_null(arg)) {
|
||||||
@@ -267,8 +264,6 @@ pgf_expr_parser_expr(PgfExprParser* parser)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PgfExpr
|
PgfExpr
|
||||||
pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err)
|
pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err)
|
||||||
{
|
{
|
||||||
@@ -281,12 +276,6 @@ pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err)
|
|||||||
parser->lookahead = NULL;
|
parser->lookahead = NULL;
|
||||||
parser->next_char = -1;
|
parser->next_char = -1;
|
||||||
PgfExpr expr = pgf_expr_parser_expr(parser);
|
PgfExpr expr = pgf_expr_parser_expr(parser);
|
||||||
const char* la = pgf_expr_parser_lookahead(parser);
|
|
||||||
if (la == pgf_expr_semic) {
|
|
||||||
pgf_expr_parser_consume(parser);
|
|
||||||
} else {
|
|
||||||
expr = gu_null_variant;
|
|
||||||
}
|
|
||||||
gu_pool_free(tmp_pool);
|
gu_pool_free(tmp_pool);
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user