bool Parser::ParseComment(token& out, bool isBlockComment) { line = cur_line; column = GetColumn(); text.str += 2; // skip over the comment start if (isBlockComment) { // scan until */ for ( ; text.str < text.end; ++text.str) { char ch = *text.str; if (ch == '\r' || ch == '\n') { SkipNewLine(ch); continue; } else if (ch == '*' && text.str[1] == '/') { out.end = text.str += 2; return true; } } } else { // scan until \r\n or \n for ( ; text.str < text.end; ++text.str) { char ch = *text.str; if (ch == '\r' || ch == '\n') { out.end = text.str; SkipNewLine(ch); ++text.str; // skip \n return true; // done } } } return true; }
void LanguagePack::ParseLine(IStringReader *reader) { SkipWhitespace(reader); codepoint_t codepoint; if (reader->TryPeek(&codepoint)) { switch (codepoint) { case '#': SkipToEndOfLine(reader); break; case '[': ParseGroupObject(reader); break; case '<': ParseGroupScenario(reader); break; case '\r': case '\n': break; default: ParseString(reader); break; } SkipToEndOfLine(reader); SkipNewLine(reader); } }
TRISTATE CTextParser::ReadLine(CTextParser* pcLine) { char* szStart; char* szEnd; pcLine->Init(); ReturnErrorOnErrorAndFalse(FindStartOfLine()); szStart = mszParserPos; ReturnErrorOnErrorAndFalse(FindEndOfLine()); szEnd = mszParserPos; SkipNewLine(); if (mbOutsideText) { szEnd++; } pcLine->Init(szStart, (int)(szEnd - szStart)); pcLine->mbAnnotated = mbAnnotated; return TRITRUE; }
bool Parser::GetToken(token& out) { // trim leading whitespace first: for (; text.str < text.end; ++text.str) { char ch = *text.str; if (ch == ' ' || ch == '\t') continue; if (ch == '\r' || ch == '\n') SkipNewLine(ch); else break; // not ' ' or '\t', so finish trim } out.end = out.str = text.str; // mark down start and default end column = GetColumn(); for ( ; text.str < text.end; ++text.str) { char ch = *text.str; if (ch == '\r' || ch == '\n') { SkipNewLine(ch); continue; } if (ch == '/') { // possible comment start? char c2 = text.str[1]; if (c2 == '/' || c2 == '*') // line comment '//' or block comment '/*' return ParseComment(out, c2 == '*'); // parse the comment } else if (ch == '"') return ParseStringLiteral(out); // skip the literal else if (ch == '\'') return ParseCharLiteral(out); if (BreakerIndex[ch] == 1) // token starts with a breaker char { line = cur_line; column = GetColumn(); char c2 = *++text.str; char c3 = text.str[1]; if (c3 == '=' && ( (ch == '<' && c2 == '<')|| // <<= (ch == '>' && c2 == '>'))) // >>= { text.str += 2; // 3 char token parsed } else if ((c2 == '=' && ( ch == '<' || // <= ch == '>' || // >= ch == '=' || // == ch == '!' || // != ch == '+' || // += ch == '-' || // -= ch == '*' || // *= ch == '/' || // /= ch == '%' || // %= ch == '&' || // &= ch == '|' || // |= ch == '^' // ^= )) || (ch == '+' && c2 == '+') || // ++ (ch == '-' && c2 == '-') || // -- (ch == '-' && c2 == '>') || // -> (ch == '?' && c2 == '?') || // ?? (ch == '&' && c2 == '&') || // && (ch == '|' && c2 == '|') || // || (ch == '<' && c2 == '<') || // << (ch == '>' && c2 == '>') || // >> (ch == ':' && c2 == ':')) // :: { ++text.str; // 2 char token parsed } out.end = text.str; return true; // 1 char token parsed } // so this is a literal or a statement? return ParseStatement(out); } return false; // end of buffer }