Przeglądaj źródła

Merge pull request #1265 from marauder2k9-torque/torquescript-errorPrinting

Torquescript error printing
Brian Roberts 1 rok temu
rodzic
commit
72eb21ede0

+ 16 - 2
Engine/source/console/torquescript/CMDgram.h

@@ -134,7 +134,7 @@ extern int CMDdebug;
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 union YYSTYPE
 union YYSTYPE
 {
 {
-#line 82 "CMDgram.y"
+#line 87 "CMDgram.y"
 
 
    Token< char >           c;
    Token< char >           c;
    Token< int >            i;
    Token< int >            i;
@@ -160,9 +160,23 @@ typedef union YYSTYPE YYSTYPE;
 # define YYSTYPE_IS_DECLARED 1
 # define YYSTYPE_IS_DECLARED 1
 #endif
 #endif
 
 
+/* Location type.  */
+#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
+typedef struct YYLTYPE YYLTYPE;
+struct YYLTYPE
+{
+  int first_line;
+  int first_column;
+  int last_line;
+  int last_column;
+};
+# define YYLTYPE_IS_DECLARED 1
+# define YYLTYPE_IS_TRIVIAL 1
+#endif
 
 
-extern YYSTYPE CMDlval;
 
 
+extern YYSTYPE CMDlval;
+extern YYLTYPE CMDlloc;
 
 
 int CMDparse (void);
 int CMDparse (void);
 
 

+ 44 - 0
Engine/source/console/torquescript/CMDgram.y

@@ -1,3 +1,6 @@
+%define parse.error custom
+%locations
+%define api.header.include {"CMDgram.h"}
 %{
 %{
 
 
 // bison --defines=cmdgram.h --verbose -o cmdgram.cpp -p CMD CMDgram.y
 // bison --defines=cmdgram.h --verbose -o cmdgram.cpp -p CMD CMDgram.y
@@ -20,6 +23,7 @@
 
 
 int outtext(char *fmt, ...);
 int outtext(char *fmt, ...);
 extern int serrors;
 extern int serrors;
+extern Vector<String> lines;
 
 
 #define nil 0
 #define nil 0
 #undef YY_ARGS
 #undef YY_ARGS
@@ -28,6 +32,7 @@ extern int serrors;
 int CMDlex();
 int CMDlex();
 void CMDerror(const char *, ...);
 void CMDerror(const char *, ...);
 
 
+
 #ifdef alloca
 #ifdef alloca
 #undef alloca
 #undef alloca
 #endif
 #endif
@@ -616,3 +621,42 @@ aidx_expr
    ;
    ;
 %%
 %%
 
 
+int
+yyreport_syntax_error (const yypcontext_t *ctx)
+{
+   int ret = 0;
+   String output;
+   const YYLTYPE *loc = yypcontext_location (ctx);
+   output += "syntax error: ";
+
+   yysymbol_kind_t nxt = yypcontext_token(ctx);
+   if (nxt != YYSYMBOL_YYEMPTY)
+      output += String::ToString("unexpected: %s at column: %d", yysymbol_name(nxt), loc->first_column);
+
+   enum { TOKENMAX = 10 };
+   yysymbol_kind_t expected[TOKENMAX];
+
+   int exp = yypcontext_expected_tokens(ctx, expected, TOKENMAX);
+   if (exp < 0)
+      ret = exp;
+   else
+   {
+      for (int i = 0; i < exp; ++i)
+         output += String::ToString("%s %s", i == 0 ? ": expected" : "or", yysymbol_name(expected[i]));
+   }
+
+   if (lines.size() > 0) 
+   {
+      output += "\n";
+      for (int i = 0; i < lines.size(); i++)
+      {
+         int line = lines.size() - i;
+         output += String::ToString("%5d | ", loc->first_line - (line-1)) + lines[i] + "\n";
+      }
+      output += String::ToString("%5s | %*s", "", loc->first_column, "^");
+   }
+
+   yyerror(output.c_str());
+
+   return ret;
+}

Plik diff jest za duży
+ 373 - 329
Engine/source/console/torquescript/CMDscan.cpp


+ 89 - 131
Engine/source/console/torquescript/CMDscan.l

@@ -1,3 +1,4 @@
+%option yylineno nounput
 %{
 %{
 
 
 // flex --nounput -o CMDscan.cpp -P CMD CMDscan.l
 // flex --nounput -o CMDscan.cpp -P CMD CMDscan.l
@@ -54,6 +55,8 @@ static int Sc_ScanIdent();
 #define FLEX_DEBUG 0
 #define FLEX_DEBUG 0
 #endif
 #endif
 
 
+Vector<String> lines;
+
 // Install our own input code...
 // Install our own input code...
 #undef CMDgetc
 #undef CMDgetc
 int CMDgetc();
 int CMDgetc();
@@ -62,7 +65,7 @@ int CMDgetc();
 #ifndef isatty
 #ifndef isatty
 inline int isatty(int) { return 0; }
 inline int isatty(int) { return 0; }
 #endif
 #endif
-
+static int yycolumn = 1;
 // Wrap our getc, so that lex doesn't try to do its own buffering/file IO.
 // Wrap our getc, so that lex doesn't try to do its own buffering/file IO.
 #define YY_INPUT(buf,result,max_size) \
 #define YY_INPUT(buf,result,max_size) \
    { \
    { \
@@ -71,16 +74,18 @@ inline int isatty(int) { return 0; }
             (c = CMDgetc()) != EOF && c != '\n'; ++n ) \
             (c = CMDgetc()) != EOF && c != '\n'; ++n ) \
          buf[n] = (char) c; \
          buf[n] = (char) c; \
       if ( c == '\n' ) \
       if ( c == '\n' ) \
-         buf[n++] = (char) c; \
+         buf[n++] = (char) c; yycolumn = 1;\
       result = n; \
       result = n; \
    }
    }
 
 
-// General helper stuff.
-static int lineIndex;
+#define YY_USER_ACTION do { \
+    CMDlloc.first_line = CMDlloc.last_line = yylineno; \
+    CMDlloc.first_column = yycolumn; CMDlloc.last_column = yycolumn + yyleng - 1; \
+    yycolumn += yyleng; \
+    } while(0);
 
 
 // File state
 // File state
 void CMDSetScanBuffer(const char *sb, const char *fn);
 void CMDSetScanBuffer(const char *sb, const char *fn);
-const char * CMDgetFileLine(int &lineNumber);
 
 
 // Error reporting
 // Error reporting
 void CMDerror(const char * s, ...);
 void CMDerror(const char * s, ...);
@@ -111,38 +116,44 @@ HEXDIGIT [a-fA-F0-9]
 ("///"([^/\n\r][^\n\r]*)?[\n\r]+)+ { return(Sc_ScanDocBlock()); }
 ("///"([^/\n\r][^\n\r]*)?[\n\r]+)+ { return(Sc_ScanDocBlock()); }
 "//"[^\n\r]*   ;
 "//"[^\n\r]*   ;
 [\r]        ;
 [\r]        ;
-[\n]        {lineIndex++;}
+\n.*        { yycolumn = 1;
+   lines.push_back(String::ToString("%s", yytext+1));
+   if (lines.size() > Con::getIntVariable("$scriptErrorLineCount", 10))
+      lines.erase(lines.begin());
+
+   yyless(1);
+}
 \"(\\.|[^\\"\n\r])*\"      { return(Sc_ScanString(STRATOM)); }
 \"(\\.|[^\\"\n\r])*\"      { return(Sc_ScanString(STRATOM)); }
 \'(\\.|[^\\'\n\r])*\'      { return(Sc_ScanString(TAGATOM)); }
 \'(\\.|[^\\'\n\r])*\'      { return(Sc_ScanString(TAGATOM)); }
-"=="        { CMDlval.i = MakeToken< int >( opEQ, lineIndex ); return opEQ; }
-"!="        { CMDlval.i = MakeToken< int >( opNE, lineIndex ); return opNE; }
-">="        { CMDlval.i = MakeToken< int >( opGE, lineIndex ); return opGE; }
-"<="        { CMDlval.i = MakeToken< int >( opLE, lineIndex ); return opLE; }
-"&&"        { CMDlval.i = MakeToken< int >( opAND, lineIndex ); return opAND; }
-"||"        { CMDlval.i = MakeToken< int >( opOR, lineIndex ); return opOR; }
-"::"        { CMDlval.i = MakeToken< int >( opCOLONCOLON, lineIndex ); return opCOLONCOLON; }
-"--"        { CMDlval.i = MakeToken< int >( opMINUSMINUS, lineIndex ); return opMINUSMINUS; }
-"++"        { CMDlval.i = MakeToken< int >( opPLUSPLUS, lineIndex ); return opPLUSPLUS; }
-"$="        { CMDlval.i = MakeToken< int >( opSTREQ, lineIndex ); return opSTREQ; }
-"!$="       { CMDlval.i = MakeToken< int >( opSTRNE, lineIndex ); return opSTRNE; }
-"<<"        { CMDlval.i = MakeToken< int >( opSHL, lineIndex ); return opSHL; }
-">>"        { CMDlval.i = MakeToken< int >( opSHR, lineIndex ); return opSHR; }
-"+="        { CMDlval.i = MakeToken< int >( opPLASN, lineIndex ); return opPLASN; }
-"-="        { CMDlval.i = MakeToken< int >( opMIASN, lineIndex ); return opMIASN; }
-"*="        { CMDlval.i = MakeToken< int >( opMLASN, lineIndex ); return opMLASN; }
-"/="        { CMDlval.i = MakeToken< int >( opDVASN, lineIndex ); return opDVASN; }
-"%="        { CMDlval.i = MakeToken< int >( opMODASN, lineIndex ); return opMODASN; }
-"&="        { CMDlval.i = MakeToken< int >( opANDASN, lineIndex ); return opANDASN; }
-"^="        { CMDlval.i = MakeToken< int >( opXORASN, lineIndex ); return opXORASN; }
-"|="        { CMDlval.i = MakeToken< int >( opORASN, lineIndex ); return opORASN; }
-"<<="       { CMDlval.i = MakeToken< int >( opSLASN, lineIndex ); return opSLASN; }
-">>="       { CMDlval.i = MakeToken< int >( opSRASN, lineIndex ); return opSRASN; }
-"->"        { CMDlval.i = MakeToken< int >( opINTNAME, lineIndex ); return opINTNAME; }
-"-->"       { CMDlval.i = MakeToken< int >( opINTNAMER, lineIndex ); return opINTNAMER; }
-"NL"        { CMDlval.i = MakeToken< int >( '\n', lineIndex ); return '@'; }
-"TAB"       { CMDlval.i = MakeToken< int >( '\t', lineIndex ); return '@'; }
-"SPC"       { CMDlval.i = MakeToken< int >( ' ', lineIndex ); return '@'; }
-"@"         { CMDlval.i = MakeToken< int >( 0, lineIndex ); return '@'; }
+"=="        { CMDlval.i = MakeToken< int >( opEQ, yylineno ); return opEQ; }
+"!="        { CMDlval.i = MakeToken< int >( opNE, yylineno ); return opNE; }
+">="        { CMDlval.i = MakeToken< int >( opGE, yylineno ); return opGE; }
+"<="        { CMDlval.i = MakeToken< int >( opLE, yylineno ); return opLE; }
+"&&"        { CMDlval.i = MakeToken< int >( opAND, yylineno ); return opAND; }
+"||"        { CMDlval.i = MakeToken< int >( opOR, yylineno ); return opOR; }
+"::"        { CMDlval.i = MakeToken< int >( opCOLONCOLON, yylineno ); return opCOLONCOLON; }
+"--"        { CMDlval.i = MakeToken< int >( opMINUSMINUS, yylineno ); return opMINUSMINUS; }
+"++"        { CMDlval.i = MakeToken< int >( opPLUSPLUS, yylineno ); return opPLUSPLUS; }
+"$="        { CMDlval.i = MakeToken< int >( opSTREQ, yylineno ); return opSTREQ; }
+"!$="       { CMDlval.i = MakeToken< int >( opSTRNE, yylineno ); return opSTRNE; }
+"<<"        { CMDlval.i = MakeToken< int >( opSHL, yylineno ); return opSHL; }
+">>"        { CMDlval.i = MakeToken< int >( opSHR, yylineno ); return opSHR; }
+"+="        { CMDlval.i = MakeToken< int >( opPLASN, yylineno ); return opPLASN; }
+"-="        { CMDlval.i = MakeToken< int >( opMIASN, yylineno ); return opMIASN; }
+"*="        { CMDlval.i = MakeToken< int >( opMLASN, yylineno ); return opMLASN; }
+"/="        { CMDlval.i = MakeToken< int >( opDVASN, yylineno ); return opDVASN; }
+"%="        { CMDlval.i = MakeToken< int >( opMODASN, yylineno ); return opMODASN; }
+"&="        { CMDlval.i = MakeToken< int >( opANDASN, yylineno ); return opANDASN; }
+"^="        { CMDlval.i = MakeToken< int >( opXORASN, yylineno ); return opXORASN; }
+"|="        { CMDlval.i = MakeToken< int >( opORASN, yylineno ); return opORASN; }
+"<<="       { CMDlval.i = MakeToken< int >( opSLASN, yylineno ); return opSLASN; }
+">>="       { CMDlval.i = MakeToken< int >( opSRASN, yylineno ); return opSRASN; }
+"->"        { CMDlval.i = MakeToken< int >( opINTNAME, yylineno ); return opINTNAME; }
+"-->"       { CMDlval.i = MakeToken< int >( opINTNAMER, yylineno ); return opINTNAMER; }
+"NL"        { CMDlval.i = MakeToken< int >( '\n', yylineno ); return '@'; }
+"TAB"       { CMDlval.i = MakeToken< int >( '\t', yylineno ); return '@'; }
+"SPC"       { CMDlval.i = MakeToken< int >( ' ', yylineno ); return '@'; }
+"@"         { CMDlval.i = MakeToken< int >( 0, yylineno ); return '@'; }
 "/*" { /* this comment stops syntax highlighting from getting messed up when editing the lexer in TextPad */
 "/*" { /* this comment stops syntax highlighting from getting messed up when editing the lexer in TextPad */
          int c = 0, l;
          int c = 0, l;
          for ( ; ; )
          for ( ; ; )
@@ -157,10 +168,6 @@ HEXDIGIT [a-fA-F0-9]
                break;
                break;
             }
             }
 
 
