public static void AcceptNewLine(this ParserContext context) { if (context.CurrentCharacter == '\n') { context.AcceptCurrent(); } else if (context.CurrentCharacter == '\r') { context.AcceptCurrent(); if (context.CurrentCharacter == '\n') { context.AcceptCurrent(); } } }
public static void AcceptCharacters(this ParserContext context, int number) { for (int i = 0; i < number; i++) { context.AcceptCurrent(); } }
public static string AcceptUntil(this ParserContext context, SourceLocation location) { var builder = new StringBuilder(); while (context.CurrentLocation < location) { builder.Append(context.AcceptCurrent()); } return(builder.ToString()); }
public static void AcceptLine(this ParserContext context, bool includeNewLineSequence) { context.AcceptUntil('\r', '\n'); if (!includeNewLineSequence) { return; } if (context.CurrentCharacter == '\r') { context.AcceptCurrent(); if (context.CurrentCharacter == '\n') { context.AcceptCurrent(); } } else if (context.CurrentCharacter == '\n') { context.AcceptCurrent(); } }
protected void AcceptLineWithBlockComments(ParserContext context, SpanFactory spanFactory) { // Read to the end of the line checking for plan9 block comments bool keepReading = true; while (keepReading) { if (CharUtils.IsNewLine(context.CurrentCharacter)) { context.AcceptNewLine(); keepReading = false; } else if (!TryParseComment(spanFactory)) { context.AcceptCurrent(); } } }
public static bool Accept(this ParserContext context, string expected, bool caseSensitive, out SourceLocation?errorLocation, out char?errorChar) { errorLocation = null; errorChar = null; using (context.StartTemporaryBuffer()) { for (int i = 0; i < expected.Length; i++) { if (CharsEqual(expected[i], context.CurrentCharacter, caseSensitive)) { context.AcceptCurrent(); } else { errorLocation = context.CurrentLocation; errorChar = context.CurrentCharacter; context.RejectTemporaryBuffer(); return(false); } } context.AcceptTemporaryBuffer(); } return(true); }