Ejemplo n.º 1
0
        private IEnumerable <CharPos> ParseText(ITextChars tc)
        {
            while (!tc.EndOfLine)
            {
                if (tc.Char() == '#')
                {
                    tc.SkipRemainder();
                }
                else if ((tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"') ||
                         (tc.Char() == '\'' && tc.NChar() == '\'' && tc.NNChar() == '\''))
                {
                    this.status    = stMultiLineString;
                    this.quoteChar = tc.Char();
                    tc.Skip(3);
                    this.ParseMultiLineString(tc);
                }
                else if (tc.Char() == '\'' || tc.Char() == '"')
                {
                    this.status    = stString;
                    this.quoteChar = tc.Char();
                    tc.Next();
                    this.ParseString(tc);
                }
                else if (lang.BraceList.IndexOf(tc.Char()) >= 0)
                {
                    yield return(new CharPos(tc.Char(), tc.AbsolutePosition));

                    tc.Next();
                }
                else
                {
                    tc.Next();
                }
            }
        }
Ejemplo n.º 2
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while (!tc.EndOfLine)
     {
         // multi-line comment
         if (tc.Char() == '/' && tc.NChar() == '*')
         {
             this.status = stMultiLineComment;
             tc.Skip(2);
             this.ParseMultiLineComment(tc);
         }
         else if (tc.Char() == '/' && tc.NChar() == '/')
         {
             tc.SkipRemainder();
         }
         else if (tc.Char() == '@' && tc.NChar() == '"')
         {
             this.status = stMultiLineString;
             tc.Skip(2);
             this.ParseMultiLineString(tc);
         }
         else if (tc.Char() == '$' && tc.NChar() == '"')
         {
             // Roslyn interpolated string
             this.parsingExpression = false;
             this.status            = stIString;
             tc.Skip(2);
             return(this.ParseInterpolatedString(tc, ref pos));
         }
         else if (tc.Char() == '$' && tc.NChar() == '@' && tc.NNChar() == '"')
         {
             this.status = stMultiLineString;
             tc.Skip(3);
             this.ParseMultiLineString(tc);
         }
         else if (tc.Char() == '"')
         {
             this.status = stString;
             tc.Next();
             this.ParseString(tc);
         }
         else if (tc.Char() == '\'')
         {
             this.status = stString;
             tc.Next();
             this.ParseCharLiteral(tc);
         }
         else if (this.BraceList.IndexOf(tc.Char()) >= 0)
         {
             pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
 public string Parse(ITextChars tc)
 {
     SkipWhitespace(tc);
     if (tc.Char() == '/' && tc.NChar() == '/')
     {
         // C single line comment
         tc.Skip(2);
         return(TrimmedRemainder(tc));
     }
     else if (tc.Char() == '/' && tc.NChar() == '*')
     {
         // C multi line comment
         tc.Skip(2);
         return(TrimmedMinus(tc, "*/"));
     }
     else if (tc.Char() == '(' && tc.NChar() == '*')
     {
         // F# multi line comment
         tc.Skip(2);
         return(TrimmedMinus(tc, "*)"));
     }
     else if (tc.Char() == '-' && tc.NChar() == '-')
     {
         // SQL single line comment
         tc.Skip(2);
         return(TrimmedRemainder(tc));
     }
     else if (tc.Char() == '#')
     {
         // Python single line comment
         tc.Skip(1);
         return(TrimmedRemainder(tc));
     }
     else if (tc.Char() == '\'')
     {
         // VB single line comment
         tc.Skip(1);
         return(TrimmedRemainder(tc));
     }
     else if (tc.Char() == '<' && tc.NChar() == '!' && tc.NNChar() == '-')
     {
         //  XML comment
         tc.Skip(3);
         if (tc.Char() == '-')
         {
             tc.Next();
             return(TrimmedMinus(tc, "-->"));
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 // we assume endChars is 2 or 3, which is the most common case
 private string TrimmedMinus(ITextChars tc, String t)
 {
     StringBuilder buffer = new StringBuilder();
       while ( !tc.EndOfLine ) {
     if ( tc.Char() == t[0] && tc.NChar() == t[1] ) {
       if ( t.Length <= 2 || tc.NNChar() == t[2] ) {
     break;
       }
     }
     buffer.Append(tc.Char());
     tc.Next();
       }
       return buffer.ToString().Trim();
 }
Ejemplo n.º 5
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '#')
         {
             tc.SkipRemainder();
         }
         else if ((tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"') ||
                  (tc.Char() == '\'' && tc.NChar() == '\'' && tc.NNChar() == '\''))
         {
             this.status    = stMultiLineString;
             this.quoteChar = tc.Char();
             tc.Skip(3);
             this.ParseMultiLineString(tc);
         }
         else if (tc.Char() == '\'' || tc.Char() == '"')
         {
             this.status    = stString;
             this.quoteChar = tc.Char();
             tc.Next();
             this.ParseString(tc);
         }
         else if (this.BraceList.IndexOf(tc.Char()) >= 0)
         {
             pos = new CharPos(tc.Char(), tc.AbsolutePosition);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
 private void ParseMultiLineString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == this.quoteChar && tc.NChar() == this.quoteChar && tc.NNChar() == this.quoteChar)
         {
             tc.Skip(3);
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
Ejemplo n.º 7
0
 private void ParseTripleQuotedString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"')
         {
             tc.Skip(3);
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
Ejemplo n.º 8
0
        // we assume endChars is 2 or 3, which is the most common case
        private string TrimmedMinus(ITextChars tc, String t)
        {
            StringBuilder buffer = new StringBuilder();

            while (!tc.EndOfLine)
            {
                if (tc.Char() == t[0] && tc.NChar() == t[1])
                {
                    if (t.Length <= 2 || tc.NNChar() == t[2])
                    {
                        break;
                    }
                }
                buffer.Append(tc.Char());
                tc.Next();
            }
            return(buffer.ToString().Trim());
        }
Ejemplo n.º 9
0
 public string Parse(ITextChars tc)
 {
     SkipWhitespace(tc);
       if ( tc.Char() == '/' && tc.NChar() == '/' ) {
     // C single line comment
     tc.Skip(2);
     return TrimmedRemainder(tc);
       } else if ( tc.Char() == '/' && tc.NChar() == '*' ) {
     // C multi line comment
     tc.Skip(2);
     return TrimmedMinus(tc, "*/");
       } else if ( tc.Char() == '(' && tc.NChar() == '*' ) {
     // F# multi line comment
     tc.Skip(2);
     return TrimmedMinus(tc, "*)");
       } else if ( tc.Char() == '-' && tc.NChar() == '-' ) {
     // SQL single line comment
     tc.Skip(2);
     return TrimmedRemainder(tc);
       } else if ( tc.Char() == '#' ) {
     // Python single line comment
     tc.Skip(1);
     return TrimmedRemainder(tc);
       } else if ( tc.Char() == '\'' ) {
     // VB single line comment
     tc.Skip(1);
     return TrimmedRemainder(tc);
       } else if ( tc.Char() == '<' && tc.NChar() == '!' && tc.NNChar() == '-' ) {
     //  XML comment
     tc.Skip(3);
     if ( tc.Char() == '-' ) {
       tc.Next();
       return TrimmedMinus(tc, "-->");
     }
       }
       return null;
 }
Ejemplo n.º 10
0
 private void ParseTripleQuotedString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"' ) {
       tc.Skip(3);
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
       }
 }
Ejemplo n.º 11
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     // multi-line comment
     if ( tc.Char() == '(' && tc.NChar() == '*' && tc.NNChar() != ')') {
       this.status = stMultiLineComment;
       tc.Skip(2);
       this.ParseMultiLineComment(tc);
     } else if ( tc.Char() == '/' && tc.NChar() == '/' ) {
       tc.SkipRemainder();
     } else if ( tc.Char() == '@' && tc.NChar() == '"' ) {
       this.status = stVerbatimString;
       tc.Skip(2);
       this.ParseVerbatimString(tc);
     } else if ( tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"' ) {
       this.status = stTripleQuotedString;
       tc.Skip(3);
       this.ParseTripleQuotedString(tc);
     } else if ( tc.Char() == '"' ) {
       this.status = stString;
       tc.Next();
       this.ParseString(tc);
     } else if ( tc.Char() == '<' && tc.NChar() == '\'') {
       // this is just a generic parameter, so skip it already
       tc.Skip(2);
     } else if ( Char.IsLetterOrDigit(tc.Char()) && tc.NChar() == '\'' ) {
       // identifier like c'
       tc.Skip(2);
     } else if ( tc.Char() == '\'' ) {
       this.status = stChar;
       tc.Next();
       this.ParseCharLiteral(tc);
     } else if ( this.BraceList.IndexOf(tc.Char()) >= 0 ) {
       pos = new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
Ejemplo n.º 12
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while (!tc.AtEnd)
     {
         // multi-line comment
         if (tc.Char() == '(' && tc.NChar() == '*' && tc.NNChar() != ')')
         {
             this.status = stMultiLineComment;
             tc.Skip(2);
             this.ParseMultiLineComment(tc);
         }
         else if (tc.Char() == '/' && tc.NChar() == '/')
         {
             tc.SkipRemainder();
         }
         else if (tc.Char() == '@' && tc.NChar() == '"')
         {
             this.status = stVerbatimString;
             tc.Skip(2);
             this.ParseVerbatimString(tc);
         }
         else if (tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"')
         {
             this.status = stTripleQuotedString;
             tc.Skip(3);
             this.ParseTripleQuotedString(tc);
         }
         else if (tc.Char() == '"')
         {
             this.status = stString;
             tc.Next();
             this.ParseString(tc);
         }
         else if (tc.Char() == '<' && tc.NChar() == '\'')
         {
             // this is just a generic parameter, so skip it already
             tc.Skip(2);
         }
         else if (Char.IsLetterOrDigit(tc.Char()) && tc.NChar() == '\'')
         {
             // identifier like c'
             tc.Skip(2);
         }
         else if (tc.Char() == '\'')
         {
             this.status = stChar;
             tc.Next();
             this.ParseCharLiteral(tc);
         }
         else if (this.BraceList.IndexOf(tc.Char()) >= 0)
         {
             pos = new CharPos(tc.Char(), tc.AbsolutePosition);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
Ejemplo n.º 13
0
 private IEnumerable<CharPos> ParseText(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '#' ) {
       tc.SkipRemainder();
     } else if ( (tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"')
          || (tc.Char() == '\'' && tc.NChar() == '\'' && tc.NNChar() == '\'') ) {
       this.status = stMultiLineString;
       this.quoteChar = tc.Char();
       tc.Skip(3);
       this.ParseMultiLineString(tc);
     } else if ( tc.Char() == '\'' || tc.Char() == '"' ) {
       this.status = stString;
       this.quoteChar = tc.Char();
       tc.Next();
       this.ParseString(tc);
     } else if ( braceList.IndexOf(tc.Char()) >= 0 ) {
       yield return new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
     } else {
       tc.Next();
     }
       }
 }
Ejemplo n.º 14
0
        private bool TryParseEscapeSequence(ref StringPart part)
        {
            int start = this.text.Position;

            text.Next();
            if (escapeChar.IndexOf(text.Char()) >= 0)
            {
                text.Next();
                part = new StringPart(new Span(text.Position - 2, 2));
                return(true);
            }
            if (Char.IsDigit(text.Char()) && Char.IsDigit(text.NChar()) && Char.IsDigit(text.NNChar()))
            {
                // a trigraph
                text.Skip(3);
                part = new StringPart(new Span(text.Position - 4, 4));
                return(true);
            }
            if (text.Char() == '0' && !Char.IsDigit(text.NChar()))
            {
                // \0
                text.Next();
                part = new StringPart(new Span(text.Position - 2, 2));
                return(true);
            }
            if (text.Char() == 'u')
            {
                text.Next();
                text.Mark();
                Span?span = TryParseShortUnicode();
                if (span.HasValue)
                {
                    part = new StringPart(span.Value);
                    return(true);
                }
                text.BackToMark();
            }
            if (text.Char() == 'U')
            {
                text.Next();
                text.Mark();
                Span?span = TryParseLongUnicode();
                if (span.HasValue)
                {
                    part = new StringPart(span.Value);
                    return(true);
                }
                text.BackToMark();
            }
            // unrecognized sequence, return it as error
            text.Next();
            int length = text.Position - start;

            part = new StringPart(new Span(start, length), StringPartType.EscapeSequenceError);
            return(true);
        }
Ejemplo n.º 15
0
 public Span?Next()
 {
     while (!text.EndOfLine)
     {
         if (text.Char() == '\\')
         {
             text.Next();
             if (escapeChar.IndexOf(text.Char()) >= 0)
             {
                 text.Next();
                 return(new Span(text.Position - 2, 2));
             }
             if (Char.IsDigit(text.Char()) && Char.IsDigit(text.NChar()) && Char.IsDigit(text.NNChar()))
             {
                 // a trigraph
                 text.Skip(3);
                 return(new Span(text.Position - 4, 4));
             }
             if (text.Char() == '0' && !Char.IsDigit(text.NChar()))
             {
                 // \0
                 text.Next();
                 return(new Span(text.Position - 2, 2));
             }
             if (text.Char() == 'u')
             {
                 text.Next();
                 text.Mark();
                 Span?span = TryParseShortUnicode();
                 if (span.HasValue)
                 {
                     return(span.Value);
                 }
                 text.BackToMark();
             }
             if (text.Char() == 'U')
             {
                 text.Next();
                 text.Mark();
                 Span?span = TryParseLongUnicode();
                 if (span.HasValue)
                 {
                     return(span.Value);
                 }
                 text.BackToMark();
             }
         }
         else
         {
             text.Next();
         }
     }
     return(null);
 }
Ejemplo n.º 16
0
 private bool TryParseEscapeSequence(ref StringPart part)
 {
     text.Next();
     if (escapeChar.IndexOf(text.Char()) >= 0)
     {
         text.Next();
         part = new StringPart(new Span(text.Position - 2, 2));
         return(true);
     }
     if (Char.IsDigit(text.Char()) && Char.IsDigit(text.NChar()) && Char.IsDigit(text.NNChar()))
     {
         // a trigraph
         text.Skip(3);
         part = new StringPart(new Span(text.Position - 4, 4));
         return(true);
     }
     if (text.Char() == '0' && !Char.IsDigit(text.NChar()))
     {
         // \0
         text.Next();
         part = new StringPart(new Span(text.Position - 2, 2));
         return(true);
     }
     if (text.Char() == 'u')
     {
         text.Next();
         text.Mark();
         Span?span = TryParseShortUnicode();
         if (span.HasValue)
         {
             part = new StringPart(span.Value);
             return(true);
         }
         text.BackToMark();
     }
     if (text.Char() == 'U')
     {
         text.Next();
         text.Mark();
         Span?span = TryParseLongUnicode();
         if (span.HasValue)
         {
             part = new StringPart(span.Value);
             return(true);
         }
         text.BackToMark();
     }
     return(false);
 }
Ejemplo n.º 17
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     // multi-line comment
     if ( tc.Char() == '/' && tc.NChar() == '*' ) {
       this.status = stMultiLineComment;
       tc.Skip(2);
       this.ParseMultiLineComment(tc);
     } else if ( tc.Char() == '/' && tc.NChar() == '/' ) {
       tc.SkipRemainder();
     } else if ( tc.Char() == '@' && tc.NChar() == '"' ) {
       this.status = stString;
       this.multiLine = true;
       tc.Skip(2);
       this.ParseMultiLineString(tc);
     } else if ( tc.Char() == '$' && tc.NChar() == '"' ) {
       // Roslyn interpolated string
       this.parsingExpression = false;
       this.status = stIString;
       tc.Skip(2);
       return this.ParseInterpolatedString(tc, ref pos);
     } else if ( tc.Char() == '$' && tc.NChar() == '@' && tc.NNChar() == '"' ) {
       this.status = stIString;
       this.multiLine = true;
       this.parsingExpression = false;
       tc.Skip(3);
       return this.ParseInterpolatedString(tc, ref pos);
     } else if ( tc.Char() == '"' ) {
       this.status = stString;
       tc.Next();
       this.ParseString(tc);
     } else if ( tc.Char() == '\'' ) {
       this.status = stString;
       tc.Next();
       this.ParseCharLiteral(tc);
     } else if ( this.BraceList.IndexOf(tc.Char()) >= 0 ) {
       pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
Ejemplo n.º 18
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '#' ) {
       tc.SkipRemainder();
     } else if ( (tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"')
          || (tc.Char() == '\'' && tc.NChar() == '\'' && tc.NNChar() == '\'') ) {
       this.status = stMultiLineString;
       this.quoteChar = tc.Char();
       tc.Skip(3);
       this.ParseMultiLineString(tc);
     } else if ( tc.Char() == '\'' || tc.Char() == '"' ) {
       this.status = stString;
       this.quoteChar = tc.Char();
       tc.Next();
       this.ParseString(tc);
     } else if ( this.BraceList.IndexOf(tc.Char()) >= 0 ) {
       pos = new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
Ejemplo n.º 19
0
        private IEnumerable <CharPos> ParseText(ITextChars tc)
        {
            while (!tc.EndOfLine)
            {
                // multi-line comment
                if (tc.Char() == '(' && tc.NChar() == '*')
                {
                    this.status = stMultiLineComment;
                    tc.Skip(2);
                    this.ParseMultiLineComment(tc);
                }
                else if (tc.Char() == '/' && tc.NChar() == '/')
                {
                    tc.SkipRemainder();
                }
                else if (tc.Char() == '@' && tc.NChar() == '"')
                {
                    this.status = stVerbatimString;
                    tc.Skip(2);
                    this.ParseVerbatimString(tc);
                }
                else if (tc.Char() == '"' && tc.NChar() == '"' && tc.NNChar() == '"')
                {
                    this.status = stTripleQuotedString;
                    tc.Skip(3);
                    this.ParseTripleQuotedString(tc);
                }
                else if (tc.Char() == '"')
                {
                    this.status = stString;
                    tc.Next();
                    this.ParseString(tc);
                }
                else if (tc.Char() == '<' && tc.NChar() == '\'')
                {
                    // this is just a generic parameter, so skip it already
                    tc.Skip(2);
                }
                else if (Char.IsLetterOrDigit(tc.Char()) && tc.NChar() == '\'')
                {
                    // identifier like c'
                    tc.Skip(2);
                }
                else if (tc.Char() == '\'')
                {
                    this.status = stChar;
                    tc.Next();
                    this.ParseCharLiteral(tc);
                }
                else if (lang.BraceList.IndexOf(tc.Char()) >= 0)
                {
                    yield return(new CharPos(tc.Char(), tc.AbsolutePosition));

                    tc.Next();
                }
                else
                {
                    tc.Next();
                }
            }
        }