-            // Increment line numbers.
-            else if ( c == '\n' )
-               lineIndex++;
-
             // Did we find the end of the comment?
             // Did we find the end of the comment?
             else if ( l == '*' && c == '/' )
             else if ( l == '*' && c == '/' )
                break;
                break;
@@ -189,37 +196,37 @@ HEXDIGIT [a-fA-F0-9]
 "%" |
 "%" |
 "^" |
 "^" |
 "~" |
 "~" |
-"="         { CMDlval.i = MakeToken< int >( CMDtext[ 0 ], lineIndex ); return CMDtext[ 0 ]; }
-"in"        { CMDlval.i = MakeToken< int >( rwIN, lineIndex ); return(rwIN); }
-"or"        { CMDlval.i = MakeToken< int >( rwCASEOR, lineIndex ); return(rwCASEOR); }
-"break"     { CMDlval.i = MakeToken< int >( rwBREAK, lineIndex ); return(rwBREAK); }
-"return"    { CMDlval.i = MakeToken< int >( rwRETURN, lineIndex ); return(rwRETURN); }
-"else"      { CMDlval.i = MakeToken< int >( rwELSE, lineIndex ); return(rwELSE); }
-"assert"    { CMDlval.i = MakeToken< int >( rwASSERT, lineIndex ); return(rwASSERT); }
-"while"     { CMDlval.i = MakeToken< int >( rwWHILE, lineIndex ); return(rwWHILE); }
-"do"        { CMDlval.i = MakeToken< int >( rwDO, lineIndex ); return(rwDO); }
-"if"        { CMDlval.i = MakeToken< int >( rwIF, lineIndex ); return(rwIF); }
-"foreach$"  { CMDlval.i = MakeToken< int >( rwFOREACHSTR, lineIndex ); return(rwFOREACHSTR); }
-"foreach"   { CMDlval.i = MakeToken< int >( rwFOREACH, lineIndex ); return(rwFOREACH); }
-"for"       { CMDlval.i = MakeToken< int >( rwFOR, lineIndex ); return(rwFOR); }
-"continue"  { CMDlval.i = MakeToken< int >( rwCONTINUE, lineIndex ); return(rwCONTINUE); }
-"function"  { CMDlval.i = MakeToken< int >( rwDEFINE, lineIndex ); return(rwDEFINE); }
-"new"       { CMDlval.i = MakeToken< int >( rwDECLARE, lineIndex ); return(rwDECLARE); }
-"singleton" { CMDlval.i = MakeToken< int >( rwDECLARESINGLETON, lineIndex ); return(rwDECLARESINGLETON); }
-"datablock" { CMDlval.i = MakeToken< int >( rwDATABLOCK, lineIndex ); return(rwDATABLOCK); }
-"case"      { CMDlval.i = MakeToken< int >( rwCASE, lineIndex ); return(rwCASE); }
-"switch$"   { CMDlval.i = MakeToken< int >( rwSWITCHSTR, lineIndex ); return(rwSWITCHSTR); }
-"switch"    { CMDlval.i = MakeToken< int >( rwSWITCH, lineIndex ); return(rwSWITCH); }
-"default"   { CMDlval.i = MakeToken< int >( rwDEFAULT, lineIndex ); return(rwDEFAULT); }
-"package"   { CMDlval.i = MakeToken< int >( rwPACKAGE, lineIndex ); return(rwPACKAGE); }
-"namespace" { CMDlval.i = MakeToken< int >( rwNAMESPACE, lineIndex ); return(rwNAMESPACE); }
-"true"      { CMDlval.i = MakeToken< int >( 1, lineIndex ); return INTCONST; }
-"false"     { CMDlval.i = MakeToken< int >( 0, lineIndex ); return INTCONST; }
+"="         { CMDlval.i = MakeToken< int >( CMDtext[ 0 ], yylineno ); return CMDtext[ 0 ]; }
+"in"        { CMDlval.i = MakeToken< int >( rwIN, yylineno ); return(rwIN); }
+"or"        { CMDlval.i = MakeToken< int >( rwCASEOR, yylineno ); return(rwCASEOR); }
+"break"     { CMDlval.i = MakeToken< int >( rwBREAK, yylineno ); return(rwBREAK); }
+"return"    { CMDlval.i = MakeToken< int >( rwRETURN, yylineno ); return(rwRETURN); }
+"else"      { CMDlval.i = MakeToken< int >( rwELSE, yylineno ); return(rwELSE); }
+"assert"    { CMDlval.i = MakeToken< int >( rwASSERT, yylineno ); return(rwASSERT); }
+"while"     { CMDlval.i = MakeToken< int >( rwWHILE, yylineno ); return(rwWHILE); }
+"do"        { CMDlval.i = MakeToken< int >( rwDO, yylineno ); return(rwDO); }
+"if"        { CMDlval.i = MakeToken< int >( rwIF, yylineno ); return(rwIF); }
+"foreach$"  { CMDlval.i = MakeToken< int >( rwFOREACHSTR, yylineno ); return(rwFOREACHSTR); }
+"foreach"   { CMDlval.i = MakeToken< int >( rwFOREACH, yylineno ); return(rwFOREACH); }
+"for"       { CMDlval.i = MakeToken< int >( rwFOR, yylineno ); return(rwFOR); }
+"continue"  { CMDlval.i = MakeToken< int >( rwCONTINUE, yylineno ); return(rwCONTINUE); }
+"function"  { CMDlval.i = MakeToken< int >( rwDEFINE, yylineno ); return(rwDEFINE); }
+"new"       { CMDlval.i = MakeToken< int >( rwDECLARE, yylineno ); return(rwDECLARE); }
+"singleton" { CMDlval.i = MakeToken< int >( rwDECLARESINGLETON, yylineno ); return(rwDECLARESINGLETON); }
+"datablock" { CMDlval.i = MakeToken< int >( rwDATABLOCK, yylineno ); return(rwDATABLOCK); }
+"case"      { CMDlval.i = MakeToken< int >( rwCASE, yylineno ); return(rwCASE); }
+"switch$"   { CMDlval.i = MakeToken< int >( rwSWITCHSTR, yylineno ); return(rwSWITCHSTR); }
+"switch"    { CMDlval.i = MakeToken< int >( rwSWITCH, yylineno ); return(rwSWITCH); }
+"default"   { CMDlval.i = MakeToken< int >( rwDEFAULT, yylineno ); return(rwDEFAULT); }
+"package"   { CMDlval.i = MakeToken< int >( rwPACKAGE, yylineno ); return(rwPACKAGE); }
+"namespace" { CMDlval.i = MakeToken< int >( rwNAMESPACE, yylineno ); return(rwNAMESPACE); }
+"true"      { CMDlval.i = MakeToken< int >( 1, yylineno ); return INTCONST; }
+"false"     { CMDlval.i = MakeToken< int >( 0, yylineno ); return INTCONST; }
 {VAR}       { return(Sc_ScanVar()); }
 {VAR}       { return(Sc_ScanVar()); }
 
 
 {ID}        { return Sc_ScanIdent(); }
 {ID}        { return Sc_ScanIdent(); }
 0[xX]{HEXDIGIT}+ return(Sc_ScanHex());
 0[xX]{HEXDIGIT}+ return(Sc_ScanHex());
