コード例 #1
0
ファイル: DfaLexemeTests.cs プロジェクト: bilsaboob/Pliant
        public void DfaLexemeShouldMatchMixedCaseWord()
        {
            var wordInput = "t90vAriabl3";
            var dfa = new DfaState();
            var final = new DfaState(true);
            dfa.AddTransition(new DfaTransition(new RangeTerminal('a', 'z'), final));
            dfa.AddTransition(new DfaTransition(new RangeTerminal('A', 'Z'), final));
            final.AddTransition(new DfaTransition(new RangeTerminal('a', 'z'), final));
            final.AddTransition(new DfaTransition(new RangeTerminal('A', 'Z'), final));
            final.AddTransition(new DfaTransition(new DigitTerminal(), final));

            var dfaLexerRule = new DfaLexerRule(dfa, new TokenType("Identifier"));
            var indentifierLexeme = new DfaLexeme(dfaLexerRule);
            for (int i = 0; i < wordInput.Length; i++)
                Assert.IsTrue(indentifierLexeme.Scan(wordInput[i]));
        }
コード例 #2
0
 static WhitespaceLexerRule()
 {
     _start = new DfaState();
     var end = new DfaState(isFinal: true);
     var transition = new DfaTransition(
         new WhitespaceTerminal(),
         end);
     _start.AddTransition(transition);
     end.AddTransition(transition);
 }
コード例 #3
0
 private static ILexerRule Whitespace()
 {
     var start = new DfaState();
     var end = new DfaState(isFinal: true);
     var transition = new DfaTransition(
         new WhitespaceTerminal(),
         end);
     start.AddTransition(transition);
     end.AddTransition(transition);
     return new DfaLexerRule(start, "\\w+");
 }
コード例 #4
0
ファイル: DfaLexemeTests.cs プロジェクト: bilsaboob/Pliant
        public void DfaLexemeShouldMatchOneOrMoreRandomWhitespaceCharacters()
        {
            var randomWhitespace = "\t\f\v \r\n";
            var dfa = new DfaState();
            var final = new DfaState(true);
            dfa.AddTransition(new DfaTransition(new WhitespaceTerminal(), final));
            final.AddTransition(new DfaTransition(new WhitespaceTerminal(), final));

            var dfaLexerRule = new DfaLexerRule(dfa, new TokenType("whitespace"));
            var whitespaceLexeme = new DfaLexeme(dfaLexerRule);
            for (int i = 0; i < randomWhitespace.Length; i++)
                Assert.IsTrue(whitespaceLexeme.Scan(randomWhitespace[i]));
        }
コード例 #5
0
ファイル: DfaLexemeTests.cs プロジェクト: bilsaboob/Pliant
        public void DfaLexemeGivenCharacerLexemeNumberShouldFail()
        {
            var numberInput = "0";
            var dfa = new DfaState();
            var final = new DfaState(true);
            dfa.AddTransition(new DfaTransition(new RangeTerminal('a', 'z'), final));
            final.AddTransition(new DfaTransition(new RangeTerminal('a', 'z'), final));

            var dfaLexerRule = new DfaLexerRule(dfa, new TokenType("lowerCase"));
            var letterLexeme = new DfaLexeme(dfaLexerRule);
            Assert.IsFalse(letterLexeme.Scan(numberInput[0]));
            Assert.AreEqual(string.Empty, letterLexeme.Capture);
        }
コード例 #6
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateWhitespaceLexerRule()
 {
     var whitespaceTerminal = new WhitespaceTerminal();
     var startWhitespace = new DfaState();
     var finalWhitespace = new DfaState(true);
     startWhitespace.AddTransition(new DfaTransition(whitespaceTerminal, finalWhitespace));
     finalWhitespace.AddTransition(new DfaTransition(whitespaceTerminal, finalWhitespace));
     var whitespace = new DfaLexerRule(startWhitespace, "whitespace");
     return whitespace;
 }
コード例 #7
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateSettingIdentifierLexerRule()
 {
     // /:[a-zA-Z][a-zA-Z0-9]*/
     var start = new DfaState();
     var oneLetter = new DfaState();
     var zeroOrMoreLetterOrDigit = new DfaState(true);
     start.AddTransition(
        new DfaTransition(
            new CharacterTerminal(':'),
            oneLetter));
     oneLetter.AddTransition(
          new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z')),
             zeroOrMoreLetterOrDigit));
     zeroOrMoreLetterOrDigit.AddTransition(
         new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z'),
                 new DigitTerminal()),
             zeroOrMoreLetterOrDigit));
     return new DfaLexerRule(start, "settingIdentifier");
 }
コード例 #8
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateNotSingleQuoteLexerRule()
 {
     var start = new DfaState();
     var final = new DfaState(true);
     var terminal = new NegationTerminal(new CharacterTerminal('\''));
     var edge = new DfaTransition(terminal, final);
     start.AddTransition(edge);
     final.AddTransition(edge);
     return new DfaLexerRule(start, new TokenType(@"([^']|(\\.))+"));
 }
コード例 #9
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
        private static BaseLexerRule CreateNotDoubleQuoteLexerRule()
        {
            // ([^"]|(\\.))*
            var start = new DfaState();
            var escape = new DfaState();
            var final = new DfaState(true);

            var notDoubleQuoteTerminal = new NegationTerminal(
                new CharacterTerminal('"'));
            var escapeTerminal = new CharacterTerminal('\\');
            var anyTerminal = new AnyTerminal();

            var notDoubleQuoteEdge = new DfaTransition(notDoubleQuoteTerminal, final);
            start.AddTransition(notDoubleQuoteEdge);
            final.AddTransition(notDoubleQuoteEdge);

            var escapeEdge = new DfaTransition(escapeTerminal, escape);
            start.AddTransition(escapeEdge);
            final.AddTransition(escapeEdge);

            var anyEdge = new DfaTransition(anyTerminal, final);
            escape.AddTransition(anyEdge);

            return new DfaLexerRule(start, new TokenType(@"([^""]|(\\.))+"));
        }
コード例 #10
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateIdentifierLexerRule()
 {
     // /[a-zA-Z][a-zA-Z0-9-_]*/
     var identifierState = new DfaState();
     var zeroOrMoreLetterOrDigit = new DfaState(true);
     identifierState.AddTransition(
         new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z')),
             zeroOrMoreLetterOrDigit));
     zeroOrMoreLetterOrDigit.AddTransition(
         new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z'),
                 new DigitTerminal(),
                 new SetTerminal('-', '_')),
             zeroOrMoreLetterOrDigit));
     var identifier = new DfaLexerRule(identifierState, "identifier");
     return identifier;
 }
コード例 #11
0
ファイル: EbnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateEscapeCharacterLexerRule()
 {
     var start = new DfaState();
     var escape = new DfaState();
     var final = new DfaState(true);
     start.AddTransition(new DfaTransition(new CharacterTerminal('\\'), escape));
     escape.AddTransition(new DfaTransition(new AnyTerminal(), final));
     return new DfaLexerRule(start, "escape");
 }
コード例 #12
0
ファイル: BnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static BaseLexerRule CreateWhitespaceLexerRule()
 {
     var whitespaceTerminal = new WhitespaceTerminal();
     var startState = new DfaState();
     var finalState = new DfaState(true);
     var whitespaceTransition = new DfaTransition(whitespaceTerminal, finalState);
     startState.AddTransition(whitespaceTransition);
     finalState.AddTransition(whitespaceTransition);
     return new DfaLexerRule(startState, new TokenType("[\\s]+"));
 }
コード例 #13
0
ファイル: BnfGrammar.cs プロジェクト: bilsaboob/Pliant
 private static ILexerRule CreateRuleNameLexerRule()
 {
     var ruleNameState = new DfaState();
     var zeroOrMoreLetterOrDigit = new DfaState(true);
     ruleNameState.AddTransition(
         new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z')),
             zeroOrMoreLetterOrDigit));
     zeroOrMoreLetterOrDigit.AddTransition(
         new DfaTransition(
             new CharacterClassTerminal(
                 new RangeTerminal('a', 'z'),
                 new RangeTerminal('A', 'Z'),
                 new DigitTerminal(),
                 new SetTerminal('-', '_')),
             zeroOrMoreLetterOrDigit));
     var ruleName = new DfaLexerRule(ruleNameState, new TokenType("rule-name"));
     return ruleName;
 }