2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
18 #include "parser_private.hxx"
19 #include "configvariable.hxx"
23 #include "charEncoding.h"
26 void ParserSingleInstance::PrintError(const std::wstring& msg)
28 std::wostringstream ostr;
29 char *codeLine = (char *) malloc(4096 * sizeof(char));
31 //If the error is a the very beginning of a line
32 if (yylloc.first_line == yylloc.last_line
33 && yylloc.first_column == 1
34 && yylloc.last_column == 1)
40 ConfigVariable::fillWhereError(yylloc.first_line);
42 /** Print where in the script the error is located */
43 wchar_t* str = to_wide_string(ParserSingleInstance::getCodeLine(yylloc.first_line, &codeLine));
45 // add EOL only if the code line doesn't already contains it.
46 if (wcscmp(str + wcslen(str) - 1, L"\n") != 0)
53 /** Underline what causes the trouble */
55 for (i = 1 ; i < yylloc.first_column ; ++i)
60 for (i = i + 1 ; i < yylloc.last_column ; ++i)
64 if ( yylloc.first_column != yylloc.last_column )
70 /** Display Parser message */
71 std::wstring wstrError(_W("Error: "));
72 ostr << wstrError << msg << std::endl;
74 ParserSingleInstance::appendErrorMessage(ostr.str());