Browse Source

Add a field to Lex to store the readcount

mingodad 8 years ago
parent
commit
9daea8a4ec
3 changed files with 13 additions and 0 deletions
  1. 8 0
      SquiLu/squirrel/sq_lexer.cpp
  2. 2 0
      SquiLu/squirrel/sqlexer.cpp
  3. 3 0
      SquiLu/squirrel/sqlexer.h

+ 8 - 0
SquiLu/squirrel/sq_lexer.cpp

@@ -250,6 +250,13 @@ static SQRESULT sq_SQLexer_last_enum_token(HSQUIRRELVM v){
 	return 1;
 	return 1;
 }
 }
 
 
+static SQRESULT sq_SQLexer_readcount(HSQUIRRELVM v){
+	SQ_FUNC_VARS_NO_TOP(v);
+	GET_SQLexer_INSTANCE();
+
+    sq_pushinteger(v, self->lex->data->readcount);
+	return 1;
+}
 #define _DECL_SQLEXER_FUNC(name,nparams,pmask) {_SC(#name),sq_SQLexer_##name,nparams,pmask}
 #define _DECL_SQLEXER_FUNC(name,nparams,pmask) {_SC(#name),sq_SQLexer_##name,nparams,pmask}
 static SQRegFunction SQLexer_obj_funcs[]={
 static SQRegFunction SQLexer_obj_funcs[]={
 
 
@@ -271,6 +278,7 @@ static SQRegFunction SQLexer_obj_funcs[]={
 	_DECL_SQLEXER_FUNC(last_enum_token, 1, _SC(".")),
 	_DECL_SQLEXER_FUNC(last_enum_token, 1, _SC(".")),
 	_DECL_SQLEXER_FUNC(lex, 1, _SC(".")),
 	_DECL_SQLEXER_FUNC(lex, 1, _SC(".")),
 	_DECL_SQLEXER_FUNC(lookaheadlex, 1, _SC(".")),
 	_DECL_SQLEXER_FUNC(lookaheadlex, 1, _SC(".")),
+	_DECL_SQLEXER_FUNC(readcount, 1, _SC(".")),
 	{0,0}
 	{0,0}
 };
 };
 #undef _DECL_SQLEXER_FUNC
 #undef _DECL_SQLEXER_FUNC

+ 2 - 0
SquiLu/squirrel/sqlexer.cpp

@@ -48,6 +48,7 @@ SQInteger SQLexer::ResetReader(SQLEXREADFUNC rg, SQUserPointer up, SQInteger lin
 	data->lasttokencolumn = 0;
 	data->lasttokencolumn = 0;
 	data->currentcolumn = 0;
 	data->currentcolumn = 0;
 	data->prevtoken = -1;
 	data->prevtoken = -1;
+	data->readcount = 0;
 	data->reached_eof = SQFalse;
 	data->reached_eof = SQFalse;
 	return Next();
 	return Next();
 }
 }
@@ -165,6 +166,7 @@ SQInteger SQLexer::Next()
 	if(t != 0) {
 	if(t != 0) {
 		data->currdata = (LexChar)t;
 		data->currdata = (LexChar)t;
 		++data->currentcolumn;
 		++data->currentcolumn;
+		++data->readcount;
 		return 0;
 		return 0;
 	}
 	}
 	data->currdata = SQUIRREL_EOB;
 	data->currdata = SQUIRREL_EOB;

+ 3 - 0
SquiLu/squirrel/sqlexer.h

@@ -22,6 +22,7 @@ struct SQLexerData
     SQInteger nvalue;
     SQInteger nvalue;
     SQFloat fvalue;
     SQFloat fvalue;
     LexChar currdata;
     LexChar currdata;
+    SQInteger readcount;
     SQChar lasterror[256];
     SQChar lasterror[256];
     SQLexerData()
     SQLexerData()
     {
     {
@@ -46,6 +47,7 @@ struct SQLexerData
         nvalue = src->nvalue;
         nvalue = src->nvalue;
         fvalue = src->fvalue;
         fvalue = src->fvalue;
         currdata = src->currdata;
         currdata = src->currdata;
+        readcount = src->readcount;
         scstrcpy(lasterror, src->lasterror);
         scstrcpy(lasterror, src->lasterror);
     }
     }
     void clear()
     void clear()
@@ -63,6 +65,7 @@ struct SQLexerData
         fvalue = 0.0;
         fvalue = 0.0;
         currdata = 0;
         currdata = 0;
         lasterror[0] = '\0';
         lasterror[0] = '\0';
+        readcount = 0;
     }
     }
 };
 };