|  | @@ -11,12 +11,19 @@
 | 
	
		
			
				|  |  |  #include "utils/SnuviUtils.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #define TOKEN_BUFFER_LENGTH (1024 * 1024)
 | 
	
		
			
				|  |  | -#define ERROR_LENGTH 256
 | 
	
		
			
				|  |  | +#define INCLUDE_STACK_LENGTH 32
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  static FileTokens fileTokens;
 | 
	
		
			
				|  |  |  static int fileTokenIndex;
 | 
	
		
			
				|  |  |  static jmp_buf errorJump;
 | 
	
		
			
				|  |  | -static Error* error;
 | 
	
		
			
				|  |  | +static Error* error = NULL;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +typedef struct {
 | 
	
		
			
				|  |  | +    const char* path;
 | 
	
		
			
				|  |  | +    int line;
 | 
	
		
			
				|  |  | +} IncludeEntry;
 | 
	
		
			
				|  |  | +static IncludeEntry includeStack[INCLUDE_STACK_LENGTH];
 | 
	
		
			
				|  |  | +static int includeStackIndex = 0;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  static char tokenBuffer[TOKEN_BUFFER_LENGTH];
 | 
	
		
			
				|  |  |  static int writeIndex = 0;
 | 
	
	
		
			
				|  | @@ -26,7 +33,13 @@ static int16 line = 1;
 | 
	
		
			
				|  |  |  static void tError(const char* format, ...) {
 | 
	
		
			
				|  |  |      va_list args;
 | 
	
		
			
				|  |  |      va_start(args, format);
 | 
	
		
			
				|  |  | -    eInitErrorV(error, "path not set", line, format, args);
 | 
	
		
			
				|  |  | +    const char* path = includeStackIndex > 0
 | 
	
		
			
				|  |  | +                           ? includeStack[includeStackIndex - 1].path
 | 
	
		
			
				|  |  | +                           : "path not set";
 | 
	
		
			
				|  |  | +    eInitErrorV(error, path, line, format, args);
 | 
	
		
			
				|  |  | +    for(int i = includeStackIndex - 2; i >= 0; i--) {
 | 
	
		
			
				|  |  | +        eAddPath(error, includeStack[i].path);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      va_end(args);
 | 
	
		
			
				|  |  |      longjmp(errorJump, 0);
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -306,10 +319,27 @@ static void tAddToken4(int c, Token tce, Token tc, Token te, Token t) {
 | 
	
		
			
				|  |  |  static void tParseToken(FileToken* t) {
 | 
	
		
			
				|  |  |      switch(t->type) {
 | 
	
		
			
				|  |  |          case FT_PATH:
 | 
	
		
			
				|  |  | -            // TODO: do something useful with the path
 | 
	
		
			
				|  |  | +            if(includeStackIndex >= INCLUDE_STACK_LENGTH) {
 | 
	
		
			
				|  |  | +                tError("include stack overflow");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            includeStack[includeStackIndex].path = t->literal;
 | 
	
		
			
				|  |  | +            includeStack[includeStackIndex].line = line;
 | 
	
		
			
				|  |  | +            includeStackIndex++;
 | 
	
		
			
				|  |  | +            line = 1;
 | 
	
		
			
				|  |  | +            tAddToken(T_OPEN_PATH);
 | 
	
		
			
				|  |  | +            tAdd(t->literal, strlen(t->literal) + 1);
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          case FT_END_PATH:
 | 
	
		
			
				|  |  | -            // TODO: do something useful
 | 
	
		
			
				|  |  | +            if(includeStackIndex <= 0) {
 | 
	
		
			
				|  |  | +                tError("include stack underflow");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            includeStackIndex--;
 | 
	
		
			
				|  |  | +            line = includeStack[includeStackIndex].line;
 | 
	
		
			
				|  |  | +            tAddToken(T_CLOSE_PATH);
 | 
	
		
			
				|  |  | +            const char* path = includeStackIndex > 0
 | 
	
		
			
				|  |  | +                                   ? includeStack[includeStackIndex - 1].path
 | 
	
		
			
				|  |  | +                                   : "path not set";
 | 
	
		
			
				|  |  | +            tAdd(path, strlen(path) + 1);
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          case FT_NEWLINE: line++; return;
 | 
	
		
			
				|  |  |          case FT_LITERAL: {
 | 
	
	
		
			
				|  | @@ -393,6 +423,7 @@ void tTokenize(const char* path, Error* e) {
 | 
	
		
			
				|  |  |      if(eHasError(e)) {
 | 
	
		
			
				|  |  |          ftPrint(&fileTokens);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    includeStackIndex = 0;
 | 
	
		
			
				|  |  |      ftDelete(&fileTokens);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |