mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
digraph and trigraph tests
This commit is contained in:
parent
da80248016
commit
d5dcb3aff7
5 changed files with 25 additions and 11 deletions
1
gmqcc.h
1
gmqcc.h
|
@ -137,7 +137,6 @@ struct lex_file {
|
|||
int current;
|
||||
int length;
|
||||
int size;
|
||||
long line; /* Line the lexer is on */
|
||||
char lastok[8192]; /* No token shall ever be bigger than this! */
|
||||
};
|
||||
|
||||
|
|
21
lex.c
21
lex.c
|
@ -39,16 +39,17 @@ static const char *const lex_keywords[] = {
|
|||
|
||||
struct lex_file *lex_open(FILE *fp) {
|
||||
struct lex_file *lex = mem_a(sizeof(struct lex_file));
|
||||
if (lex) {
|
||||
lex->file = fp;
|
||||
fseek(lex->file, 0, SEEK_END);
|
||||
lex->length = ftell(lex->file);
|
||||
lex->size = lex->length; /* copy, this is never changed */
|
||||
fseek(lex->file, 0, SEEK_SET);
|
||||
lex->last = 0;
|
||||
if (!lex || !fp)
|
||||
return NULL;
|
||||
|
||||
memset(lex->peek, 0, sizeof(lex->peek));
|
||||
}
|
||||
lex->file = fp;
|
||||
fseek(lex->file, 0, SEEK_END);
|
||||
lex->length = ftell(lex->file);
|
||||
lex->size = lex->length; /* copy, this is never changed */
|
||||
fseek(lex->file, 0, SEEK_SET);
|
||||
lex->last = 0;
|
||||
|
||||
memset(lex->peek, 0, sizeof(lex->peek));
|
||||
return lex;
|
||||
}
|
||||
|
||||
|
@ -236,7 +237,7 @@ static int lex_skipcmt(struct lex_file *file) {
|
|||
lex_addch(ch, file);
|
||||
while ((ch = lex_getch(file)) != '*') {
|
||||
if (ch == EOF)
|
||||
return error(ERROR_LEX, "malformatted comment at line %d", file->line);
|
||||
return error(ERROR_LEX, "malformatted comment at line", "");
|
||||
else
|
||||
lex_addch(ch, file);
|
||||
}
|
||||
|
|
4
main.c
4
main.c
|
@ -65,6 +65,10 @@ int main(int argc, char **argv) {
|
|||
return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
|
||||
} else {
|
||||
struct lex_file *lex = lex_open(fp);
|
||||
if (!lex) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
parse_tree(lex); /* generate parse tree */
|
||||
lex_close (lex); /* cleanup lexer */
|
||||
}
|
||||
|
|
5
test/digraph.qc
Normal file
5
test/digraph.qc
Normal file
|
@ -0,0 +1,5 @@
|
|||
<%
|
||||
<%
|
||||
<% %>
|
||||
%>
|
||||
%>
|
5
test/trigraph.qc
Normal file
5
test/trigraph.qc
Normal file
|
@ -0,0 +1,5 @@
|
|||
??<
|
||||
??<
|
||||
??< ??>
|
||||
??>
|
||||
??>
|
Loading…
Reference in a new issue