// scans for a comment bool opScanner::Comment(const inputtype& Input, int& current) { int size = Input.Size(); if (current + 1 < size) { int one = current; int two = current + 1; if (Input[one] == '/' && Input[two] == '/') { opToken newToken(T_COMMENT, "//", CurrentLine); current += 2; while (current < size) { one = current; if (IsNewline(Input[one])) break; newToken.Value += Input[one]; ++current; } Tokens.PushBack(newToken); return true; } } return false; }
static inline void AdvanceToEndOfLine(GLTokenizer* Tokenizer) { while(*Tokenizer->At && !IsNewline(*Tokenizer->At)) { Tokenizer->At++; } }
static void redraw_remark_lines(void) { int i=0,tls = line_space, j; Char *temptxt = text; if (!remark_is_open || !text) return; line_space = 3; set_output_window(&remark_win); set_margin(draw_pos); set_x_y(0,MARGIN); if (scrollbar) j = scrollbar_line(scrollbar,0); else j=0; while (i<j) { while (*temptxt && !IsNewline(*temptxt)) temptxt++; i++; if (!*temptxt) i=j; else temptxt++; } if (i==selected_line) set_text_mode(Reverse); while (*temptxt && i<j+nr_visible) { if (IsNewline(*temptxt)) { if (where_x() && where_x()<black_width) thinspace(black_width-where_x()); if (i==selected_line) set_text_mode(Normal); out_char(*temptxt); i++; if (i==selected_line) set_text_mode(Reverse); } else out_char(*temptxt); temptxt++; } if (where_x() && where_x()<black_width) thinspace(black_width-where_x()); out_char(Newline); clear_to_end_of_page(); unset_output_window(); line_space = tls; }
// newline - parses a newline bool opScanner::Newline(const inputtype& Input, int& current) { char c = Input[current]; if (!IsNewline(c)) return false; opToken newToken(T_NEWLINE, '\n', CurrentLine); ++CurrentLine; Tokens.PushBack(newToken); ++current; return true; }
/* IScanner */ static inline int ParseCommentLine(struct IParse *parse) { ParseSkip(parse); if (!IsComment(parse)) { return 0; } int code = 0; while ((code = ParseRead(parse)) != -1) { if (IsNewline(code)) { return 1; } } return 1; }
// scans for strings bool opScanner::String(const inputtype& Input, int& current) { char start = Input[current]; int size = Input.Size(); int count = 0; if (start == '\"' || start == '\'') { opToken newToken((start == '\"') ? T_STRING : T_CHAR, start, CurrentLine); char c, last; ++count; ++current; c = start; while (current < size) { last = c; c = Input[current]; if (IsNewline(c)) { opError::UnboundedStringError(Root, CurrentLine); ScanError = true; return false; } // If we reach an end token, process it. if (c == start) { // Handle special cases. if (last != '\\' || (last == '\\' && count >= 3 && newToken.Value[count - 2] == '\\')) { newToken.Value += c; ++current; Tokens.PushBack(newToken); return true; } } newToken.Value += c; ++current; ++count; } opError::UnboundedStringError(Root, CurrentLine); ScanError = true; } return false; }
// scans for a c-style comment bool opScanner::CComment(const inputtype& Input, int& current) { int size = Input.Size(); if (current + 1 < size) { int one = current; int two = current + 1; if (Input[one] == '/' && Input[two] == '*') { opToken newToken(T_CCOMMENT, "/*", CurrentLine); bool bFoundEnd = false; current += 2; while (current + 1 < size) { one = current; two = current + 1; if (Input[one] == '*' && Input[two] == '/') { newToken.Value += "*/"; current += 2; bFoundEnd = true; break; } else { if (IsNewline(Input[one])) ++CurrentLine; newToken.Value += Input[one]; ++current; } } // check for unbounded comments if (bFoundEnd) { Tokens.PushBack(newToken); return true; } else { opError::UnboundedCommentError(Root, newToken.Line); ScanError = true; } } } return false; }
PPDERROR PARSEROBJ_SkipLine( PPARSEROBJ pParserObj, PFILEOBJ pFileObj ) /*++ Routine Description: Skip to the end of line. Arguments: pParserObj - pointer to parser object pFileObj - pointer to input file object Return Value: PPDERR_NONE - a line was successfully skipped PPDERR_xxx - an error occured --*/ { PPDERROR err; char ch; do { // Read one character err = FILEOBJ_GetChar(pFileObj, &ch); // Repeat while the character is not newline // and there is no error } while (err == PPDERR_NONE && ! IsNewline(ch)); return err; }
static int exec(FILE* fp, ENC_INFO* einfo) { #define NCOL 8 int c, val, enc; enc = einfo->num; fprintf(fp, "static const unsigned short Enc%s_CtypeTable[256] = {\n", einfo->name); for (c = 0; c < 256; c++) { val = 0; if (IsNewline(enc, c)) val |= BIT_CTYPE_NEWLINE; if (IsAlpha (enc, c)) val |= (BIT_CTYPE_ALPHA | BIT_CTYPE_ALNUM); if (IsBlank (enc, c)) val |= BIT_CTYPE_BLANK; if (IsCntrl (enc, c)) val |= BIT_CTYPE_CNTRL; if (IsDigit (enc, c)) val |= (BIT_CTYPE_DIGIT | BIT_CTYPE_ALNUM); if (IsGraph (enc, c)) val |= BIT_CTYPE_GRAPH; if (IsLower (enc, c)) val |= BIT_CTYPE_LOWER; if (IsPrint (enc, c)) val |= BIT_CTYPE_PRINT; if (IsPunct (enc, c)) val |= BIT_CTYPE_PUNCT; if (IsSpace (enc, c)) val |= BIT_CTYPE_SPACE; if (IsUpper (enc, c)) val |= BIT_CTYPE_UPPER; if (IsXDigit(enc, c)) val |= BIT_CTYPE_XDIGIT; if (IsWord (enc, c)) val |= BIT_CTYPE_WORD; if (IsAscii (enc, c)) val |= BIT_CTYPE_ASCII; if (c % NCOL == 0) fputs(" ", fp); fprintf(fp, "0x%04x", val); if (c != 255) fputs(",", fp); if (c != 0 && c % NCOL == (NCOL-1)) fputs("\n", fp); else fputs(" ", fp); } fprintf(fp, "};\n"); return 0; }
PPDERROR PARSEROBJ_ParseValue( PPARSEROBJ pParserObj, PFILEOBJ pFileObj, PSTR pCh ) /*++ Routine Description: Parse the entry value. Arguments: pParserObj - pointer to the parser object pFileObj - pointer to input file object pCh - placeholder for returning the entry value terminating character Return Value: PPDERR_NONE - entry value was parsed successfully PPDERR_xxx - an error occured --*/ { PPDERROR err; BOOL bQuoted; PBUFOBJ pBufObj = & pParserObj->value; // Skip over any leading spaces do { err = FILEOBJ_GetChar(pFileObj, pCh); if (err != PPDERR_NONE) return err; } while (IsSpace(*pCh)); // Check to see if the first character is a '"'. // If it's a '"', then parse a quoted value (which // can span multiple lines) until the matching quote // is found. If the first character is not a quote, // the parse a normal string value until a newline // is found. if (*pCh == QUOTE_CHAR) { bQuoted = TRUE; pParserObj->valueType = QUOTED_VALUE; err = FILEOBJ_GetChar(pFileObj, pCh); } else { bQuoted = FALSE; pParserObj->valueType = STRING_VALUE; } for ( ; ; ) { // Read characters from the file until one of the // following condition is true: // an error occured // found a '"' when parsing a quoted value // found a newline or '/' when parsing a normal value if ((err != PPDERR_NONE) || (bQuoted && *pCh == QUOTE_CHAR) || (!bQuoted && (IsNewline(*pCh) || *pCh == XLATION_CHAR))) { break; } // Add the character to the buffer if (BUFOBJ_AddChar(pBufObj, *pCh) != PPDERR_NONE) { PSTR pNewBuffer; // The value string is longer than what our // buffer can hold. Expand the buffer by // DefaultValueLen. pNewBuffer = (PSTR) MEMALLOC(pBufObj->maxlen + 1 + DefaultValueLen); if (pNewBuffer == NULL) { DBGERRMSG("MEMALLOC"); return PPDERR_MEM; } else { memset(pNewBuffer, 0, pBufObj->maxlen + 1 + DefaultValueLen); } // Copy over the previous buffer contents memcpy(pNewBuffer, pBufObj->pBuffer, pBufObj->curlen); // Free the previous buffer MEMFREE(pBufObj->pBuffer); // Switch to the new buffer and update the buffer length. pBufObj->pBuffer = pNewBuffer; pBufObj->maxlen += DefaultValueLen; // Try adding the character to the buffer again. err = BUFOBJ_AddChar(pBufObj, *pCh); ASSERT(err == PPDERR_NONE); } // Read the next character from the file err = FILEOBJ_GetChar(pFileObj, pCh); } // Null-terminate the value string pBufObj->pBuffer[pBufObj->curlen] = '\0'; // Skip the remaining characters on the line // (which should be a translation string). if (err == PPDERR_NONE && ! IsNewline(*pCh)) err = PARSEROBJ_SkipLine(pParserObj, pFileObj); // Handle symbol value if (pParserObj->valueType == STRING_VALUE && *(pBufObj->pBuffer) == SYMBOL_CHAR) pParserObj->valueType = SYMBOL_VALUE; return err; }
PPDERROR PARSEROBJ_ParseKeyword( PPARSEROBJ pParserObj, PFILEOBJ pFileObj, PSTR pCh ) /*++ Routine Description: Parse the main keyword. Arguments: pParserObj - pointer to the parser object pFileObj - pointer to input file object pCh - placeholder for returning the main keyword terminating character Return Value: PPDERR_NONE - main keyword was parsed successfully PPDERR_xxx - an error occured --*/ { PPDERROR err; // Find the first keyword character after '*' for ( ; ; ) { // Read a character from the file object err = FILEOBJ_GetChar(pFileObj, pCh); if (err != PPDERR_NONE) return err; if (*pCh == KEYWORD_CHAR) { // Get the first keyword character err = FILEOBJ_GetChar(pFileObj, pCh); if (err != PPDERR_NONE) return err; // If it's not a '%', start parsing the keyword. if (*pCh != COMMENT_CHAR) break; } else { if (! IsNewline(*pCh)) { DBGMSG(DBG_LEVEL_VERBOSE, "Lines not starting with a '*' are discarded\n"); } } if (! IsNewline(*pCh)) { // If the line does not start with a '*' or // it starts with "*%", then skip the line. err = PARSEROBJ_SkipLine(pParserObj, pFileObj); if (err != PPDERR_NONE) return err; } } // Collect characters into the main keyword buffer return BUFOBJ_GetString( & pParserObj->keyword, pFileObj, pCh, CC_KEYWORD); }
PPDERROR PARSEROBJ_ParseEntry( PPARSEROBJ pParserObj, PFILEOBJ pFileObj ) /*++ Routine Description: Parse one entry out of a PPD file. The parse results (main keyword, option, translation string, and value) are stored in the parser object. Arguments: pParserObj - Pointer to a parser objct. pFileObj - Pointer to a file object. Return Value: PPDERR_NONE - a PPD entry was successfully parsed PPDERR_EOF - encountered end-of-file PPDERR_xxx - other error conditions --*/ { PPDERROR err; char ch; // Reset the parser object to its initial state BUFOBJ_Reset(& pParserObj->keyword); BUFOBJ_Reset(& pParserObj->option); BUFOBJ_Reset(& pParserObj->xlation); BUFOBJ_Reset(& pParserObj->value); pParserObj->valueType = NO_VALUE; // Parse the main keyword. err = PARSEROBJ_ParseKeyword(pParserObj, pFileObj, &ch); // If the main keyword is terminated by a space, // then skip over any trailing spaces. while (err == PPDERR_NONE && IsSpace(ch)) { err = FILEOBJ_GetChar(pFileObj, &ch); } if (err != PPDERR_NONE) return err; // Decide what to do next based on the first non-space // character after the main keyword. if (IsNewline(ch)) { // If the main keyword is terminated by a newline, // then the entry only has a main keyword. return PPDERR_NONE; } if (ch != SEPARATOR_CHAR) { // Look for the option keyword next. err = PARSEROBJ_ParseOption(pParserObj, pFileObj, &ch); // If the option keyword is terminated by a space, // then skip over any trailing spaces. while (err == PPDERR_NONE && IsSpace(ch)) { err = FILEOBJ_GetChar(pFileObj, &ch); } if (err != PPDERR_NONE) return err; // Decide what to do next based on the first non-space // character after the option keyword. if (ch == XLATION_CHAR) { // The option keyword is terminated by a '/'. // Look for translation string next. err = PARSEROBJ_ParseXlation(pParserObj, pFileObj, &ch); if (err != PPDERR_NONE) return err; } // The option keyword and/or translation string must // be terminated by a ':'. If not, return syntax error. if (ch != SEPARATOR_CHAR) { DBGMSG1(DBG_LEVEL_ERROR, "Missing ':' in *%s entry\n", BUFOBJ_Buffer(& pParserObj->keyword)); return PPDERR_SYNTAX; } } return PARSEROBJ_ParseValue(pParserObj, pFileObj, &ch); }
/** \brief Read the next token from the string. */ ptr_tok_type TokenReader::ReadNextToken() { assert(m_pParser); SkipCommentsAndWhitespaces(); int token_pos = m_nPos; ptr_tok_type pTok; // Check for end of expression if (IsEOF(pTok)) return Store(pTok, token_pos); if (IsNewline(pTok)) return Store(pTok, token_pos); if (!(m_nSynFlags & noOPT) && IsOprt(pTok)) return Store(pTok, token_pos); // Check for user defined binary operator if (!(m_nSynFlags & noIFX) && IsInfixOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators if (IsValTok(pTok)) return Store(pTok, token_pos); // Check for values / constant tokens if (IsBuiltIn(pTok)) return Store(pTok, token_pos); // Check built in operators / tokens if (IsVarOrConstTok(pTok)) return Store(pTok, token_pos); // Check for variable tokens if (IsFunTok(pTok)) return Store(pTok, token_pos); if (!(m_nSynFlags & noPFX) && IsPostOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators // 2.) We have found no token, maybe there is a token that we don't expect here. // Again call the Identifier functions but this time only those we don't expect // to find. if ((m_nSynFlags & noOPT) && IsOprt(pTok)) return Store(pTok, token_pos); // Check for user defined binary operator if ((m_nSynFlags & noIFX) && IsInfixOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators if ((m_nSynFlags & noPFX) && IsPostOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators // </ibg> // Now we are in trouble because there is something completely unknown.... // Check the string for an undefined variable token. This is done // only if a flag is set indicating to ignore undefined variables. // This is a way to conditionally avoid an error if undefined variables // occur. The GetExprVar function must supress the error for undefined // variables in order to collect all variable names including the // undefined ones. if ((m_pParser->m_bIsQueryingExprVar || m_pParser->m_bAutoCreateVar) && IsUndefVarTok(pTok)) return Store(pTok, token_pos); // Check for unknown token // // !!! From this point on there is no exit without an exception possible... // string_type sTok; int iEnd = ExtractToken(m_pParser->ValidNameChars(), sTok, m_nPos); ErrorContext err; err.Errc = ecUNASSIGNABLE_TOKEN; err.Expr = m_sExpr; err.Pos = m_nPos; if (iEnd != m_nPos) err.Ident = sTok; else err.Ident = m_sExpr.substr(m_nPos); throw ParserError(err); }
static inline int IsWhitespaceOrNewline(char c) { int Result = IsNewline(c) || IsWhitespace(c); return Result; }
static tchar SkipWhite( TidyConfigImpl* config ) { while ( IsWhite(config->c) && !IsNewline(config->c) ) config->c = GetC( config ); return config->c; }