示例#1
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_currToken = {_currToken}");
            //Log($"Result = {Result}");
            //Log($"_state = {_state}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.KeyWordTokenKind)
                {
                case KeyWordTokenKind.World:
                    _state = State.GotWorld;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotWorld:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                case TokenKind.Identifier:
                    Result.Name = ParseName(_currToken.Content);
                    _state      = State.GotName;
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.GotName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                    _state = State.ContentStarted;
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Is:
                    {
                        _context.Recovery(_currToken);
                        var parser = new InheritanceParser(_context, Result.Name);
                        parser.Run();
                        Result.InheritanceItems.AddRange(parser.Result);
                    }
                    break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case State.ContentStarted:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseFigureBracket:
                    Exit();
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Fun:
                    {
                        _context.Recovery(_currToken);
                        var parser = new NamedFunctionParser(_context);
                        parser.Run();
                        Result.SubItems.Add(parser.Result);
                    }
                    break;

                    default:
                        throw new UnexpectedTokenException(_currToken);
                    }
                    break;

                case TokenKind.OpenFactBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new LogicalQueryAsCodeEntityParser(_context);
                    parser.Run();
                    Result.SubItems.Add(parser.Result);
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
示例#2
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_currToken = {_currToken}");
#endif

            switch (_currToken.TokenKind)
            {
            case TokenKind.Word:
                switch (_currToken.KeyWordTokenKind)
                {
                case KeyWordTokenKind.World:
                {
                    _context.Recovery(_currToken);
                    var parser = new WorldPaser(_context);
                    parser.Run();
                    Result.Add(parser.Result);
                }
                break;

                case KeyWordTokenKind.App:
                {
                    _context.Recovery(_currToken);
                    var parser = new AppPaser(_context);
                    parser.Run();
                    Result.Add(parser.Result);
                }
                break;

                case KeyWordTokenKind.Class:
                {
                    _context.Recovery(_currToken);
                    var parser = new ClassPaser(_context);
                    parser.Run();
                    Result.Add(parser.Result);
                }
                break;

                case KeyWordTokenKind.LinguisticVariable:
                {
                    _context.Recovery(_currToken);
                    var parser = new LinguisticVariableParser(_context);
                    parser.Run();
                    Result.Add(parser.Result);
                }
                break;

                case KeyWordTokenKind.Fun:
                {
                    _context.Recovery(_currToken);
                    var parser = new NamedFunctionParser(_context);
                    parser.Run();
                    Result.Add(parser.Result);
                }
                break;

                default:
                    throw new UnexpectedTokenException(_currToken);
                }
                break;

            case TokenKind.OpenFactBracket:
            {
                _context.Recovery(_currToken);
                var parser = new LogicalQueryAsCodeEntityParser(_context);
                parser.Run();
                Result.Add(parser.Result);
            }
            break;

            default:
                throw new UnexpectedTokenException(_currToken);
            }
        }