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:
parent
c6c079f8aa
commit
02abfe62fa
|
@ -202,6 +202,7 @@ void SpaceParser::Parse()
|
||||||
line = 1;
|
line = 1;
|
||||||
status = ok;
|
status = ok;
|
||||||
space = root_space;
|
space = root_space;
|
||||||
|
reading_commentary = false;
|
||||||
ReadChar();
|
ReadChar();
|
||||||
SkipWhiteLines();
|
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 )
|
if( lastc == commentary )
|
||||||
SkipLine();
|
SkipComment();
|
||||||
else
|
else
|
||||||
ReadChar();
|
ReadChar();
|
||||||
}
|
}
|
||||||
|
@ -315,16 +318,13 @@ void SpaceParser::SkipWhite()
|
||||||
|
|
||||||
void SpaceParser::SkipWhiteLines()
|
void SpaceParser::SkipWhiteLines()
|
||||||
{
|
{
|
||||||
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
|
SkipWhite(true);
|
||||||
{
|
|
||||||
if( lastc == commentary )
|
|
||||||
SkipLine();
|
|
||||||
else
|
|
||||||
ReadChar();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
do not skip the last \n character
|
||||||
|
*/
|
||||||
void SpaceParser::SkipLine()
|
void SpaceParser::SkipLine()
|
||||||
{
|
{
|
||||||
while( lastc != -1 && lastc != '\n' )
|
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)
|
void SpaceParser::Trim(std::wstring & s)
|
||||||
{
|
{
|
||||||
|
@ -411,7 +422,7 @@ void SpaceParser::ReadTokenSingle(bool white_delimit, bool new_line_delimit, int
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
if( lastc == commentary )
|
if( lastc == commentary )
|
||||||
SkipLine();
|
SkipComment();
|
||||||
|
|
||||||
if( lastc == -1 ||
|
if( lastc == -1 ||
|
||||||
(!char_was_escaped &&
|
(!char_was_escaped &&
|
||||||
|
@ -662,7 +673,7 @@ int SpaceParser::ReadChar()
|
||||||
char_was_escaped = false;
|
char_was_escaped = false;
|
||||||
ReadCharNoEscape();
|
ReadCharNoEscape();
|
||||||
|
|
||||||
if( use_escape_char && lastc == '\\' )
|
if( !reading_commentary && use_escape_char && lastc == '\\' )
|
||||||
{
|
{
|
||||||
char_was_escaped = true;
|
char_was_escaped = true;
|
||||||
ReadCharNoEscape();
|
ReadCharNoEscape();
|
||||||
|
|
|
@ -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"
|
so "some \t t\"ext" will produce "some t t"ext"
|
||||||
default: true
|
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);
|
void UseEscapeChar(bool escape);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if true then the input file or string (char* or std::string) is treated as UTF-8
|
if true then the input file or string (char* or std::string) is treated as UTF-8
|
||||||
|
default: true
|
||||||
*/
|
*/
|
||||||
void UTF8(bool utf);
|
void UTF8(bool utf);
|
||||||
|
|
||||||
|
@ -287,6 +297,12 @@ private:
|
||||||
bool use_escape_char;
|
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;
|
std::string afile_name;
|
||||||
|
|
||||||
void Parse();
|
void Parse();
|
||||||
|
@ -314,9 +330,10 @@ private:
|
||||||
int ReadCharNoEscape();
|
int ReadCharNoEscape();
|
||||||
int ReadChar();
|
int ReadChar();
|
||||||
bool IsWhite(int c);
|
bool IsWhite(int c);
|
||||||
void SkipWhite();
|
void SkipWhite(bool skip_lines = false);
|
||||||
void SkipWhiteLines();
|
void SkipWhiteLines();
|
||||||
void SkipLine();
|
void SkipLine();
|
||||||
|
void SkipComment();
|
||||||
void Trim(std::wstring & s);
|
void Trim(std::wstring & s);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue