private void ParseCharLiteral(ITextChars tc)
 {
     // valid:
       // - 'a'
       // - '\b'
       // - '\uaaaa'
       // - '()
       // not valid:
       // - 'a,
       // - 'a
       // - 'a)
       // mark is just after the opening '
       if ( tc.Char() == '\\' ) {
     // skip until next quote
     tc.Skip(2);
     while ( !tc.EndOfLine && tc.Char() != '\'' ) {
       tc.Next();
     }
     tc.Next();
       } else {
     // skip the first char, as it's going to be a literal
     // however, if the next char isn't a ', assume
     // this is a generic declaration
     tc.Next();
     if ( tc.Char() == '\'' ) {
       tc.Next();
     }
       }
       this.status = stText;
 }
        internal static StringPart ParseEscapeSequence(ITextChars text)
        {
            // text.Char() == \
              int start = text.Position;
              int len = 1;
              text.Next();

              int maxlen = Int32.MaxValue;

              char f = text.Char();
              text.Next();
              // not perfect, but close enough for first version
              if ( (f == 'x' || f == 'u' || f == 'U') && text.Char() != '{' ) {
            if ( f == 'x' ) maxlen = 3;
            else if ( f == 'u' ) maxlen = 5;
            else if ( f == 'U' ) maxlen = 9;

            while ( text.Char().IsHexDigit() && len < maxlen ) {
              text.Next();
              len++;
            }
              } else if ( (f == 'u' || f == 'U') && text.Char() == '{' ) {
            len++;
            while ( text.Char() != '}' && !text.EndOfLine ) {
              text.Next();
              len++;
            }
              }
              var span = new Span(start, len + 1);
              return new StringPart(span, StringPartType.EscapeSequence);
        }
 // 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();
 }
Exemple #4
0
 private void ParseString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\'' && tc.NChar() == '\'' ) {
       tc.Skip(2);
     } else if ( tc.Char() == '\'' ) {
       tc.Next();
       this.status = stText;
       break;
     } else {
       tc.Next();
     }
       }
 }
 private void ParseString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '"' && tc.NChar() == '"' ) {
       // embedded quotes, skip
       tc.Skip(2);
     } else if ( tc.Char() == '"' ) {
       this.status = stText;
       tc.Next();
       break;
     } else {
       tc.Next();
     }
       }
 }
Exemple #6
0
 private void ParseCharLiteral(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\\' ) {
       // skip over escape sequences
       tc.Skip(2);
     } else if ( tc.Char() == '\'' ) {
       tc.Next();
       break;
     } else {
       tc.Next();
     }
       }
       this.status = stText;
 }
Exemple #7
0
 private void ParseHereExpandableString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '`' ) {
       // skip over escape sequences
       tc.Skip(2);
     } else if ( tc.Char() == '"' && tc.NChar() == '@' ) {
       tc.Skip(2);
       break;
     } else {
       tc.Next();
     }
       }
       this.status = stText;
 }
 private void ParseStringInt(ITextChars tc, char quote)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\\' ) {
       // skip over escape sequences
       tc.Skip(2);
     } else if ( tc.Char() == quote ) {
       tc.Next();
       this.status = stText;
       break;
     } else {
       tc.Next();
     }
       }
 }
Exemple #9
0
 private IEnumerable<CharPos> ParseText(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\'' ) {
       // single line comment
       tc.SkipRemainder();
     } else if ( tc.Char() == '"' ) {
       this.status = stString;
       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();
     }
       }
 }
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\'' ) {
       // single line comment
       tc.SkipRemainder();
     } else if ( tc.Char() == '"' ) {
       this.status = stString;
       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;
 }
 private void ParseComment(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '*' && tc.NChar() == '/' ) {
       tc.Skip(2);
       this.state = stText;
       return;
     }
     tc.Next();
       }
 }
Exemple #12
0
 private void ParseString(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '\'' && tc.NChar() == '\'')
         {
             tc.Skip(2);
         }
         else if (tc.Char() == '\'')
         {
             tc.Next();
             this.status = stText;
             break;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #13
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);
 }
