예제 #1
0
 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();
         }
     }
 }
예제 #2
0
 public static void AcceptCharacters(this ParserContext context, int number)
 {
     for (int i = 0; i < number; i++)
     {
         context.AcceptCurrent();
     }
 }
예제 #3
0
        public static string AcceptUntil(this ParserContext context, SourceLocation location)
        {
            var builder = new StringBuilder();

            while (context.CurrentLocation < location)
            {
                builder.Append(context.AcceptCurrent());
            }
            return(builder.ToString());
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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();
                }
            }
        }
예제 #6
0
 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);
 }
예제 #7
0
 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();
         }
     }
 }