static int lex_skipwhite(lex_file *lex)
{
int ch = 0;
+ bool haswhite = false;
do
{
if (ch == '\n') {
/* end-of-line */
/* see if there was whitespace first */
- if (lex->tok.value_count) {
+ if (haswhite) { /* (lex->tok.value_count) { */
lex_ungetch(lex, ch);
if (!lex_endtoken(lex))
return TOKEN_FATAL;
/* otherwise return EOL */
return TOKEN_EOL;
}
+ haswhite = true;
if (!lex_tokench(lex, ch))
return TOKEN_FATAL;
}
ch = lex_getch(lex);
}
- if (lex->flags.preprocessing && !lex_tokench(lex, ch))
- return TOKEN_FATAL;
if (ch == '/') {
ch = lex_getch(lex);
if (ch == '/')
{
/* one line comment */
+ haswhite = true;
ch = lex_getch(lex);
if (lex->flags.preprocessing) {
if (ch == '*')
{
/* multiline comment */
+ haswhite = true;
if (lex->flags.preprocessing) {
if (!lex_tokench(lex, ' ') ||
!lex_tokench(lex, ' '))
}
} while (ch != EOF && isspace(ch));
+ if (haswhite) {
+ if (!lex_endtoken(lex))
+ return TOKEN_FATAL;
+ lex_ungetch(lex, ch);
+ return TOKEN_WHITE;
+ }
return ch;
}
lex->tok.ctx.line = lex->sline;
lex->tok.ctx.file = lex->name;
- if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || TOKEN_FATAL)) {
+ if (lex->flags.preprocessing && (ch == TOKEN_WHITE || ch == TOKEN_EOL || ch == TOKEN_FATAL)) {
return (lex->tok.ttype = ch);
}
(items_data[itr].type == TYPE_SRC ? "progs.src" :
("unknown"))))));
+ if (opts_pp_only) {
+ if (!preprocess(items_data[itr].filename)) {
+ retval = 1;
+ goto cleanup;
+ }
+ continue;
+ }
+
if (!parser_compile(items_data[itr].filename)) {
retval = 1;
goto cleanup;
--- /dev/null
+#include "gmqcc.h"
+#include "lexer.h"
+
+bool preprocess(const char *filename)
+{
+ int tok;
+ lex_file *lex = lex_open(filename);
+ lex->flags.preprocessing = true;
+
+ do {
+ tok = lex_do(lex);
+ if (tok == TOKEN_EOL)
+ printf("EOL");
+ else if (tok >= TOKEN_START && tok <= TOKEN_FATAL)
+ printf("%s: ", _tokennames[tok - TOKEN_START]);
+ else
+ printf("TOKEN: '%c'", tok);
+ if (tok == TOKEN_WHITE)
+ printf(">>%s<<\n", lex->tok.value);
+ else
+ printf("\n");
+ } while (tok < TOKEN_EOF);
+
+ lex_close(lex);
+ return true;
+}