diff --git a/qbsp/parser.c b/qbsp/parser.c index c74274ce..1e3517cf 100644 --- a/qbsp/parser.c +++ b/qbsp/parser.c @@ -46,16 +46,21 @@ ParseToken(parser_t *p, parseflags_t flags) /* skip space */ while (*p->pos <= 32) { if (!*p->pos) { + if (flags & PARSE_OPTIONAL) + return false; if (flags & PARSE_SAMELINE) Error("line %d: Line is incomplete", p->linenum); return false; } - if (*p->pos++ == '\n') { + if (*p->pos == '\n') { + if (flags & PARSE_OPTIONAL) + return false; if (flags & PARSE_SAMELINE) Error("line %d: Line is incomplete", p->linenum); p->linenum++; } - } + p->pos++; + } /* comment field */ if (p->pos[0] == '/' && p->pos[1] == '/') { @@ -68,14 +73,17 @@ ParseToken(parser_t *p, parseflags_t flags) } goto out; } + if (flags & PARSE_OPTIONAL) + return false; if (flags & PARSE_SAMELINE) Error("line %d: Line is incomplete", p->linenum); - while (*p->pos++ != '\n') + while (*p->pos++ != '\n') { if (!*p->pos) { if (flags & PARSE_SAMELINE) Error("line %d: Line is incomplete", p->linenum); return false; } + } goto skipspace; } if (flags & PARSE_COMMENT) diff --git a/qbsp/parser.h b/qbsp/parser.h index 01e53ba5..4dd16dce 100644 --- a/qbsp/parser.h +++ b/qbsp/parser.h @@ -28,8 +28,9 @@ typedef enum parseflags { PARSE_NORMAL = 0, - PARSE_SAMELINE = 1, /* The next token must be on the current line */ - PARSE_COMMENT = 2 /* Return a // comment as the next token */ + PARSE_SAMELINE = 1, /* Expect the next token the current line */ + PARSE_COMMENT = 2, /* If a // comment is next token, return it */ + PARSE_OPTIONAL = 4, /* Return next token on same line, or false if EOL */ } parseflags_t; typedef struct parser {