diff options
author | Adrian Thurston <thurston@complang.org> | 2013-04-06 14:07:41 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-04-06 14:07:41 -0400 |
commit | 7343ff7f7c770633ef41b395d6eb5adcb01b9c56 (patch) | |
tree | 4d5db3a4515f6d92d44a54947decf788906225f2 | |
parent | 2d2bef4a39aef0721ad19e75770852e60524c198 (diff) | |
download | colm-7343ff7f7c770633ef41b395d6eb5adcb01b9c56.tar.gz |
put a location into the error string tree stored in a failed parse object
-rw-r--r-- | colm/pdarun.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/colm/pdarun.c b/colm/pdarun.c index 0049b7a5..0d352d5d 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -497,13 +497,18 @@ static void reportParseError( Program *prg, Tree **sp, PdaRun *pdaRun ) Head *errorHead = 0; /* If there are no error points on record assume the error occurred at the beginning of the stream. */ - if ( deepest == 0 ) + if ( deepest == 0 ) { errorHead = stringAllocFull( prg, "PARSE ERROR at 1:1", 18 ); + errorHead->location = locationAllocate( prg ); + errorHead->location->line = 1; + errorHead->location->column = 1; + } else { debug( prg, REALM_PARSE, "deepest location byte: %d\n", deepest->location->byte ); long line = deepest->location->line; long i, column = deepest->location->column; + long byte = deepest->location->byte; for ( i = 0; i < deepest->length; i++ ) { if ( deepest->data[i] != '\n' ) @@ -512,11 +517,18 @@ static void reportParseError( Program *prg, Tree **sp, PdaRun *pdaRun ) line += 1; column = 1; } + byte += 1; } char formatted[128]; sprintf( formatted, "PARSE ERROR at %ld:%ld", line, column ); errorHead = stringAllocFull( prg, formatted, strlen(formatted) ); + + errorHead->location = locationAllocate( prg ); + errorHead->location->line = line; + errorHead->location->column = column; + errorHead->location->byte = byte; + errorHead->location->file = deepest->location->file; } Tree *tree = constructString( prg, errorHead ); |