-{INTEGER}   { CMDtext[CMDleng] = 0; CMDlval.i = MakeToken< int >( dAtoi(CMDtext), lineIndex ); return INTCONST; }
+{INTEGER}   { CMDtext[CMDleng] = 0; CMDlval.i = MakeToken< int >( dAtoi(CMDtext), yylineno ); return INTCONST; }
 {FLOAT}     return Sc_ScanNum();
 {FLOAT}     return Sc_ScanNum();
 {ILID}      return(ILLEGAL_TOKEN);
 {ILID}      return(ILLEGAL_TOKEN);
 .           return(ILLEGAL_TOKEN);
 .           return(ILLEGAL_TOKEN);
@@ -228,6 +235,7 @@ HEXDIGIT [a-fA-F0-9]
 static const char *scanBuffer;
 static const char *scanBuffer;
 static const char *fileName;
 static const char *fileName;
 static int scanIndex;
 static int scanIndex;
+extern YYLTYPE CMDlloc;
 
 
 const char * CMDGetCurrentFile()
 const char * CMDGetCurrentFile()
 {
 {
@@ -236,7 +244,7 @@ const char * CMDGetCurrentFile()
 
 
 int CMDGetCurrentLine()
 int CMDGetCurrentLine()
 {
 {
-   return lineIndex;
+   return yylineno;
 }
 }
 
 
 extern bool gConsoleSyntaxError;
 extern bool gConsoleSyntaxError;
@@ -254,74 +262,28 @@ void CMDerror(const char *format, ...)
 #else
 #else
    vsnprintf( tempBuf, BUFMAX, format, args );
    vsnprintf( tempBuf, BUFMAX, format, args );
 #endif
 #endif
-    va_end(args);
+   va_end(args);
 
 
    if(fileName)
    if(fileName)
    {
    {
-      Con::errorf(ConsoleLogEntry::Script, "%s Line: %d - %s", fileName, lineIndex, tempBuf);
-
-#ifndef NO_ADVANCED_ERROR_REPORT
-      // dhc - lineIndex is bogus.  let's try to add some sanity back in.
-      int i,j,n;
-      char c;
-      int linediv = 1;
-      // first, walk the buffer, trying to detect line ending type.
-      // this is imperfect, if inconsistant line endings exist...
-      for (i=0; i<scanIndex; i++)
-      {
-         c = scanBuffer[i];
-         if (c=='\r' && scanBuffer[i+1]=='\n') linediv = 2; // crlf detected
-         if (c=='\r' || c=='\n' || c==0) break; // enough for us to stop.
-      }
-      // grab some of the chars starting at the error location - lineending.
-      i = 1; j = 0; n = 1;
-      // find prev lineending
-      while (n<BUFMAX-8 && i<scanIndex) // cap at file start
-      {
-         c = scanBuffer[scanIndex-i];
-         if ((c=='\r' || c=='\n') && i>BUFMAX>>2) break; // at least get a little data
-         n++; i++;
-      }
-      // find next lineending
-      while (n<BUFMAX-8 && j<BUFMAX>>1) // cap at half-buf-size forward
-      {
-         c = scanBuffer[scanIndex+j];
-         if (c==0) break;
-         if ((c=='\r' || c=='\n') && j>BUFMAX>>2) break; // at least get a little data
-         n++; j++;
-      }
-      if (i) i--; // chop off extra linefeed.
-      if (j) j--; // chop off extra linefeed.
-      // build our little text block
-      if (i) dStrncpy(tempBuf,scanBuffer+scanIndex-i,i);
-      dStrncpy(tempBuf+i,"##", 2); // bracketing.
-      tempBuf[i+2] = scanBuffer[scanIndex]; // copy the halt character.
-      dStrncpy(tempBuf+i+3,"##", 2); // bracketing.
-      if (j) dStrncpy(tempBuf+i+5,scanBuffer+scanIndex+1,j); // +1 to go past current char.
-      tempBuf[i+j+5] = 0; // null terminate
-      for(n=0; n<i+j+5; n++) // convert CR to LF if alone...
-         if (tempBuf[n]=='\r' && tempBuf[n+1]!='\n') tempBuf[n] = '\n';
-      // write out to console the advanced error report
-      Con::warnf(ConsoleLogEntry::Script, ">>> Advanced script error report.  Line %d.", lineIndex);
-      Con::warnf(ConsoleLogEntry::Script, ">>> Some error context, with ## on sides of error halt:");
-      Con::errorf(ConsoleLogEntry::Script, "%s", tempBuf);
-      Con::warnf(ConsoleLogEntry::Script, ">>> Error report complete.\n");
-#endif
-
+      Con::errorf(ConsoleLogEntry::Script, "%s Line: %d - %s", fileName, yylineno, tempBuf);
       // Update the script-visible error buffer.
       // Update the script-visible error buffer.
       const char *prevStr = Con::getVariable("$ScriptError");
       const char *prevStr = Con::getVariable("$ScriptError");
       if (prevStr[0])
       if (prevStr[0])
-         dSprintf(tempBuf, sizeof(tempBuf), "%s\n%s Line: %d - Syntax error.", prevStr, fileName, lineIndex);
+         dSprintf(tempBuf, sizeof(tempBuf), "%s\n%s Line: %d - Syntax error.", prevStr, fileName, yylineno);
       else
       else
-         dSprintf(tempBuf, sizeof(tempBuf), "%s Line: %d - Syntax error.", fileName, lineIndex);
+         dSprintf(tempBuf, sizeof(tempBuf), "%s Line: %d - Syntax error.", fileName, yylineno);
       Con::setVariable("$ScriptError", tempBuf);
       Con::setVariable("$ScriptError", tempBuf);
 
 
       // We also need to mark that we came up with a new error.
       // We also need to mark that we came up with a new error.
       static S32 sScriptErrorHash=1000;
       static S32 sScriptErrorHash=1000;
       Con::setIntVariable("$ScriptErrorHash", sScriptErrorHash++);
       Con::setIntVariable("$ScriptErrorHash", sScriptErrorHash++);
+
    }
    }
    else
    else
+   {
       Con::errorf(ConsoleLogEntry::Script, tempBuf);
       Con::errorf(ConsoleLogEntry::Script, tempBuf);
+   }
 }
 }
 
 
 void CMDSetScanBuffer(const char *sb, const char *fn)
 void CMDSetScanBuffer(const char *sb, const char *fn)
