Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Keep track of token location when parsing.
  • Loading branch information
icculus committed Feb 21, 2010
1 parent c30fb60 commit aa8d805
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mojoshader_compiler.c
Expand Up @@ -482,6 +482,8 @@ typedef struct Context
ErrorList *errors;
Preprocessor *preprocessor;
StringBucket *string_hashtable[256];
const char *sourcefile;
unsigned int sourceline;
const char *usertypes[512]; // !!! FIXME: dynamic allocation
int usertype_count;
CompilationUnit *ast; // Abstract Syntax Tree
Expand Down Expand Up @@ -522,7 +524,7 @@ static void fail(Context *ctx, const char *str)
{
// !!! FIXME: placeholder.
(void) ctx;
printf("FAIL: %s\n", str);
printf("%s:%u: %s\n", ctx->sourcefile, ctx->sourceline, str);
} // fail

// These functions are mostly for construction and cleanup of nodes in the
Expand Down Expand Up @@ -1787,6 +1789,7 @@ void MOJOSHADER_compile(const char *filename,
Token tokenval;
const char *token;
int lemon_token;
const char *fname;

if (m == NULL) m = MOJOSHADER_internal_malloc;
if (f == NULL) f = MOJOSHADER_internal_free;
Expand Down Expand Up @@ -1816,7 +1819,10 @@ void MOJOSHADER_compile(const char *filename,
break;
} // if

else if (tokenval == TOKEN_BAD_CHARS)
fname = preprocessor_sourcepos(ctx.preprocessor, &ctx.sourceline);
ctx.sourcefile = fname ? cache_string(&ctx, fname, strlen(fname)) : 0;

if (tokenval == TOKEN_BAD_CHARS)
{
fail(&ctx, "Bad characters in source file");
continue;
Expand Down

0 comments on commit aa8d805

Please sign in to comment.