Exemple #14
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.SkipRemainder();
                }
                else if (tc.Char() == '@' && tc.NChar() == '\'')
                {
                    this.status = stHereString;
                    tc.Skip(2);
                    this.ParseHereString(tc);
                }
                else if (tc.Char() == '@' && tc.NChar() == '"')
                {
                    this.status = stHereExpandableString;
                    tc.Skip(2);
                    this.ParseHereExpandableString(tc);
                }
                else if (tc.Char() == '"')
                {
                    this.status = stString;
                    tc.Next();
                    this.ParseExpandableString(tc);
                }
                else if (tc.Char() == '\'')
                {
                    this.status = stString;
                    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();
                }
            }
        }
 private void ParseString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '"' && tc.NChar() == '"')
         {
             // embedded quotes, skip
             tc.Skip(2);
         }
         else if (tc.Char() == '"')
         {
             this.status = stText;
             tc.Next();
             break;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #16
0
 private void ParseMultiLineString(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '"' && tc.NChar() == '"')
         {
             // means a single embedded double quote
             tc.Skip(2);
         }
         else if (tc.Char() == '"')
         {
             tc.Next();
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #17
0
 private void ParseStringInt(ITextChars tc, char quote)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '\\')
         {
             // skip over escape sequences
             tc.Skip(2);
         }
         else if (tc.Char() == quote)
         {
             tc.Next();
             this.status = stText;
             break;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #18
0
 private void ParseString(ITextChars tc, char quote)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == quote && tc.NChar() == quote)
         {
             // double quote, meaning a single literal quote, skip
             tc.Skip(2);
         }
         else if (tc.Char() == quote)
         {
             tc.Next();
             break;
         }
         else
         {
             tc.Next();
         }
     }
     this.status = stText;
 }
Exemple #19
0
 private void ParseHereExpandableString(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '`')
         {
             // skip over escape sequences
             tc.Skip(2);
         }
         else if (tc.Char() == '"' && tc.NChar() == '@')
         {
             tc.Skip(2);
             break;
         }
         else
         {
             tc.Next();
         }
     }
     this.status = stText;
 }
Exemple #20
0
 private void ParseCharLiteral(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '\\')
         {
             // skip over escape sequences
             tc.Skip(2);
         }
         else if (tc.Char() == '\'')
         {
             tc.Next();
             break;
         }
         else
         {
             tc.Next();
         }
     }
     this.status = stText;
 }
 private void ParseString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '\\')
         {
             // skip over escape sequences
             tc.Skip(2);
         }
         else if (tc.Char() == '"')
         {
             tc.Next();
             break;
         }
         else
         {
             tc.Next();
         }
     }
     this.status = stText;
 }
 private void ParseMultiLineString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '"' ) {
       tc.Next();
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
       }
 }
Exemple #23
0
 public StringPart?Next()
 {
     while (!text.EndOfLine)
     {
         if (text.Char() == '\\')
         {
             return(ParseEscapeSequence(text));
         }
         text.Next();
     }
     return(null);
 }
 private void ParseComment(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '*' && tc.NChar() == '/')
         {
             tc.Skip(2);
             this.state = stText;
             return;
         }
         tc.Next();
     }
 }
Exemple #25
0
        private void String(ITextChars tc)
        {
            while (!tc.AtEnd)
            {
                // End of a String.
                if (tc.Char() == '"')
                {
                    tc.Next();
                    this.status = State.Text;
                    return;
                }

                // Start of an Escape Sequence.
                if (tc.Char() == '\\')
                {
                    tc.Next();
                }

                // Content of a String, or an Escaped Character.
                tc.Next();
            }
        }
 private bool ParseText(ITextChars tc, ref CharPos pos) {
   while ( !tc.AtEnd ) {
     // 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;
 }
Exemple #27
0
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && tc.Char() != '#')
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            return(tc.GetRemainder());
        }
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && tc.Char() != '\'')
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            // single line comment
            return(tc.GetRemainder());
        }
 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() == '\'' ) {
       this.status = stString;
       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;
 }
 private void ParseString(ITextChars tc, char quote)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '\\' ) {
       // escape sequence
       // could be 1-6 hex digits or something else
       tc.Skip(2);
     } else if ( tc.Char() == quote ) {
       tc.Next();
       this.state = stText;
       break;
     }
     tc.Next();
       }
 }
 public StringPart?Next()
 {
     while (!text.EndOfLine)
     {
         if (text.Char() == '\\')
         {
             return(BasicCStringScanner.ParseEscapeSequence(text));
         }
         else if (text.Char() == '{' && text.NChar() == '{')
         {
             text.Next(); // skip it
         }
         else if (text.Char() == '{' && !isInterpolated)
         {
             StringPart part = new StringPart();
             if (ParseFormatSpecifier(ref part))
             {
                 return(part);
             }
         }
         text.Next();
     }
     return(null);
 }
 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();
         }
     }
 }
 private void ParseVerbatimString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '"')
         {
             tc.Next();
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #34
0
 private void ParseHereString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '\'' && tc.NChar() == '@')
         {
             tc.Skip(2);
             break;
         }
         else
         {
             tc.Next();
         }
     }
     this.status = stText;
 }
Exemple #35
0
 private void ParseMultiLineString(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '"')
         {
             tc.Next();
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
 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();
         }
     }
 }
Exemple #37
0
 private void ParseString(ITextChars tc)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '\"')
         {
             tc.Next();
             this.status = stText;
             break;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #38
0
 private void ParseMultiLineComment(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '#' && tc.NChar() == '>')
         {
             tc.Skip(2);
             this.status = stText;
             return;
         }
         else
         {
             tc.Next();
         }
     }
 }
Exemple #39
0
        private StringPart?ParseEscapeSequence(ITextChars text)
        {
            // text.Char() == \
            int start = text.Position;

            text.Next();

            char f = text.Char();

            text.Next();
            if (f == '\\' || f == '\"')
            {
                var span = new TextSpan(start, 2);
                return(new StringPart(span, StringPartType.EscapeSequence));
            }
            return(null);
        }
 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() == '/' && CheckPrevious(tc.PreviousToken()))
         {
             // probably a regular expression literal
             tc.Next();
             this.status = stRegex;
             this.ParseRegex(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);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
 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);
 }
Exemple #42
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() == '"')
         {
             this.status = stString;
             tc.Next();
             this.ParseString(tc);
         }
         else if (Char.IsDigit(tc.Char()) && tc.NChar() == '\'')
         {
             // this is a C++ 14 digit separator, such as 1'000'000
             tc.Skip(2);
         }
         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);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
Exemple #43
0
 private bool ParseTemplateExpressionChar(ITextChars tc, ref CharPos pos)
 {
     if (tc.Char() == '"')
     {
         // opening string
         tc.Next();
         this.ParseString(tc);
         this.status = stIString;
     }
     else if (tc.Char() == '\'')
     {
         tc.Next();
         ParseCharLiteral(tc);
         this.status = stIString;
     }
     else if (tc.Char() == '}')
     {
         // reached the end
         this.nestingLevel--;
         if (this.nestingLevel == 0)
         {
             this.parsingExpression = false;
         }
         pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
         tc.Next();
         return(true);
     }
     else if (BraceList.Contains(tc.Char()))
     {
         pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
         if (tc.Char() == '{')
         {
             this.nestingLevel++;
         }
         tc.Next();
         return(true);
     }
     else
     {
         tc.Next();
     }
     return(false);
 }
 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;
 }
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     pos = CharPos.Empty;
     while (!tc.AtEnd)
     {
         if (tc.Char() == '/' && tc.NChar() == '*')
         {
             this.state = stComment;
             tc.Skip(2);
             ParseComment(tc);
         }
         else if (tc.Char() == '/' && tc.NChar() == '/')
         {
             // CSS doesn't really support single-line comments,
             // but SASS does, and it doesn't harm too
             // much to implement it as a single thing
             tc.SkipRemainder();
         }
         else if (tc.Char() == '"')
         {
             this.state = stDoubleQuotedString;
             tc.Next();
             ParseDString(tc);
         }
         else if (tc.Char() == '\'')
         {
             this.state = stSingleQuotedString;
             tc.Next();
             ParseString(tc);
         }
         else if (this.BraceList.Contains(tc.Char()))
         {
             pos = new CharPos(tc.Char(), tc.AbsolutePosition);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
 // C# 6.0 interpolated string support:
 // this is a hack. It will not handle all possible expressions
 // but will handle most basic stuff
 private bool ParseInterpolatedString(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     if ( parsingExpression ) {
       //
       // we're inside an interpolated section
       //
       if ( tc.Char() == '"' ) {
     // opening string
     tc.Next();
     this.ParseString(tc);
     this.status = stIString;
       } else if ( tc.Char() == '\'' ) {
     tc.Next();
     ParseCharLiteral(tc);
     this.status = stIString;
       } else if ( tc.Char() == '}' ) {
     // reached the end
     this.nestingLevel--;
     if ( nestingLevel == 0 ) {
       this.parsingExpression = false;
     }
     pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
     tc.Next();
     return true;
       } else if ( BraceList.Contains(tc.Char()) ) {
     pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
     if ( tc.Char() == '{' )
       this.nestingLevel++;
     tc.Next();
     return true;
       } else {
     tc.Next();
       }
     } else {
       //
       // parsing the string part
       // if it's an at-string, don't look for escape sequences
       //
       if ( tc.Char() == '\\' && !this.multiLine ) {
     // skip over escape sequences
     tc.Skip(2);
       } else if ( tc.Char() == '{' && tc.NChar() == '{' ) {
     tc.Skip(2);
       } else if ( tc.Char() == '{' ) {
     this.parsingExpression = true;
     this.nestingLevel++;
     pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
     tc.Next();
     return true;
       } else if ( this.multiLine && tc.Char() == '"' && tc.NChar() == '"' ) {
     // single embedded double quote
     tc.Skip(2);
       } else if ( tc.Char() == '"' ) {
     // done parsing the interpolated string
     this.status = stText;
     this.multiLine = false;
     tc.Next();
     break;
       } else {
     tc.Next();
       }
     }
       }
       return false;
 }
 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;
 }
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     pos = CharPos.Empty;
       while ( !tc.EndOfLine ) {
     if ( tc.Char() == '/' && tc.NChar() == '*' ) {
       this.state = stComment;
       tc.Skip(2);
       ParseComment(tc);
     } else if ( tc.Char() == '/' && tc.NChar() == '/' ) {
       // CSS doesn't really support single-line comments,
       // but SASS does, and it doesn't harm too
       // much to implement it as a single thing
       tc.SkipRemainder();
     } else if ( tc.Char() == '"' ) {
       this.state = stDoubleQuotedString;
       tc.Next();
       ParseDString(tc);
     } else if ( tc.Char() == '\'' ) {
       this.state = stSingleQuotedString;
       tc.Next();
       ParseString(tc);
     } else if ( this.BraceList.Contains(tc.Char()) ) {
       pos = new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
Exemple #49
0
 private IEnumerable<CharPos> ParseText(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '/' && tc.NChar() == '*' ) {
       this.state = stComment;
       tc.Skip(2);
       ParseComment(tc);
     } else if ( tc.Char() == '/' && tc.NChar() == '/' ) {
       // CSS doesn't really support single-line comments,
       // but SASS does, and it doesn't harm too
       // much to implement it as a single thing
       tc.SkipRemainder();
     } else if ( tc.Char() == '"' ) {
       this.state = stDoubleQuotedString;
       tc.Next();
       ParseDString(tc);
     } else if ( tc.Char() == '\'' ) {
       this.state = stSingleQuotedString;
       tc.Next();
       ParseString(tc);
     } else if ( braceList.Contains(tc.Char()) ) {
       yield return new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
     } else {
       tc.Next();
     }
       }
 }
 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;
 }
