private static INfa Character(RegexCharacterClassCharacter character, bool negate)
 {
     var start = new NfaState();
     var end = new NfaState();
     ITerminal terminal = new CharacterTerminal(character.Value);
     if (negate)
         terminal = new NegationTerminal(terminal);
     var transition = new TerminalNfaTransition(
         terminal: terminal,
         target: end);
     start.AddTransistion(transition);
     return new Nfa(start, end);
 }
Esempio n. 2
0
 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(@"([^']|(\\.))+"));
 }
Esempio n. 3
0
        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(@"([^""]|(\\.))+"));
        }
Esempio n. 4
0
        private static BaseLexerRule CreateMultiLineCommentLexerRule()
        {
            var pattern = @"\/[*]([*][^\/]|[^*])*[*][\/]";

            var states = new DfaState[5];
            for (int i = 0; i < states.Length; i++)
                states[i] = new DfaState();

            var slash = new CharacterTerminal('/');
            var star = new CharacterTerminal('*');
            var notStar = new NegationTerminal(star);
            var notSlash = new NegationTerminal(slash);

            var firstSlash = new DfaTransition(slash, states[1]);
            var firstStar = new DfaTransition(star, states[2]);
            var repeatNotStar = new DfaTransition(notStar, states[2]);
            var lastStar = new DfaTransition(star, states[3]);
            var goBackNotSlash = new DfaTransition(notSlash, states[2]);
            var lastSlash = new DfaTransition(slash, states[4]);

            states[0].AddTransition(firstSlash);
            states[1].AddTransition(firstStar);
            states[2].AddTransition(repeatNotStar);
            states[2].AddTransition(lastStar);
            states[3].AddTransition(goBackNotSlash);
            states[3].AddTransition(lastSlash);

            return new DfaLexerRule(states[0], pattern);
        }
Esempio n. 5
0
 private static ILexerRule CreateNotSingleQuoteLexerRule()
 {
     var start = new DfaState();
     var final = new DfaState(true);
     var terminal = new NegationTerminal(new Terminal('\''));
     var edge = new DfaEdge(terminal, final);
     start.AddEdge(edge);
     final.AddEdge(edge);
     return new DfaLexerRule(start, new TokenType("not-single-quote"));
 }
Esempio n. 6
0
        private static ILexerRule CreateNotDoubleQuoteLexerRule()
        {
            // ( [^"\\] | (\\ .) ) +
            var start = new DfaState();
            var escape = new DfaState();
            var final = new DfaState(true);

            var notQuoteTerminal = new NegationTerminal(
                new SetTerminal('"', '\\'));
            var escapeTerminal = new Terminal('\\');
            var anyTerminal = new AnyTerminal();

            var notQuoteEdge = new DfaEdge(notQuoteTerminal, final);
            start.AddEdge(notQuoteEdge);
            final.AddEdge(notQuoteEdge);

            var escapeEdge = new DfaEdge(escapeTerminal, escape);
            start.AddEdge(escapeEdge);
            final.AddEdge(escapeEdge);

            var anyEdge = new DfaEdge(anyTerminal, final);
            escape.AddEdge(anyEdge);

            return new DfaLexerRule(start, new TokenType("not-double-quote"));
        }
 private static INfa Range(RegexCharacterRange range, bool negate)
 {
     // combine characters into a character range terminal
     var start = range.StartCharacter.Value;
     var end = range.EndCharacter.Value;
     ITerminal terminal = new RangeTerminal(start, end);
     var nfaStartState = new NfaState();
     var nfaEndState = new NfaState();
     if (negate)
         terminal = new NegationTerminal(terminal);
     nfaStartState.AddTransistion(
         new TerminalNfaTransition(terminal, nfaEndState));
     return new Nfa(nfaStartState, nfaEndState);
 }