qbsp: add a PARSE_OPTIONAL parser flag
Enables us to check if there is extra data on the same line, without advancing the parser past the end of line. Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
30ab46b752
commit
4a487955c8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue