Fix line number tracking in sexpr parser

This commit is contained in:
Cirilo Bernardo 2017-02-01 15:53:16 +11:00 committed by Wayne Stambaugh
parent cf1003955d
commit d29f39dce4
3 changed files with 8 additions and 4 deletions

View File

@ -31,7 +31,7 @@ namespace SEXPR
}
SEXPR::SEXPR(SEXPR_TYPE type) :
m_type(type), m_lineNumber(0)
m_type(type), m_lineNumber(1)
{
}

View File

@ -30,7 +30,7 @@ namespace SEXPR
{
const std::string PARSER::whitespaceCharacters = " \t\n\r\b\f\v";
PARSER::PARSER() : m_lineNumber(0), m_lineOffset(0)
PARSER::PARSER() : m_lineNumber(1)
{
}
@ -82,7 +82,6 @@ namespace SEXPR
if (*it == '\n')
{
m_lineNumber++;
m_lineOffset = 0;
}
if (whitespaceCharacters.find(*it) != std::string::npos)
@ -95,6 +94,12 @@ namespace SEXPR
SEXPR_LIST* list = new SEXPR_LIST(m_lineNumber);
while (it != aString.end() && *it != ')')
{
//there may be newlines in between atoms of a list, so detect these here
if (*it == '\n')
{
m_lineNumber++;
}
if (whitespaceCharacters.find(*it) != std::string::npos)
{
std::advance(it, 1);

View File

@ -38,7 +38,6 @@ namespace SEXPR
SEXPR* parseString(const std::string& aString, std::string::const_iterator& it);
static const std::string whitespaceCharacters;
int m_lineNumber;
int m_lineOffset;
};
}