public static IEnumerable <ICodeBlock> Parse(string scriptContent)
        {
            if (string.IsNullOrWhiteSpace(scriptContent))
            {
                throw new ArgumentException("Null/blank scriptContent specified");
            }

            // Break down content into String, Comment and UnprocessedContent tokens
            var tokens = StringBreaker.SegmentString(
                scriptContent.Replace("\r\n", "\n")
                );

            // Break down further into String, Comment, Atom and AbstractEndOfStatement tokens
            var atomTokens = new List <IToken>();

            foreach (var token in tokens)
            {
                if (token is UnprocessedContentToken)
                {
                    atomTokens.AddRange(TokenBreaker.BreakUnprocessedToken((UnprocessedContentToken)token));
                }
                else
                {
                    atomTokens.Add(token);
                }
            }

            // Translate these tokens into ICodeBlock implementations (representing code VBScript structures)
            string[] endSequenceMet;
            return((new CodeBlockHandler(null)).Process(atomTokens, out endSequenceMet));
        }
Exemple #2
0
 public void DoNotConsiderUnderscoresToBeLineContinuationsWhenTheyArePartOfVariableNames()
 {
     Assert.Equal(
         new IToken[]
     {
         new NameToken("a_b", 0)
     },
         TokenBreaker.BreakUnprocessedToken(new UnprocessedContentToken("a_b", 0)),
         new TokenSetComparer()
         );
 }
Exemple #3
0
 public void EnsureThatIntegerDivisionOperatorsAreRecognised()
 {
     Assert.Equal(
         new IToken[]
     {
         new NumericValueToken("1", 0),
         new OperatorToken("\\", 0),
         new NumericValueToken("0", 0)
     },
         TokenBreaker.BreakUnprocessedToken(new UnprocessedContentToken("1\\0", 0)),
         new TokenSetComparer()
         );
 }
Exemple #4
0
 public void UnderscoresAreLineContinuationsWhenTheyArePrecededByTokenBreakers()
 {
     Assert.Equal(
         new IToken[]
     {
         new NameToken("a", 0),
         new OperatorToken("&", 0),
         new NameToken("b", 1)
     },
         TokenBreaker.BreakUnprocessedToken(new UnprocessedContentToken("a&_\nb", 0)),
         new TokenSetComparer()
         );
 }
Exemple #5
0
 public void IncrementLineIndexAfterLineBreaks()
 {
     Assert.Equal(
         new IToken[]
     {
         new NameToken("Test", 0),
         new NameToken("z", 0),
         new EndOfStatementNewLineToken(0)
     },
         TokenBreaker.BreakUnprocessedToken(new UnprocessedContentToken("Test z\n", 0)),
         new TokenSetComparer()
         );
 }
Exemple #6
0
 public void LessThanComparisonOperatorIndicatesTokenBreakRegardlessOfWhitespace()
 {
     Assert.Equal(
         new IToken[]
     {
         new NameToken("value", 0),
         new ComparisonOperatorToken("<", 0),
         new ComparisonOperatorToken(">", 0)
     },
         TokenBreaker.BreakUnprocessedToken(new UnprocessedContentToken("value<>", 0)),
         new TokenSetComparer()
         );
 }
        private static IEnumerable <IToken> GetTokens(string scriptContent)
        {
            // Break down content into String, Comment and UnprocessedContent tokens
            var tokens = StringBreaker.SegmentString(scriptContent);

            // Break down further into String, Comment, Atom and AbstractEndOfStatement tokens
            var atomTokens = new List <IToken>();

            foreach (var token in tokens)
            {
                if (token is UnprocessedContentToken)
                {
                    atomTokens.AddRange(TokenBreaker.BreakUnprocessedToken((UnprocessedContentToken)token));
                }
                else
                {
                    atomTokens.Add(token);
                }
            }

            return(NumberRebuilder.Rebuild(OperatorCombiner.Combine(atomTokens)).ToList());
        }