Пример #1
0
        public void UnlexedRuleTest()
        {
            LexResultGroup lexedSource = _testLexer.Lex("   samIAm       ");

            LexResultValidator checker = lexed => lexed.MatchType == LexMatchType.None;
            LexResultParser    parser  = lexed => {
                return(DetailedParseResult.CreateError(
                           new ASTNode(ParseMatchType.None, lexed),
                           $"Unlexed token `{lexed.Text}' detected at character {lexed.Start}."
                           ));
            };

            IParseRule unlexedTokenRule = new ParseRule(checker, parser);

            DetailedParseResult result = unlexedTokenRule.Parse(lexedSource[1]) as DetailedParseResult;

            Assert.AreEqual("Unlexed token `samIAm' detected at character 3.", result.Message);
        }