bool Scanner::scanInt (char c, Parser& parser, bool& cont) { assert(c != '\0'); std::string value; value += c; bool error = false; while (get (c)) { if (std::isdigit (c)) { value += c; } else if (c!='-' && isStringCharacter (c)) { error = true; value += c; } else if (c=='.') { if (error) { putback (c); break; } return scanFloat (value, parser, cont); } else { putback (c); break; } } if (error) { /// workaround that allows names to begin with digits /// \todo disable TokenLoc loc (mLoc); mLoc.mLiteral.clear(); cont = parser.parseName (value, loc, *this); return true; // return false; } TokenLoc loc (mLoc); mLoc.mLiteral.clear(); std::istringstream stream (value); int intValue = 0; stream >> intValue; cont = parser.parseInt (intValue, loc, *this); return true; }
bool Scanner::isStringCharacter (char c, bool lookAhead) { return std::isalpha (c) || std::isdigit (c) || c=='_' || /// \todo disable this when doing more stricter compiling c=='`' || c=='\'' || /// \todo disable this when doing more stricter compiling. Also, find out who is /// responsible for allowing it in the first place and meet up with that person in /// a dark alley. (c=='-' && (!lookAhead || isStringCharacter (mStream.peek(), false))); }
bool Scanner::scanName (std::string& name) { char c; bool error = false; while (get (c)) { if (!name.empty() && name[0]=='"') { if (c=='"') { name += c; break; } // ignoring escape sequences for now, because they are messing up stupid Windows path names. // else if (c=='\\') // { // if (!get (c)) // { // error = true; // mErrorHandler.error ("incomplete escape sequence", mLoc); // break; // } // } else if (c=='\n') { if (mIgnoreNewline) mErrorHandler.warning ("string contains newline character, make sure that it is intended", mLoc); else { error = true; mErrorHandler.error ("incomplete string or name", mLoc); break; } } } else if (!(c=='"' && name.empty())) { if (!isStringCharacter (c) && !(mTolerantNames && (c=='.' || c=='-'))) { putback (c); break; } } name += c; } return !error; }
bool Scanner::scanName (std::string& name) { char c; bool error = false; while (get (c)) { if (!name.empty() && name[0]=='"') { if (c=='"') { name += c; break; } // ignoring escape sequences for now, because they are messing up stupid Windows path names. // else if (c=='\\') // { // if (!get (c)) // { // error = true; // mErrorHandler.error ("incomplete escape sequence", mLoc); // break; // } // } else if (c=='\n') { error = true; mErrorHandler.error ("incomplete string or name", mLoc); break; } } else if (!(c=='"' && name.empty())) { if (!isStringCharacter (c)) { putback (c); break; } } name += c; } return !error; }