void ASNLexer::LookupComments(void) { while ( true ) { char c = Char(); switch ( c ) { case ' ': case '\t': case '\r': SkipChar(); break; case '\n': SkipChar(); NextLine(); break; case '-': if ( Char(1) == '-' ) { // comments SkipChars(2); SkipComment(); break; } return; case '/': if ( Char(1) == '*' ) { // comments SkipChars(2); SkipComment(); break; } return; default: return; } } }
void Tokenizer::SkipToEndConditionPreprocessor() { do { wxChar ch = CurrentChar(); if (ch == _T('\'') || ch == _T('"') || ch == _T('/') || ch <= _T(' ')) { while (SkipWhiteSpace() || SkipString() || SkipComment()) ; ch = CurrentChar(); } if (ch == _T('#')) { MoveToNextChar(); while (SkipWhiteSpace() || SkipComment()) ; const wxChar current = CurrentChar(); const wxChar next = NextChar(); // #if if (current == _T('i') && next == _T('f')) SkipToEndConditionPreprocessor(); // #endif else if (current == _T('e') && next == _T('n')) { SkipToEOL(false); break; } } } while (MoveToNextChar()); }
bool Tokenizer::SkipUnwanted() { while (SkipWhiteSpace() || SkipComment()) ; wxChar c = CurrentChar(); const unsigned int startIndex = m_TokenIndex; if (c == _T('#')) { const PreprocessorType type = GetPreprocessorType(); if (type != ptOthers) { HandleConditionPreprocessor(type); c = CurrentChar(); } } // skip [XXX][YYY] if (m_State & tsSkipSubScrip) { while (c == _T('[') ) { SkipBlock('['); SkipWhiteSpace(); if (IsEOF()) return false; c = CurrentChar(); } } // skip the following = or ? if (m_State & tsSkipEqual) { if (c == _T('=')) { if (!SkipToOneOfChars(_T(",;}"), true, true, false)) return false; } } else if (m_State & tsSkipQuestion) { if (c == _T('?')) { if (!SkipToOneOfChars(_T(";}"), false, true)) return false; } } // skip the following white space and comments while (SkipWhiteSpace() || SkipComment()) ; if (startIndex != m_TokenIndex && CurrentChar() == _T('#')) return SkipUnwanted(); return NotEOF(); }
Namespace *SKS::GetNamespace(Position &pos, bool noName) { Namespace *name = new Namespace(); if(!noName) name->SetName(GetName(pos)); while(true) { if(islineEndOfFile(pos)) { break; } SkipComment(pos); if(isLineNamespaceEnd(pos)) { ExitNamespace(pos); break; } else if(isLineNamespace(pos)) { name->AddNamespace(GetNamespace(pos)); } else if(isLineKeyValue(pos)) { name->AddKeyValue(GetKeyValue(pos)); } else break; } return name; }
bool Tokenizer::SkipToEOL(bool nestBraces, bool skippingComment) { // skip everything until we find EOL while (1) { while (NotEOF() && CurrentChar() != '\n') { if (CurrentChar() == '/' && NextChar() == '*') { SkipComment(false); // don't skip whitespace after the comment if (skippingComment && CurrentChar() == '\n') { continue; // early exit from the loop } } if (nestBraces && CurrentChar() == _T('{')) ++m_NestLevel; else if (nestBraces && CurrentChar() == _T('}')) --m_NestLevel; MoveToNextChar(); } wxChar last = PreviousChar(); // if DOS line endings, we 've hit \r and we skip to \n... if (last == '\r') last = m_Buffer.GetChar(m_TokenIndex - 2); if (IsEOF() || last != '\\') break; else MoveToNextChar(); } if (IsEOF()) return false; return true; }
int GetNextToken() { EatWhitespace(); if (isalpha(LastChar)) { return GetIdentifier(); } if (isdigit(LastChar) || LastChar == '.') { return GetNumber(); } if (LastChar == '#') { SkipComment(); if (LastChar != EOF) { return GetNextToken(); } } if (LastChar == EOF) { return static_cast<int>(Token::Eof); } int ch = LastChar; LastChar = getchar(); return ch; }
void Handle(char c) { switch(state) { case State::Default: ReadDefault(c); break; case State::ReadTagName: ReadTagName(c); break; case State::SkipTag: SkipTag(c); break; case State::ReadTag: ReadTag(c); break; case State::ReadAttribute: ReadAttribute(c); break; case State::SkipAttribute: SkipAttribute(c); break; case State::SkipComment: SkipComment(c); break; } }
//========================================================================== // ReadToken //========================================================================== int ReadToken() { int ch = FGetC(); char *out = token; memset(token, 0, sizeof(token)); if(endOfSource) return false; // Skip whitespace and comments in the beginning. while((ch == '#' || isspace(ch))) { if(ch == '#') SkipComment(); ch = FGetC(); if(endOfSource) return false; } // Always store the first character. *out++ = ch; if(STOPCHAR(ch)) { // Stop here. *out = 0; return true; } while(!STOPCHAR(ch) && !endOfSource) { // Store the character in the buffer. ch = FGetC(); *out++ = ch; } *(out-1) = 0; // End token. // Put the last read character back in the stream. FUngetC(ch); return true; }
bool Tokenizer::SkipBlock(const wxChar& ch) { // skip blocks () [] {} <> wxChar match; switch (ch) { case '(': match = ')'; break; case '[': match = ']'; break; case '{': match = '}'; break; case '<': match = '>'; break; default : return false; } MoveToNextChar(); int nestLevel = 1; // counter for nested blocks (xxx()) while (NotEOF()) { while (SkipWhiteSpace() || SkipString() || SkipComment()) ; if (CurrentChar() == ch) ++nestLevel; else if (CurrentChar() == match) --nestLevel; MoveToNextChar(); if (nestLevel == 0) break; } return NotEOF(); }
bool Tokenizer::IsMacroDefined() { while (SkipWhiteSpace() || SkipComment()) ; int id = m_TokensTree->TokenExists(DoGetToken(), -1, tkPreprocessor); SkipToEOL(false); return (id != -1); }
/* GetChar - get the next character */ int GetChar(ParseContext *c) { int ch; /* check for being in a comment */ if (c->inComment) { if (!SkipComment(c)) return EOF; c->inComment = VMFALSE; } /* loop until we find a non-comment character */ for (;;) { /* get the next character */ if ((ch = XGetC(c)) == EOF) return EOF; /* check for a comment */ else if (ch == '/') { if ((ch = XGetC(c)) == '/') { while ((ch = XGetC(c)) != EOF) ; } else if (ch == '*') { if (!SkipComment(c)) { c->inComment = VMTRUE; return EOF; } } else { UngetC(c); ch = '/'; break; } } /* handle a normal character */ else break; } /* return the character */ return ch; }
void Tokenizer::SpliteArguments(wxArrayString& results) { while (SkipWhiteSpace() || SkipComment()) ; if (CurrentChar() != _T('(')) return; MoveToNextChar(); // Skip the '(' int level = 1; // include '(' wxString piece; while (NotEOF()) { wxString token = DoGetToken(); if (token.IsEmpty()) break; if (token == _T("(")) ++level; else if (token == _T(")")) --level; if (token == _T(",")) { results.Add(piece); piece.Clear(); } else if (level != 0) { if (!piece.IsEmpty() && piece.Last() > _T(' ')) piece << _T(" "); piece << token; } if (level == 0) { if (!piece.IsEmpty()) results.Add(piece); break; } while (SkipWhiteSpace() || SkipComment()) ; } }
// SkipWhiteSpaceAndComments //------------------------------------------------------------------------------ void BFFIterator::SkipWhiteSpaceAndComments() { SkipWhiteSpace(); while ( IsAtComment() ) { SkipComment(); SkipWhiteSpace(); } }
bool Tokenizer::SkipToOneOfChars(const wxChar* chars, bool supportNesting) { // skip everything until we find any one of chars while (1) { while (NotEOF() && !CharInString(CurrentChar(), chars)) { if (CurrentChar() == '"' || CurrentChar() == '\'') { // this is the case that match is inside a string! wxChar ch = CurrentChar(); MoveToNextChar(); SkipToChar(ch); } MoveToNextChar(); // make sure we skip comments if (CurrentChar() == '/') SkipComment(); // this will decide if it is a comment // use 'while' here to cater for consecutive blocks to skip (e.g. sometemplate<foo>(bar) // must skip <foo> and immediately after (bar)) // because if we don't, the next block won't be skipped ((bar) in the example) leading to weird // parsing results bool done = false; while (supportNesting && !done) { switch (CurrentChar()) { case '{': SkipBlock('{'); break; case '(': SkipBlock('('); break; case '[': SkipBlock('['); break; case '<': // don't skip if << operator if (NextChar() == '<') MoveToNextChar(2); // skip it and also the next '<' or the next '<' leads to a SkipBlock('<'); else SkipBlock('<'); break; default: done = true; break; } } } if (PreviousChar() != '\\') break; else { // check for "\\" if (m_TokenIndex - 2 >= 0 && m_Buffer.GetChar(m_TokenIndex - 2) == '\\') break; } MoveToNextChar(); } if (IsEOF()) return false; return true; }
void TFunctionScanner::ReadFunctionArgs(const TChar*& text) { SkipWhiteSpace(text); if (*text == '(') { while (*text != ')') { if (IsString(text)) SkipString(text); else if (IsComment(text)) SkipComment(text); else NextChar(text); } NextChar(text); fScanState = kFunctionArgs; } else { while (1) { TChar ch = *text; if (IsString(text)) SkipString(text); else if (IsComment(text)) SkipComment(text); else { NextChar(text); if (ch == ';') { fScanState = kTopLevel; break; } } } } }
// This function return the next character not including comments void SKS::Next(Position &pos, bool skipComment) { if(m_fileContents[pos.pos] == '\n') { pos.line++; pos.colum = 0; } ++pos.pos; if(skipComment) SkipComment(pos); }
/****************************************************************************** * skip newline *****************************************************************************/ int SkipNewline() { int old = line_number; SkipComment(); if (line_number - old > 0) return 1; else { PrintError("Newline expected"); return 0; } }
PreprocessorType Tokenizer::GetPreprocessorType() { const unsigned int undoIndex = m_TokenIndex; const unsigned int undoLine = m_LineNumber; MoveToNextChar(); while (SkipWhiteSpace() || SkipComment()) ; const wxString token = DoGetToken(); switch (token.Len()) { case 2: if (token == TokenizerConsts::kw_if) return ptIf; break; case 4: if (token == TokenizerConsts::kw_else) return ptElse; else if (token == TokenizerConsts::kw_elif) return ptElif; break; case 5: if (token == TokenizerConsts::kw_ifdef) return ptIfdef; else if (token == TokenizerConsts::kw_endif) return ptEndif; break; case 6: if (token == TokenizerConsts::kw_ifndef) return ptIfndef; break; case 7: if (token == TokenizerConsts::kw_elifdef) return ptElifdef; break; case 8: if (token == TokenizerConsts::kw_elifndef) return ptElifndef; break; } m_TokenIndex = undoIndex; m_LineNumber = undoLine; return ptOthers; }
void Tokenizer::SkipToNextConditionPreprocessor() { do { wxChar ch = CurrentChar(); if (ch == _T('\'') || ch == _T('"') || ch == _T('/') || ch <= _T(' ')) { while (SkipWhiteSpace() || SkipString() || SkipComment()) ; ch = CurrentChar(); } if (ch == _T('#')) { const unsigned int undoIndex = m_TokenIndex; const unsigned int undoLine = m_LineNumber; MoveToNextChar(); while (SkipWhiteSpace() || SkipComment()) ; const wxChar current = CurrentChar(); const wxChar next = NextChar(); // #if if (current == _T('i') && next == _T('f')) SkipToEndConditionPreprocessor(); // #else #elif #elifdef #elifndef #endif else if (current == _T('e') && (next == _T('l') || next == _T('n'))) { m_TokenIndex = undoIndex; m_LineNumber = undoLine; break; } } } while (MoveToNextChar()); }
void CppScanner::GetNext() { SetEmpty(); SkipWhitespace(); if (f.Get() == '/') { SkipComment(); SkipWhitespace(); } char ch = f.Get(); if (IsNumber(ch) || (ch == '+') || (ch == '-')) GetNumber(); else if (IsAlpha(ch)) GetName(); else if (ch == '(' || ch == ')' || ch == '<' || ch == '>' || ch == '=' || ch == ',' || ch == ';' || ch == '&') { type = CToken::DELIMITER; delimiter = ch; f.GetNext(); } else throw CPError(CPError::UNKNOWN_CHARACTER); }
int KLScript::SkipComment(const KLString& Script) { while (isspace(Script[LastProcess])) ++LastProcess; if (Script[LastProcess] == '#') { while (Script[LastProcess] && Script[LastProcess] != '\n') ++LastProcess; SkipComment(Script); } return LastProcess; }
void CppScanner::SkipTo(const char *name) { if (name[0] == 0) return; while (true) { while (name[0] != f.Get()) { if (f.Get() == '/') SkipComment(); else f.GetNext(); } unsigned int i = 0; while(true) { if (name[i] == 0) return; if (f.Get() == '/') { SkipComment(); break; } if (f.Get() != name[i]) break; f.GetNext(); i++; } } }
void Tokenizer::ReadParentheses(wxString& str, bool trimFirst) { str.Clear(); // e.g. #define AAA /*args*/ (x) x // we want read "(x)", so, we need trim the unwanted before the "(x)" if (trimFirst) { while (SkipWhiteSpace() && SkipComment()) ; if (CurrentChar() != _T('(')) return; } ReadParentheses(str); }
KLString KLScript::GetName(const KLString& Script) { int Start = SkipComment(Script); while (isalnum(Script[LastProcess])) ++LastProcess; int Stop = LastProcess; if (Script[LastProcess] != ';' && Script[LastProcess] != ',') { while (isspace(Script[LastProcess])) ++LastProcess; } return Script.Part(Start, Stop); }
KLString KLScript::GetParam(const KLString& Script) { int Start = SkipComment(Script); while (Script[LastProcess] != ';' && Script[LastProcess] != '#' && Script[LastProcess] != ',' && Script[LastProcess] != 0) ++LastProcess; KLString Param = Script.Part(Start, LastProcess); if (Script[LastProcess] == '#') return Param + GetParam(Script); while (isspace(Script[LastProcess])) ++LastProcess; return Param; }
bool Tokenizer::SkipBlock(const wxChar& ch) { // skip blocks () [] {} <> wxChar match; switch (ch) { case '(': match = ')'; break; case '[': match = ']'; break; case '{': match = '}'; break; case '<': match = '>'; break; default : return false; } MoveToNextChar(); int count = 1; // counter for nested blocks (xxx()) while (NotEOF()) { bool noMove = false; if (CurrentChar() == '/') SkipComment(); // this will decide if it is a comment if (CurrentChar() == '"' || CurrentChar() == '\'') { // this is the case that match is inside a string! wxChar ch = CurrentChar(); MoveToNextChar(); SkipToChar(ch); MoveToNextChar(); // don't move to next char below if concatenating strings (e.g. printf("" "")) if (CurrentChar() == '"' || CurrentChar() == '\'') noMove = true; } if (CurrentChar() == ch) ++count; else if (CurrentChar() == match) --count; if (!noMove) MoveToNextChar(); if (count == 0) break; } if (IsEOF()) return false; return true; }
// expect we are not in a C-string. bool Tokenizer::SkipToOneOfChars(const wxChar* chars, bool supportNesting, bool skipPreprocessor, bool skipAngleBrace) { while (NotEOF() && !CharInString(CurrentChar(), chars)) { MoveToNextChar(); while (SkipString() || SkipComment()) ; // use 'while' here to cater for consecutive blocks to skip (e.g. sometemplate<foo>(bar) // must skip <foo> and immediately after (bar)) // because if we don't, the next block won't be skipped ((bar) in the example) leading to weird // parsing results bool done = false; while (supportNesting && !done) { switch (CurrentChar()) { case '#': if (skipPreprocessor) SkipToEOL(true); else done = true; break; case '{': SkipBlock('{'); break; case '(': SkipBlock('('); break; case '[': SkipBlock('['); break; case '<': // don't skip if << operator if (skipAngleBrace) { if (NextChar() == '<') MoveToNextChar(2); // skip it and also the next '<' or the next '<' leads to a SkipBlock('<'); else SkipBlock('<'); break; } default: done = true; break; } } } return NotEOF(); }
void SkipWhiteSpace() { register char c; PrevFilePtr = FilePtr; while (WS[(unsigned char)*FilePtr]) FilePtr++; while(1) { while (WS[(unsigned char)*FilePtr]) FilePtr++; if (SkipCommentOn == 1) { if (*FilePtr == ';') { SkipLine(); continue; } if (*FilePtr == '/') { c = *(FilePtr+1); if ( c == '/') { SkipLine(); continue; } if (c == '*') { SkipComment(); continue; } } } break; } }
bool Tokenizer::SkipComment(bool skipWhiteAtEnd) // = true { // C/C++ style comments bool is_comment = CurrentChar() == '/' && (NextChar() == '/' || NextChar() == '*'); if (!is_comment) return true; bool cstyle = NextChar() == '*'; MoveToNextChar(2); while (1) { if (!cstyle) { if (!SkipToEOL(false, true)) return false; MoveToNextChar(); break; } else { if (SkipToChar('/')) { if (PreviousChar() == '*') { MoveToNextChar(); break; } MoveToNextChar(); } else return false; } } if (IsEOF()) return false; if (skipWhiteAtEnd && !SkipWhiteSpace()) return false; return CurrentChar() == '/' ? SkipComment() : true; // handle chained comments }
void P6::Read(const char* filename) { ifstream inBinaryFile(filename, ios::binary | ios::in); if (!inBinaryFile) { cerr << "Cannot read P6 file! \n"; return; } inBinaryFile.seekg(0, ios::beg); inBinaryFile.getline(magic, 3); SkipComment(inBinaryFile); char ch; inBinaryFile >> width >> height >> max_num; inBinaryFile.get(ch); this->setMagic(magic); this->setWidth(width); this->setHeight(height); this->setMaxNum(max_num); pixels = createPixelsArray(height, width); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { inBinaryFile.read((char*)&r, sizeof(char)); inBinaryFile.read((char*)&g, sizeof(char)); inBinaryFile.read((char*)&b, sizeof(char)); pixels[i][j].setRed(r); pixels[i][j].setGreen(g); pixels[i][j].setBlue(b); } } inBinaryFile.close(); }