コード例 #1
0
        public void ScanSingleLineFalseTest()
        {
            var lexer = Lexer.CreateState("/X");

            Assert.Throws <InvalidOperationException>(() =>
                                                      CommentScanner.ScanSingleLine(lexer, ref this.token));
        }
コード例 #2
0
        public void MultiLineErrorPositionTest()
        {
            var lexer = Lexer.CreateState("/*/");

            _ = CommentScanner.ScanMultiLine(lexer, ref this.token);

            Assert.Equal(3, lexer.Src.Index);
        }
コード例 #3
0
        public void ScanMultiLineTrueTest()
        {
            var lexer = Lexer.CreateState("/**/");

            bool result = CommentScanner.ScanMultiLine(lexer, ref this.token);

            Assert.True(result);
        }
コード例 #4
0
        public void MultiLineNewLinePositionTest()
        {
            var lexer = Lexer.CreateState("/*" + Environment.NewLine + "*/");

            _ = CommentScanner.ScanMultiLine(lexer, ref this.token);

            Assert.Equal(5, lexer.Src.Index);
        }
コード例 #5
0
        public void ScanMultiLineFalseTest()
        {
            foreach (string text in new[] { "/*/", "/**", "/*" })
            {
                var lexer = Lexer.CreateState(text);

                bool result = CommentScanner.ScanMultiLine(lexer, ref this.token);

                Assert.False(result);
            }
        }
コード例 #6
0
        public void ScanMultiLineNewLineTest()
        {
            string comment = "/*" + Environment.NewLine + "*/";

            var lexer = Lexer.CreateState(comment);

            bool result = CommentScanner.ScanMultiLine(lexer, ref this.token);

            Assert.True(result);

            Assert.Equal(comment, this.token.Value);
        }
コード例 #7
0
        public void TestNegativeBlockComments(string content)
        {
            var input = new TextInputRange {
                File = new TextFile {
                    Content  = content,
                    Filename = ""
                }
            };

            var exception = Assert.Throws <Exception>(() => CommentScanner.Scan(input));

            Assert.True(exception.Message.Equals(value: "Line Comment not Escaped."));
        }
コード例 #8
0
        public void TestNegativeLineComments(string content)
        {
            var input = new TextInputRange {
                File = new TextFile {
                    Content  = content,
                    Filename = ""
                }
            };

            var output = CommentScanner.Scan(input);

            Assert.IsFalse(output);
            Assert.AreEqual(content[index: 0], input.EndChar);
        }
コード例 #9
0
        public void TestPositiveLineComments(string content)
        {
            var input = new TextInputRange {
                File = new TextFile {
                    Content  = content,
                    Filename = ""
                }
            };

            var output = CommentScanner.Scan(input);

            Assert.IsTrue(output);
            Assert.IsFalse(input.IsEndValid);
        }
コード例 #10
0
        public void TestPositiveBlockComments(string content, int line)
        {
            var input = new TextInputRange {
                File = new TextFile {
                    Content  = content,
                    Filename = ""
                }
            };

            var output = CommentScanner.Scan(input);

            Assert.IsTrue(output);
            Assert.IsFalse(input.IsEndValid);
            Assert.AreEqual(line, input.End.Line);
        }
コード例 #11
0
        public void TestNegativeLineEndLineComments(string content)
        {
            var input = new TextInputRange {
                File = new TextFile {
                    Content  = content,
                    Filename = ""
                }
            };

            var output = CommentScanner.Scan(input);

            Assert.IsTrue(output);
            Assert.IsTrue(input.IsEndValid);
            Assert.AreEqual(expected: '\n', actual: input.EndChar);
        }
コード例 #12
0
        /// <summary>
        /// Used to analyse the current textwindow and retrieve/skip any
        /// trivia which includes things such as whitespace, newlines,
        /// comments and multi-line comments
        /// Returns them as a flat list
        /// </summary>
        /// <param name="bIsTrailing"></param>
        /// <returns></returns>
        private List <SyntaxTrivia> LexSyntaxTrivia(Boolean bIsTrailing = false)
        {
            // Initialise variables
            List <SyntaxTrivia> aoReturnList      = new List <SyntaxTrivia>();
            Boolean             bNewLineCharFound = false;

            // Just keep lexing until we are told to stop
            // or we run out of characters to process
            while (TextWindow.HasCharactersLeftToProcess())
            {
                // Check the next character and switch based on that
                char xcNextChar = TextWindow.PeekCharacter();

                if (SyntaxUtilities.IsWhiteSpace(xcNextChar))
                {
                    // Try and scan the item
                    SyntaxTrivia oNewItem = WhiteSpaceScanner.Scan(TextWindow);
                    // Insert it
                    aoReturnList.Add(oNewItem);
                }
                else if (SyntaxUtilities.IsNewLineCharacter(xcNextChar))
                {
                    bNewLineCharFound = true;
                    // Do not steal trailing comments if a newline has been found
                    if (bIsTrailing)
                    {
                        break;
                    }

                    // Try and scan the item
                    SyntaxTrivia oNewItem = NewLineScanner.Scan(TextWindow);
                    // Insert it
                    aoReturnList.Add(oNewItem);
                }
                // Handle Comments
                else if (xcNextChar == '-')
                {
                    // Do not touch a single -, only play with --
                    if (TextWindow.PeekCharacter(1) != '-')
                    {
                        return(aoReturnList);
                    }
                    // Only pick up inlines if they are directly trailing an item
                    // Do not steal another nodes leading comments
                    if (bNewLineCharFound && bIsTrailing)
                    {
                        break;
                    }

                    SyntaxTrivia oComment = CommentScanner.ScanSingleLineComment(TextWindow);
                    aoReturnList.Add(oComment);
                }
                else if (xcNextChar == '/')
                {
                    // Do not touch a single /, only play with /*
                    if (TextWindow.PeekCharacter(1) != '*')
                    {
                        return(aoReturnList);
                    }

                    // Do not steal trailing comments if a newline has been found
                    if (bNewLineCharFound && bIsTrailing)
                    {
                        break;
                    }

                    SyntaxTrivia oComment = CommentScanner.ScanMultiLineComment(TextWindow);
                    aoReturnList.Add(oComment);
                }
                else
                {
                    break;
                }
            }

            return(aoReturnList);
        }
コード例 #13
0
 public void ScanSingleLineNullTest()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           CommentScanner.ScanSingleLine(null, ref this.token));
 }