Exemple #1
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);
 }
Exemple #2
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);
        }
Exemple #3
0
 public ConfigToken(ConfigTokenType type, CharPos fromPos, CharPos toPos, string text)
 {
     Type    = type;
     FromPos = fromPos;
     ToPos   = toPos;
     Text    = text;
 }
Exemple #4
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);
        }
 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);
 }
 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;
 }
Exemple #7
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);
 }
Exemple #8
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);
 }
 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;
 }
 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;
 }
 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;
 }
Exemple #12
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);
        }
 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;
 }
        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);
        }
Exemple #15
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.EndOfLine)
            {
                switch (this.status)
                {
                case stString: ParseString(tc); break;

                case stMultiLineString: ParseMultiLineString(tc); break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
Exemple #16
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                switch (this.status)
                {
                case stStringSingle: ParseStringSingle(tc); break;

                case stStringDouble: ParseStringDouble(tc); break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
        static ConfigUsing CreateDefaultUsing(Dictionary <string, ConfigUsing> usingLookup)
        {
            var current           = 0;
            var defaultUsingLabel = "Object";

            while (usingLookup.ContainsKey(defaultUsingLabel))
            {
                current++;
                defaultUsingLabel = "Object" + current.ToString(CultureInfo.InvariantCulture);
            }

            var pos = new CharPos(0, 1, 1);

            return(new ConfigUsing(
                       label: new ConfigToken(ConfigTokenType.Label, pos, pos, defaultUsingLabel),
                       className: new ConfigToken(ConfigTokenType.String, pos, pos, "System.Object")));
        }
Exemple #18
0
 static void Render(StringBuilder builder, CharPos pos)
 {
     if (pos == null)
     {
         builder.Append("null");
     }
     else
     {
         builder.Append("new CharPos(");
         builder.Append(pos.Index);
         builder.Append(", ");
         builder.Append(pos.LineNo);
         builder.Append(", ");
         builder.Append(pos.CharNo);
         builder.Append(')');
     }
 }
Exemple #19
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            pos = CharPos.Empty;
            while (!tc.EndOfLine)
            {
                switch (status)
                {
                case stString: ParseString(tc); break;

                case stMultiLineComment: ParseMultilineComment(tc); break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
Exemple #20
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 #21
0
 // template literal support,
 // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
 private bool ParseInterpolatedString(ITextChars tc, ref CharPos pos)
 {
     while (!tc.AtEnd)
     {
         if (this.parsingExpression)
         {
             // inside template literal expression in ${}
             if (ParseTemplateExpressionChar(tc, ref pos))
             {
                 return(true);
             }
         }
         else
         {
             // in the string part
             if (tc.Char() == '\\')
             {
                 // skip over escape sequences
                 tc.Skip(2);
             }
             else if (tc.Char() == '$' && tc.NChar() == '{')
             {
                 // opening expression
                 this.parsingExpression = true;
                 this.nestingLevel++;
                 tc.Next(); // skip $
                 pos = new CharPos(tc.Char(), tc.AbsolutePosition, EncodedState());
                 tc.Next(); // skip {
                 return(true);
             }
             else if (tc.Char() == '`')
             {
                 // done parsing the template
                 this.status = stText;
                 tc.Next();
                 break;
             }
             else
             {
                 tc.Next();
             }
         }
     }
     return(false);
 }
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                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);
        }
 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);
 }
        protected IList <CharPos> Extract(IBraceScanner extractor, string input, int start, int state, bool reset = true)
        {
            if (reset)
            {
                extractor.Reset(0);
            }
            ITextChars      chars = new StringChars(input, start);
            IList <CharPos> list  = new List <CharPos>();
            CharPos         cp    = CharPos.Empty;

            while (!chars.AtEnd)
            {
                if (extractor.Extract(chars, ref cp))
                {
                    list.Add(cp);
                }
            }
            return(list);
        }
Exemple #25
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);
 }
 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;
 }
Exemple #27
0
 private bool ParseText(ITextChars tc, ref CharPos pos)
 {
     while (!tc.EndOfLine)
     {
         if (tc.Char() == '/' && tc.NChar() == '*')
         {
             tc.Skip(2);
             status = stMultiLineComment;
             ParseMultilineComment(tc);
         }
         else if (tc.Char() == '/' && tc.NChar() == '/')
         {
             tc.SkipRemainder();
         }
         else if (tc.Char() == '\'')
         {
             status = stString;
             tc.Next();
             ParseCharLiteral(tc);
         }
         else if (tc.Char() == '"')
         {
             status = stString;
             tc.Next();
             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 #28
0
        public bool Extract(ITextChars tc, ref CharPos pos)
        {
            while (!tc.AtEnd)
            {
                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:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
        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 stVerbatimString: ParseVerbatimString(tc); break;

                case stTripleQuotedString: ParseTripleQuotedString(tc); break;

                default:
                    return(ParseText(tc, ref pos));
                }
            }
            return(false);
        }
        protected IList <CharPos> ExtractWithLines(IBraceScanner extractor, string input, int start, int state)
        {
            extractor.Reset(0);

            input = input.Substring(start);

            String[]       lines  = input.Split('\r', '\n');
            List <CharPos> result = new List <CharPos>();

            foreach (String line in lines)
            {
                ITextChars chars = new StringChars(line);
                CharPos    cp    = CharPos.Empty;
                while (!chars.AtEnd)
                {
                    if (extractor.Extract(chars, ref cp))
                    {
                        result.Add(cp);
                    }
                }
            }
            return(result);
        }
 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);
 }
 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;
 }
 // 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;
 }
 public bool CanResume(CharPos brace)
 {
     return(brace.State == stText);
 }
 // 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.AtEnd)
     {
         if (this.parsingExpression)
         {
             //
             // we're inside an interpolated section
             //
             if (tc.Char() == '$' && tc.NChar() == '"')
             {
                 // opening nested interpolated string
                 tc.Skip(2);
                 this.parsingExpression = false;
                 this.istringNestLevel++;
                 this.nestingLevel = 0;
                 if (this.ParseInterpolatedString(tc, ref pos))
                 {
                     return(true);
                 }
                 this.istringNestLevel--;
                 this.parsingExpression = true;
                 this.status            = stIString;
             }
             else if (tc.Char() == '@' && tc.NChar() == '"')
             {
                 // opening nested verbatim string
                 tc.Skip(2);
                 this.ParseMultiLineString(tc);
                 this.status = stIString;
             }
             else 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();
             }
         }
         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.multiLine = false;
                 this.istringNestLevel--;
                 if (this.istringNestLevel <= 0)
                 {
                     this.istringNestLevel = 0;
                     this.status           = stText;
                 }
                 else
                 {
                     this.status            = stIString;
                     this.parsingExpression = true;
                 }
                 tc.Next();
                 break;
             }
             else
             {
                 tc.Next();
             }
         }
     }
     return(false);
 }
 public bool Extract(ITextChars text, ref CharPos pos)
 {
     text.SkipRemainder();
     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)
 {
     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;
 }
Exemple #39
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;
 }
 public bool CanResume(CharPos brace)
 {
     // When adding (*, we want to be able to ignore the
     // ( and go back to the previous brace
     return(brace.Char != '(');
 }
 private void MatchBrace(IBraceStacker pairs, CharPos cp)
 {
     if ( IsOpeningBrace(cp) ) {
     Add(pairs.Push(cp));
       } else if ( pairs.Count(cp.Char) > 0 ) {
     // check if this is a closing brace matching
     // the opening on the stack
     BracePos p = pairs.Peek(cp.Char);
     if ( braceList[p.Brace] == cp.Char ) {
       // it does, add it
       pairs.Pop(cp.Char);
       Add(cp.AsBrace(p.Depth));
     } else {
       // it doesn't; it's an error
       this.braceErrors.Add(cp);
     }
       } else {
     // closing brace has no opening brace
     this.braceErrors.Add(cp);
       }
 }
 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);
 }
 public bool CanResume(CharPos brace)
 {
     // When adding (*, we want to be able to ignore the
       // ( and go back to the previous brace
       return brace.Char != '(';
 }
 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;
 }
 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;
 }
 public bool CanResume(CharPos brace)
 {
     return brace.State == stText;
 }
 public bool Extract(ITextChars text, ref CharPos pos)
 {
     text.SkipRemainder();
       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() == '@' && 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;
 }