示例#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();
                }
            }
        }
示例#2
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                switch (this.status)
                {
                case stString: ParseString(tc); break;

                case stChar: ParseCharLiteral(tc); break;

                case stMultiLineComment: ParseMultiLineComment(tc); break;

                case stIString:
                    if (ParseInterpolatedString(tc, ref pos))
                    {
                        return(true);
                    }
                    break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
示例#3
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while (!tc.AtEnd)
     {
         if (tc.Char() == '!')
         {
             // single line comment
             tc.SkipRemainder();
         }
         else if (tc.Char() == '\'')
         {
             this.status = stStringSingle;
             tc.Next();
             ParseStringSingle(tc);
         }
         else if (tc.Char() == '"')
         {
             this.status = stStringDouble;
             tc.Next();
             ParseStringDouble(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);
 }
示例#4
0
 public RStringScanner(String text)
 {
     this.text = new StringChars(text, 0, text.Length - 1);
       // always skip the first char
       // (since quotes are included in the string)
       this.text.Next();
 }
示例#5
0
        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);
        }
示例#6
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 (language.BraceList.IndexOf(tc.Char()) >= 0)
                {
                    yield return(new CharPos(tc.Char(), tc.AbsolutePosition));

                    tc.Next();
                }
                else
                {
                    tc.Next();
                }
            }
        }
 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.AtEnd && 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;
 }
 public bool Extract(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString:
     if ( this.multiLine ) {
       ParseMultiLineString(tc);
     } else {
       ParseString(tc);
     }
     break;
       case stChar: ParseCharLiteral(tc); break;
       case stMultiLineComment: ParseMultiLineComment(tc); break;
       case stIString:
     if ( ParseInterpolatedString(tc, ref pos) )
       return true;
     break;
       default:
     if ( ParseText(tc, ref pos) )
       return true;
     break;
     }
       }
       return false;
 }
示例#9
0
        public IEnumerable <CharPos> Extract(ITextChars tc)
        {
            while (!tc.EndOfLine)
            {
                switch (this.status)
                {
                case stString: ParseString(tc); break;

                case stExpandableString: ParseExpandableString(tc); break;

                case stMultiLineComment: ParseMultiLineComment(tc); break;

                case stHereString: ParseHereString(tc); break;

                case stHereExpandableString: ParseHereExpandableString(tc); break;

                default:
                    foreach (var p in ParseText(tc))
                    {
                        yield return(p);
                    }
                    break;
                }
            }
        }
示例#10
0
        public CSharpStringScanner(String text, String classificationName = "string")
        {
            this.text       = new StringChars(text, 0, text.Length - 1);
            this.isVerbatim = classificationName == "string - verbatim";
            // If this is an at-string, skip it
            char first = this.text.Char();

            if (first == '@')
            {
                this.isVerbatim = true;
                this.text.Skip(2);
            }
            else if (first == '$')
            {
                this.isInterpolated = true;
                if (this.text.NChar() == '@')
                {
                    this.isVerbatim = true;
                    this.text.Skip(3);
                }
                else
                {
                    this.text.Skip(2);
                }
            }
            else if (first == '"' || first == '\'')
            {
                // always skip the first char
                // (since quotes are included in the string)
                this.text.Next();
            }
        }
示例#11
0
        private bool Parse(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                // Comment.
                if (tc.Char() == '#')
                {
                    tc.SkipRemainder();
                }

                // String.
                else if (tc.Char() == '"')
                {
                    tc.Next();

                    this.status = State.MultiLineString;
                    this.String(tc);

                    continue;
                }

                // Braces.
                else if (this.BraceList.IndexOf(tc.Char()) >= 0)
                {
                    pos = new CharPos(tc.Char(), tc.AbsolutePosition);
                    tc.Next();
                    return(true);
                }

                // Code.
                tc.Next();
            }
            return(false);
        }
示例#12
0
 public RStringScanner(String text)
 {
     this.text = new StringChars(text, 0, text.Length - 1);
     // always skip the first char
     // (since quotes are included in the string)
     this.text.Next();
 }
示例#13
0
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && Char.IsWhiteSpace(tc.Char()))
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            if (tc.Char() == '(' && tc.NChar() == '*')
            {
                tc.Skip(2);
                // multiline comment
                StringBuilder sb = new StringBuilder();
                while (!tc.EndOfLine && tc.Char() != '*' && tc.NChar() != ')')
                {
                    sb.Append(tc.Char());
                    tc.Next();
                }
                return(sb.ToString());
            }
            else if (tc.Char() == '/' && tc.NChar() == '/')
            {
                tc.Skip(2);
                // single line comment
                return(tc.GetRemainder());
            }
            return(null);
        }
示例#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.NChar() == '-')
                {
                    tc.SkipRemainder();
                }
                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();
                }
            }
        }
示例#15
0
 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() == '\'')
         {
             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);
 }
示例#16
0
 private void SkipWhitespace(ITextChars tc)
 {
     while (!tc.EndOfLine && Char.IsWhiteSpace(tc.Char()))
     {
         tc.Next();
     }
 }
示例#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 = 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);
 }
示例#18
0
        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 == 'X' || f == 'u' || f == 'U')
            {
                if (f == 'u')
                {
                    maxlen = 5;
                }
                else if (f == 'U')
                {
                    maxlen = 9;
                }

                while (text.Char().IsHexDigit() && len < maxlen)
                {
                    text.Next();
                    len++;
                }
            }
            var span = new Span(start, len + 1);

            return(new StringPart(span, StringPartType.EscapeSequence));
        }
示例#19
0
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && tc.Char() != '/')
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            tc.Next();
            if (tc.Char() == '*')
            {
                tc.Next();
                // multiline comment
                while (!tc.EndOfLine && tc.Char() != '*' && tc.NChar() != '/')
                {
                    sb.Append(tc.Char());
                    tc.Next();
                }
            }
            else if (tc.Char() == '/')
            {
                tc.Next();
                // single line comment
                sb.Append(tc.GetRemainder());
            }
            return(sb.ToString());
        }
示例#20
0
 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;
 }
示例#21
0
        public CSharpStringScanner(String text)
        {
            this.text = new StringChars(text, 0, text.Length - 1);
            // If this is an at-string, skip it
            char first = this.text.Char();

            if (first == '@')
            {
                this.text.SkipRemainder();
            }
            else if (first == '$')
            {
                if (this.text.NChar() == '@')
                {
                    this.text.SkipRemainder();
                }
                else
                {
                    this.isInterpolated = true;
                    this.text.Skip(2);
                }
            }
            else if (first == '"' || first == '\'')
            {
                // always skip the first char
                // (since quotes are included in the string)
                this.text.Next();
            }
        }
示例#22
0
        public IEnumerable <CharPos> Extract(ITextChars tc)
        {
            while (!tc.EndOfLine)
            {
                switch (this.status)
                {
                case stString: ParseString(tc); break;

                case stChar: ParseCharLiteral(tc); break;

                case stMultiLineComment: ParseMultiLineComment(tc); break;

                case stVerbatimString: ParseVerbatimString(tc); break;

                case stTripleQuotedString: ParseTripleQuotedString(tc); break;

                default:
                    foreach (var p in ParseText(tc))
                    {
                        yield return(p);
                    }
                    break;
                }
            }
        }
示例#23
0
 public BasicCStringScanner(String text)
 {
     this.text = new StringChars(text, 0, text.Length);
     // only skip the first char if it's a quote
     // vs2017 does not can break the token and parse it in partial chunks
     if (this.text.Char() == '\'' || this.text.Char() == '"')
     {
         this.text.Next();
     }
 }
示例#24
0
        public FSharpStringScanner(String text)
        {
            this.text = new StringChars(text);
              // always skip the first char
              // (since quotes are included in the string)
              this.text.Next();

              if ( text.StartsWith("\"\"\"") ) {
            this.text.SkipRemainder();
              }
        }
示例#25
0
 private void ParseComment(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '*' && tc.NChar() == '/' ) {
       tc.Skip(2);
       this.state = stText;
       return;
     }
     tc.Next();
       }
 }
示例#26
0
 private void ParseMultiLineComment(ITextChars tc) {
   while ( !tc.AtEnd ) {
     if ( tc.Char() == '*' && tc.NChar() == '/' ) {
       tc.Skip(2);
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
   }
 }
示例#27
0
 private void ParseMultiLineString(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     if ( tc.Char() == '"' ) {
       tc.Next();
       this.status = stText;
       return;
     } else {
       tc.Next();
     }
       }
 }
示例#28
0
 public bool Extract(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString: ParseString(tc); break;
       case stSQString: ParseSQString(tc); break;
       default:
     return ParseText(tc, ref pos);
     }
       }
       return false;
 }
示例#29
0
        public FSharpStringScanner(String text)
        {
            this.text = new StringChars(text);
            // always skip the first char
            // (since quotes are included in the string)
            this.text.Next();

            if (text.StartsWith("\"\"\""))
            {
                this.text.SkipRemainder();
            }
        }
示例#30
0
 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() == '/' && 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 (tc.Char() == '`')
         {
             this.status = stIString;
             tc.Next();
             return(this.ParseInterpolatedString(tc, ref pos));
         }
         else if (this.BraceList.IndexOf(tc.Char()) >= 0)
         {
             pos = new CharPos(tc.Char(), tc.AbsolutePosition);
             tc.Next();
             return(true);
         }
         else
         {
             tc.Next();
         }
     }
     return(false);
 }
示例#31
0
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && tc.Char() != '#')
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            return(tc.GetRemainder());
        }
示例#32
0
 public IEnumerable<CharPos> Extract(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString: ParseString(tc); break;
       default:
     foreach ( var p in ParseText(tc) ) {
       yield return p;
     }
     break;
     }
       }
 }
示例#33
0
 public bool Extract(ITextChars tc, ref CharPos pos)
 {
     pos = CharPos.Empty;
       while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString: ParseString(tc); break;
       case stMultiLineComment: ParseMultiLineComment(tc); break;
       default:
     return ParseText(tc, ref pos);
     }
       }
       return false;
 }
示例#34
0
 public bool Extract(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.state ) {
       case stComment: ParseComment(tc); break;
       case stSingleQuotedString: ParseString(tc); break;
       case stDoubleQuotedString: ParseDString(tc); break;
       default:
     return ParseText(tc, ref pos);
     }
       }
       return false;
 }
示例#35
0
 private void ParseComment(ITextChars tc)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '*' && tc.NChar() == '/')
         {
             tc.Skip(2);
             this.state = stText;
             return;
         }
         tc.Next();
     }
 }
示例#36
0
 public CStringScanner(String text)
 {
     this.text = new StringChars(text, 0, text.Length - 1);
       // If it's a C preprocessor include
       // skip it
       if ( this.text.Char() == '<' ) {
     this.text.SkipRemainder();
       } else {
     // always skip the first char
     // (since quotes are included in the string)
     this.text.Next();
       }
 }
示例#37
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);
 }
示例#38
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                switch (this.status)
                {
                case State.MultiLineString: String(tc); break;

                default:
                    return(Parse(tc, ref pos));
                }
            }
            return(false);
        }
示例#39
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();
     }
       }
 }
示例#40
0
 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;
 }
示例#41
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();
 }
示例#42
0
        public string Parse(ITextChars tc)
        {
            while (!tc.EndOfLine && tc.Char() != '\'')
            {
                tc.Next();
            }
            if (tc.EndOfLine)
            {
                return(null);
            }

            // single line comment
            return(tc.GetRemainder());
        }
示例#43
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();
     }
       }
 }
示例#44
0
 private void ParseMultiLineString(ITextChars tc) {
   while ( !tc.AtEnd ) {
     if ( tc.Char() == '"' && tc.NChar() == '"' ) {
       // means a single embedded double quote
       tc.Skip(2);
     } else if ( tc.Char() == '"' ) {
       tc.Next();
       this.status = stText;
       this.multiLine = false;
       return;
     } else {
       tc.Next();
     }
   }
 }
示例#45
0
 public IEnumerable<CharPos> Extract(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.state ) {
       case stComment: ParseComment(tc); break;
       case stSingleQuotedString: ParseString(tc); break;
       case stDoubleQuotedString: ParseDString(tc); break;
       default:
     foreach ( var ch in ParseText(tc) ) {
       yield return ch;
     }
     break;
     }
       }
 }
示例#46
0
 public bool Extract(ITextChars tc, ref CharPos pos)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString: ParseString(tc); break;
       case stChar: ParseCharLiteral(tc); break;
       case stMultiLineComment: ParseMultiLineComment(tc); break;
       case stVerbatimString: ParseVerbatimString(tc); break;
       case stTripleQuotedString: ParseTripleQuotedString(tc); break;
       default:
     return ParseText(tc, ref pos);
     }
       }
       return false;
 }
示例#47
0
 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();
     }
       }
 }
示例#48
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            pos = CharPos.Empty;
            while (!tc.AtEnd)
            {
                switch (this.status)
                {
                case stString: ParseString(tc); break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
示例#49
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;
 }
示例#50
0
 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();
       }
 }
示例#51
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;
 }
        public FSharpEscapeSequenceParser(String text)
        {
            this.text = new StringChars(text);
              // always skip the first char
              // (since quotes are included in the string)
              this.text.Next();
              // If this is an at-string, or a C preprocessor include
              // skip it
              if ( text.StartsWith("@") || text.StartsWith("<") ) {
            this.text.SkipRemainder();
              }

              if ( text.StartsWith("\"\"\"") ) {
            this.text.SkipRemainder();
              }
        }
示例#53
0
 public IEnumerable<CharPos> Extract(ITextChars tc)
 {
     while ( !tc.EndOfLine ) {
     switch ( this.status ) {
       case stString: ParseString(tc); break;
       case stChar: ParseCharLiteral(tc); break;
       case stMultiLineComment: ParseMultiLineComment(tc); break;
       case stVerbatimString: ParseVerbatimString(tc); break;
       case stTripleQuotedString: ParseTripleQuotedString(tc); break;
       default:
     foreach ( var p in ParseText(tc) ) {
       yield return p;
     }
     break;
     }
       }
 }
示例#54
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();
     }
       }
 }
示例#55
0
 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;
 }
示例#56
0
 public CSharpStringScanner(String text)
 {
     this.text = new StringChars(text, 0, text.Length - 1);
       // If this is an at-string, skip it
       char first = this.text.Char();
       if ( first == '@' ) {
     this.text.SkipRemainder();
       } else if ( first == '$' ) {
     if ( this.text.NChar() == '@' ) {
       this.text.SkipRemainder();
     } else {
       this.isInterpolated = true;
       this.text.Skip(2);
     }
       } else if ( first == '"' || first == '\'' ) {
     // always skip the first char
     // (since quotes are included in the string)
     this.text.Next();
       }
 }
示例#57
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() == '\'' ) {
       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();
     }
       }
 }
示例#58
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;
 }
示例#59
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();
     }
       }
 }
示例#60
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 ( this.BraceList.IndexOf(tc.Char()) >= 0 ) {
       pos = new CharPos(tc.Char(), tc.AbsolutePosition);
       tc.Next();
       return true;
     } else {
       tc.Next();
     }
       }
       return false;
 }