Esempio n. 1
0
 public ILexeme Create(ILexerRule lexerRule)
 {
     if (lexerRule.LexerRuleType != LexerRuleType)
         throw new Exception(
             string.Format(
                 "Unable to create TerminalLexeme from type {0}. Expected TerminalLexerRule",
                 lexerRule.GetType().FullName));
     var terminalLexerRule = lexerRule as ITerminalLexerRule;
     return new TerminalLexeme(terminalLexerRule);
 }
Esempio n. 2
0
 public ILexeme Create(ILexerRule lexerRule)
 {
     if (lexerRule.LexerRuleType != LexerRuleType)
         throw new Exception(
             string.Format(
                 "Unable to create DfaLexeme from type {0}. Expected DfaLexerRule",
                 lexerRule.GetType().FullName));
     var dfaLexerRule = lexerRule as IDfaLexerRule;
     return new DfaLexeme(dfaLexerRule.Start, dfaLexerRule.TokenType);
 }
Esempio n. 3
0
        public ILexeme Create(ILexerRule lexerRule)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
                throw new Exception(
                    string.Format(
                        "Unable to create ParseEngineLexeme from type {0}. Expected TerminalLexerRule",
                        lexerRule.GetType().FullName));

            var grammarLexerRule = lexerRule as IGrammarLexerRule;
            var parseEngine = new ParseEngine(grammarLexerRule.Grammar);

            return new ParseEngineLexeme(parseEngine, grammarLexerRule.TokenType);
        }
Esempio n. 4
0
        public ILexeme Create(ILexerRule lexerRule)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
                throw new Exception(
                    $"Unable to create TerminalLexeme from type {lexerRule.GetType().FullName}. Expected TerminalLexerRule");

            var terminalLexerRule = lexerRule as ITerminalLexerRule;
            if (_queue.Count == 0)
                return new TerminalLexeme(terminalLexerRule);

            var reusedLexeme = _queue.Dequeue();
            reusedLexeme.Reset(terminalLexerRule);
            return reusedLexeme;
        }
Esempio n. 5
0
 public ILexeme Create(ILexerRule lexerRule)
 {
     if (lexerRule.LexerRuleType != LexerRuleType)
         throw new Exception(
             $"Unable to create DfaLexeme from type {lexerRule.GetType().FullName}. Expected DfaLexerRule");
     var dfaLexerRule = lexerRule as IDfaLexerRule;
     if (_queue.Count > 0)
     {
         var reusedLexeme = _queue.Dequeue();
         reusedLexeme.Reset(dfaLexerRule);
         return reusedLexeme;
     }
     return new DfaLexeme(dfaLexerRule);
 }
Esempio n. 6
0
        public ILexeme Create(ILexerRule lexerRule, int position)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
            {
                throw new Exception(
                          $"Unable to create DfaLexeme from type {lexerRule.GetType().FullName}. Expected DfaLexerRule");
            }
            var dfaLexerRule = lexerRule as IDfaLexerRule;

            if (_queue.Count > 0)
            {
                var reusedLexeme = _queue.Dequeue();
                reusedLexeme.Reset(dfaLexerRule);
                return(reusedLexeme);
            }
            return(new DfaLexeme(dfaLexerRule, position));
        }
Esempio n. 7
0
        public ILexeme Create(ILexerRule lexerRule, ICapture <char> segment, int offset)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
            {
                throw new Exception(
                          $"Unable to create StringLiteralLexeme from type {lexerRule.GetType().FullName}. Expected StringLiteralLexerRule");
            }
            var stringLiteralLexerRule = lexerRule as IStringLiteralLexerRule;

            if (_queue.Count == 0)
            {
                return(new StringLiteralLexeme(stringLiteralLexerRule, segment, offset));
            }

            var reusedLexeme = _queue.Dequeue();

            reusedLexeme.Reset(stringLiteralLexerRule, offset);
            return(reusedLexeme);
        }
Esempio n. 8
0
        public ILexeme Create(ILexerRule lexerRule, ICapture <char> segment, int offset)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
            {
                throw new Exception(
                          $"Unable to create DfaLexeme from type {lexerRule.GetType().FullName}. Expected DfaLexerRule");
            }
            var dfaLexerRule = lexerRule as IDfaLexerRule;

            if (_queue.Count > 0)
            {
                var reusedLexeme = _queue.Dequeue();
                reusedLexeme.Reset(dfaLexerRule, offset);
                return(reusedLexeme);
            }
            var dfaLexeme = new DfaLexeme(dfaLexerRule, segment, offset);

            return(dfaLexeme);
        }
Esempio n. 9
0
        public ILexeme Create(ILexerRule lexerRule, int position)
        {
            if (lexerRule.LexerRuleType != LexerRuleType)
            {
                throw new Exception(
                          $"Unable to create ParseEngineLexeme from type {lexerRule.GetType().FullName}. Expected TerminalLexerRule");
            }

            var grammarLexerRule = lexerRule as IGrammarLexerRule;

            if (_queue.Count == 0)
            {
                return(new ParseEngineLexeme(grammarLexerRule));
            }

            var reusedLexeme = _queue.Dequeue();

            reusedLexeme.Reset(grammarLexerRule);
            return(reusedLexeme);
        }
Esempio n. 10
0
        public ILexeme Create(ILexerRule lexerRule, ICapture <char> segment, int offset)
        {
            if (!LexerRuleType.Equals(lexerRule.LexerRuleType))
            {
                throw new Exception(
                          $"Unable to create TerminalLexeme from type {lexerRule.GetType().FullName}. Expected TerminalLexerRule");
            }

            var terminalLexerRule = lexerRule as ITerminalLexerRule;

            if (_queue.Count == 0)
            {
                return(new TerminalLexeme(terminalLexerRule, segment, offset));
            }

            var reusedLexeme = _queue.Dequeue();

            reusedLexeme.Reset(terminalLexerRule, offset);
            return(reusedLexeme);
        }