changed: in SpaceParser: now we do not parse special characters when reading commentaries

so we can parse:
         # such a \n string
         beforehand this \n was treated as a new line character
         and the parser was returning syntax error when reading above 'string'



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@432 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-09-25 16:50:01 +00:00
parent c6c079f8aa
commit 02abfe62fa
2 changed files with 43 additions and 15 deletions

View File

@ -202,6 +202,7 @@ void SpaceParser::Parse()
line = 1;
status = ok;
space = root_space;
reading_commentary = false;
ReadChar();
SkipWhiteLines();
@ -300,13 +301,15 @@ return false;
}
void SpaceParser::SkipWhite()
/*
skip_lines is default false
*/
void SpaceParser::SkipWhite(bool skip_lines)
{
while( IsWhite(lastc) || lastc == commentary )
while( IsWhite(lastc) || lastc == commentary || (skip_lines && lastc=='\n'))
{
if( lastc == commentary )
SkipLine();
SkipComment();
else
ReadChar();
}
@ -315,16 +318,13 @@ void SpaceParser::SkipWhite()
void SpaceParser::SkipWhiteLines()
{
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
{
if( lastc == commentary )
SkipLine();
else
ReadChar();
}
SkipWhite(true);
}
/*
do not skip the last \n character
*/
void SpaceParser::SkipLine()
{
while( lastc != -1 && lastc != '\n' )
@ -332,6 +332,17 @@ void SpaceParser::SkipLine()
}
/*
do not skip the last \n character
*/
void SpaceParser::SkipComment()
{
reading_commentary = true;
SkipLine();
reading_commentary = false;
}
void SpaceParser::Trim(std::wstring & s)
{
@ -411,7 +422,7 @@ void SpaceParser::ReadTokenSingle(bool white_delimit, bool new_line_delimit, int
while( true )
{
if( lastc == commentary )
SkipLine();
SkipComment();
if( lastc == -1 ||
(!char_was_escaped &&
@ -662,7 +673,7 @@ int SpaceParser::ReadChar()
char_was_escaped = false;
ReadCharNoEscape();
if( use_escape_char && lastc == '\\' )
if( !reading_commentary && use_escape_char && lastc == '\\' )
{
char_was_escaped = true;
ReadCharNoEscape();

View File

@ -140,15 +140,25 @@ public:
/*
'\' character is used to escape other characters in a quoted string
'\' character is used to escape other characters
so "some \t t\"ext" will produce "some t t"ext"
default: true
special characters:
\0 - 0 (zero code point)
\t - tabulator (9 code point)
\r - carriage return (13 code point)
\n - a new line character (10 code point)
in other cases we return the last character so \Z gives Z and \\ gives one \
escape character are not used in commentaries
so you can write:
# this is my comment \n but this was not a new line
*/
void UseEscapeChar(bool escape);
/*
if true then the input file or string (char* or std::string) is treated as UTF-8
default: true
*/
void UTF8(bool utf);
@ -287,6 +297,12 @@ private:
bool use_escape_char;
/*
true if we are reading the commentary (#)
this is to avoid parsing escape characters in the commentary
*/
bool reading_commentary;
std::string afile_name;
void Parse();
@ -314,9 +330,10 @@ private:
int ReadCharNoEscape();
int ReadChar();
bool IsWhite(int c);
void SkipWhite();
void SkipWhite(bool skip_lines = false);
void SkipWhiteLines();
void SkipLine();
void SkipComment();
void Trim(std::wstring & s);
};