Exemple #51
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.SkipRemainder();
     } else if ( tc.Char() == '@' && tc.NChar() == '\'' ) {
       this.status = stHereString;
       tc.Skip(2);
       this.ParseHereString(tc);
     } else if ( tc.Char() == '@' && tc.NChar() == '"' ) {
       this.status = stHereExpandableString;
       tc.Skip(2);
       this.ParseHereExpandableString(tc);
     } else if ( tc.Char() == '"' ) {
       this.status = stString;
       tc.Next();
       this.ParseExpandableString(tc);
     } else if ( tc.Char() == '\'' ) {
       this.status = stString;
       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();
     }
       }
 }
Exemple #52
0
 private void ParseMultiLineComment(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '#' && tc.NChar() == '>' ) {
       tc.Skip(2);
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
       }
 }
 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;
 }
 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() == '/' && CheckPrevious(tc.PreviousToken()) ) {
       // probably a regular expression literal
       tc.Next();
       this.status = stRegex;
       this.ParseRegex(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);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
 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();
     }
       }
 }
 private void SkipWhitespace(ITextChars tc)
 {
     while ( !tc.EndOfLine && Char.IsWhiteSpace(tc.Char()) ) {
     tc.Next();
       }
 }
 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();
     }
       }
 }
Exemple #58
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() == '"' ) {
       this.status = stString;
       tc.Next();
       this.ParseString(tc);
     } else if ( Char.IsDigit(tc.Char()) && tc.NChar() == '\'' ) {
       // this is a C++ 14 digit separator, such as 1'000'000
       tc.Skip(2);
     } 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);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }
Exemple #59
0
 private void ParseMultiLineString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '"' && tc.NChar() == '"' ) {
       // means a single embedded double quote
       tc.Skip(2);
     } else if ( tc.Char() == '"' ) {
       tc.Next();
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
       }
 }