@@ -329,7 +291,6 @@ void CMDSetScanBuffer(const char *sb, const char *fn)
    scanBuffer = sb;
    scanBuffer = sb;
    fileName = fn;
    fileName = fn;
    scanIndex = 0;
    scanIndex = 0;
-   lineIndex = 1;
 }
 }
 
 
 int CMDgetc()
 int CMDgetc()
@@ -353,7 +314,7 @@ static int Sc_ScanVar()
    CMDtext[CMDleng] = 0;
    CMDtext[CMDleng] = 0;
 
 
    // Make it a stringtable string!
    // Make it a stringtable string!
-   CMDlval.s = MakeToken< StringTableEntry >( StringTable->insert(CMDtext), lineIndex );
+   CMDlval.s = MakeToken< StringTableEntry >( StringTable->insert(CMDtext), yylineno );
    return(VAR);
    return(VAR);
 }
 }
 
 
@@ -387,7 +348,7 @@ static int Sc_ScanDocBlock()
 {
 {
    S32 len = dStrlen(CMDtext);
    S32 len = dStrlen(CMDtext);
    char* text = (char *) consoleAlloc(len + 1);
    char* text = (char *) consoleAlloc(len + 1);
-   S32 line = lineIndex;
+   S32 line = yylineno;
 
 
    for( S32 i = 0, j = 0; j <= len; j++ )
    for( S32 i = 0, j = 0; j <= len; j++ )
    {
    {
@@ -400,9 +361,6 @@ static int Sc_ScanDocBlock()
       if( CMDtext[j] == '\r' )
       if( CMDtext[j] == '\r' )
          continue;
          continue;
 
 
-      if( CMDtext[j] == '\n' )
-         lineIndex++;
-
       text[i++] = CMDtext[j];
       text[i++] = CMDtext[j];
    }
    }
 
 
@@ -420,7 +378,7 @@ static int Sc_ScanString(int ret)
    char* buffer = ( char* ) consoleAlloc( bufferLen );
    char* buffer = ( char* ) consoleAlloc( bufferLen );
    dStrcpy( buffer, CMDtext + 1, bufferLen );
    dStrcpy( buffer, CMDtext + 1, bufferLen );
 
 
-   CMDlval.str = MakeToken< char* >( buffer, lineIndex );
+   CMDlval.str = MakeToken< char* >( buffer, yylineno );
    return ret;
    return ret;
 }
 }
 
 
