Пример #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);
 }
Пример #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);
 }
Пример #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);
        }
Пример #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;
        }
Пример #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);
 }
Пример #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));
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }