public static void IgnoreWhiteSpaceAndCommentsToNextLine(this IPreprocessorReader rdr) { char ch; bool lineChangeFound; while (!rdr.EOF) { ch = rdr.Peek(); if (ch == '\n') { rdr.Ignore(1); break; } if (char.IsWhiteSpace(ch)) { rdr.Ignore(1); continue; } if (!rdr.IgnoreComments(out lineChangeFound)) { break; } if (lineChangeFound) { break; } } }
public static void IgnoreWhiteSpaceAndComments(this IPreprocessorReader rdr, bool stayOnSameLine) { char ch; bool lineChangeFound; while (!rdr.EOF) { ch = rdr.Peek(); if (stayOnSameLine && (ch == '\r' || ch == '\n')) { break; } if (char.IsWhiteSpace(ch)) { rdr.IgnoreWhile(stayOnSameLine ? WhiteNonEolChars : WhiteChars); continue; } if (!rdr.IgnoreComments(out lineChangeFound)) { break; } if (lineChangeFound && stayOnSameLine) { break; } } }
public static string PeekToken(this IPreprocessorReader rdr, bool stayOnSameLine) { bool lineChange; if (rdr.IgnoreComments(out lineChange)) { if (lineChange && stayOnSameLine) { return(null); } return(string.Empty); } var ch = rdr.Peek(); if ((ch == '\r' || ch == '\n') && stayOnSameLine) { return(null); } if (ch == ' ' || ch == '\t') { return(rdr.PeekUntil(c => c == ' ' || c == '\t')); } if (ch.IsWordChar(true)) { return(rdr.PeekIdentifier()); } if (char.IsDigit(ch)) { var gotDecimal = false; return(rdr.PeekUntil(c => { if (char.IsDigit(c)) { return true; } if (c == '.') { if (gotDecimal) { return false; } gotDecimal = true; return true; } return false; })); } if (ch == '\"' || ch == '\'') { var sb = new StringBuilder(); var lastCh = '\0'; var first = true; var gotEnd = false; sb.Append(rdr.PeekUntil(c => { if (gotEnd) { return(false); } if (first) { first = false; return(true); } if (c == ch && lastCh != '\\') { gotEnd = true; return(true); } if (c == '\\' && lastCh == '\\') { lastCh = '\0'; } else { lastCh = c; } return(true); })); return(sb.ToString()); } if (ch == '#') { var index = -1; return(rdr.PeekUntil(c => { index++; if (index == 0) { return c == '#'; } else if (index == 1) { return c.IsWordChar(true); } else { return c.IsWordChar(false); } })); } return(ch.ToString()); }
public static bool IgnoreComments(this IPreprocessorReader rdr, out bool lineChangeFound, bool multiLineOnly) { lineChangeFound = false; if (rdr.Peek() == '/') { var str = rdr.Peek(2); if (str == "/*") { rdr.Ignore(2); //rdr.IgnoreUntil(c => c != '/' && c != '*' && c != '\r' && c != '\n'); rdr.IgnoreUntil(_multiLineCommentBreakChars); char ch; while (!rdr.EOF) { ch = rdr.Peek(); if (ch == '*') { if (rdr.Peek(2) == "*/") { rdr.Ignore(2); return(true); } else { rdr.Ignore(1); } } else if (ch == '/') { bool lineChange; if (rdr.IgnoreComments(out lineChange, true)) { if (lineChange) { lineChangeFound = true; } } else { rdr.Ignore(1); } } else if (ch == '\r' || ch == '\n') { lineChangeFound = true; rdr.Ignore(1); } //rdr.IgnoreUntil(c => c != '/' && c != '*' && c != '\r' && c != '\n'); rdr.IgnoreUntil(_multiLineCommentBreakChars); } return(true); } else if (str == "//" && multiLineOnly == false) { //rdr.IgnoreUntil(c => c != '\r' && c != '\n'); rdr.IgnoreUntil(LineEndChars); return(true); } } return(false); }
public static bool IgnoreComments(this IPreprocessorReader rdr, out bool lineChangeFound) { return(rdr.IgnoreComments(out lineChangeFound, false)); }
public static bool IgnoreComments(this IPreprocessorReader rdr) { bool lineChange; return(rdr.IgnoreComments(out lineChange, false)); }