@@ -433,12 +391,12 @@ static int Sc_ScanIdent()
    if((type = ConsoleBaseType::getTypeByName(CMDtext)) != NULL)
    if((type = ConsoleBaseType::getTypeByName(CMDtext)) != NULL)
    {
    {
       /* It's a type */
       /* It's a type */
-      CMDlval.i = MakeToken< int >( type->getTypeID(), lineIndex );
+      CMDlval.i = MakeToken< int >( type->getTypeID(), yylineno );
       return TYPEIDENT;
       return TYPEIDENT;
    }
    }
 
 
    /* It's an identifier */
    /* It's an identifier */
-   CMDlval.s = MakeToken< StringTableEntry >( StringTable->insert(CMDtext), lineIndex );
+   CMDlval.s = MakeToken< StringTableEntry >( StringTable->insert(CMDtext), yylineno );
    return IDENT;
    return IDENT;
 }
 }
 
 
@@ -612,7 +570,7 @@ bool collapseEscape(char *buf)
 static int Sc_ScanNum()
 static int Sc_ScanNum()
 {
 {
    CMDtext[CMDleng] = 0;
    CMDtext[CMDleng] = 0;
-   CMDlval.f = MakeToken< double >( dAtof(CMDtext), lineIndex );
+   CMDlval.f = MakeToken< double >( dAtof(CMDtext), yylineno );
    return(FLTCONST);
    return(FLTCONST);
 }
 }
 
 
@@ -620,7 +578,7 @@ static int Sc_ScanHex()
 {
 {
    S32 val = 0;
    S32 val = 0;
    dSscanf(CMDtext, "%x", &val);
    dSscanf(CMDtext, "%x", &val);
-   CMDlval.i = MakeToken< int >( val, lineIndex );
+   CMDlval.i = MakeToken< int >( val, yylineno );
    return INTCONST;
    return INTCONST;
 }
 }
 
 

Plik diff jest za duży
+ 546 - 359
Engine/source/console/torquescript/cmdgram.cpp


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików