コード例 #1
0
ファイル: Parser.cs プロジェクト: dionrhys/vbscripttranslator
        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));
        }
コード例 #2
0
 public void EmptyContentEscapedVariableNameIsSetToNumericValue()
 {
     Assert.Equal(
         new IToken[]
     {
         new EscapedNameToken("[]", 0),
         new UnprocessedContentToken(" = 1", 0)
     },
         StringBreaker.SegmentString(
             "[] = 1"
             ),
         new TokenSetComparer()
         );
 }
コード例 #3
0
 public void NonLineReturningWhiteSpaceBetweenCommentsIsIgnored()
 {
     Assert.Equal(
         new IToken[]
     {
         new CommentToken(" Comment 1", 0),
         new CommentToken(" Comment 2", 1)
     },
         StringBreaker.SegmentString(
             "' Comment 1\n ' Comment 2"
             ),
         new TokenSetComparer()
         );
 }
コード例 #4
0
 public void REMCommentsAreIdentified()
 {
     Assert.Equal(
         new IToken[]
     {
         new CommentToken(" Test", 0),
         new UnprocessedContentToken("WScript.Echo 1", 1)
     },
         StringBreaker.SegmentString(
             "REM Test\nWScript.Echo 1"
             ),
         new TokenSetComparer()
         );
 }
コード例 #5
0
 public void InlineREMCommentsAreIdentified()
 {
     Assert.Equal(
         new IToken[]
     {
         new UnprocessedContentToken("WScript.Echo 1", 0),
         new EndOfStatementSameLineToken(0),
         new InlineCommentToken(" Test", 0)
     },
         StringBreaker.SegmentString(
             "WScript.Echo 1 REM Test"
             ),
         new TokenSetComparer()
         );
 }
コード例 #6
0
 public void VariableSetToStringContentIncludedQuotedContent()
 {
     Assert.Equal(
         new IToken[]
     {
         new UnprocessedContentToken("strValue = ", 0),
         new StringToken("Test string with \"quoted\" content", 0),
         new UnprocessedContentToken("\n", 0)
     },
         StringBreaker.SegmentString(
             "strValue = \"Test string with \"\"quoted\"\" content\"\n"
             ),
         new TokenSetComparer()
         );
 }
コード例 #7
0
 public void WhitespaceBetweenStringTokenAndCommentDoesNotPreventEndOfStatementBeingInserted()
 {
     Assert.Equal(
         new IToken[]
     {
         new UnprocessedContentToken("a = ", 0),
         new StringToken("", 0),
         new EndOfStatementSameLineToken(0),
         new CommentToken(" Comment", 0)
     },
         StringBreaker.SegmentString(
             "a = \"\" ' Comment"
             ),
         new TokenSetComparer()
         );
 }
コード例 #8
0
 public void InlineCommentsAreIdentifiedAsSuchWhenAfterMultipleLinesOfContent()
 {
     // The StringBreaker will insert an EndOfStatementSameLineToken between the UnprocessedContentToken and InlineCommentToken
     // since that the later processes rely on end-of-statement tokens, even before an inline comment
     Assert.Equal(
         new IToken[]
     {
         new UnprocessedContentToken("\nWScript.Echo 1", 0),
         new EndOfStatementSameLineToken(0),
         new InlineCommentToken(" Test", 1)
     },
         StringBreaker.SegmentString(
             "\nWScript.Echo 1 ' Test"
             ),
         new TokenSetComparer()
         );
 }
コード例 #9
0
        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());
        }