Lexer: Fixed DOM missing lookahead

This commit is contained in:
Paul Beckingham 2018-01-24 23:50:42 -05:00
parent e0dbf4b691
commit d5a0b616e1

View file

@ -726,7 +726,7 @@ bool Lexer::isNumber (std::string& token, Lexer::Type& type)
} }
} }
// Lookahread: !<isWhitespace> | !<isSingleCharOperator> // Lookahead: !<isWhitespace> | !<isSingleCharOperator>
// If there is an immediately consecutive character, that is not an operator, fail. // If there is an immediately consecutive character, that is not an operator, fail.
if (_eos > marker && if (_eos > marker &&
! isWhitespace (_text[marker]) && ! isWhitespace (_text[marker]) &&
@ -1173,6 +1173,7 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
{ {
std::size_t marker = _cursor; std::size_t marker = _cursor;
// rc. ...
std::string partialToken; std::string partialToken;
Lexer::Type partialType; Lexer::Type partialType;
if (isLiteral ("rc.", false, false) && if (isLiteral ("rc.", false, false) &&
@ -1185,6 +1186,7 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
else else
_cursor = marker; _cursor = marker;
// Literals
if (isOneOf ({"tw.syncneeded", if (isOneOf ({"tw.syncneeded",
"tw.program", "tw.program",
"tw.args", "tw.args",
@ -1233,7 +1235,7 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
else else
_cursor = checkpoint; _cursor = checkpoint;
// [prefix]attribute // [prefix]attribute (bounded)
if (isOneOf (attributes, false, true)) if (isOneOf (attributes, false, true))
{ {
token = _text.substr (marker, _cursor - marker); token = _text.substr (marker, _cursor - marker);
@ -1241,7 +1243,7 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
return true; return true;
} }
// [prefix]attribute. // [prefix]attribute. (unbounded)
if (isOneOf (attributes, false, false)) if (isOneOf (attributes, false, false))
{ {
if (isLiteral (".", false, false)) if (isLiteral (".", false, false))
@ -1259,13 +1261,19 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
type = Lexer::Type::dom; type = Lexer::Type::dom;
return true; return true;
} }
_cursor = checkpoint;
} }
else
// Lookahead: !<alpha>
else if (! isAlpha (_text[marker]))
{ {
token = _text.substr (marker, _cursor - marker); token = _text.substr (marker, _cursor - marker);
type = Lexer::Type::dom; type = Lexer::Type::dom;
return true; return true;
} }
_cursor = checkpoint;
} }
// [prefix]annotations. // [prefix]annotations.
@ -1310,6 +1318,8 @@ bool Lexer::isDOM (std::string& token, Lexer::Type& type)
} }
} }
} }
else
_cursor = checkpoint;
} }
_cursor = marker; _cursor = marker;
@ -1450,6 +1460,7 @@ bool Lexer::isAllDigits (const std::string& text)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// This is intentionally looking for a single token.
bool Lexer::isDOM (const std::string& text) bool Lexer::isDOM (const std::string& text)
{ {
Lexer lex (text); Lexer lex (text);