コード例 #1
0
        private void ParseBody()
        {
            _context.Recovery(_currToken);
            var parser = new FunctionBodyParser(_context);

            parser.Run();

#if DEBUG
            //Log($"parser.Result = {parser.Result.WriteListToString()}");
#endif

            Result.Statements = parser.Result;

            Exit();
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override void OnRun()
        {
#if DEBUG
            //Log($"_state = {_state}");
            //Log($"_currToken = {_currToken}");
#endif

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Try:
                        _state = State.GotTryMark;
                        break;

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

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

            case State.GotTryMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new FunctionBodyParser(_context);
                    parser.Run();
                    var statementsList = parser.Result;

#if DEBUG
                    //Log($"statementsList = {statementsList.WriteListToString()}");
#endif

                    _rawStatement.TryStatements = statementsList;

                    _state = State.GotTryBody;
                }
                break;

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

            case State.GotTryBody:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Else:
                        _state = State.GotElseMark;
                        break;

                    case KeyWordTokenKind.Ensure:
                        _state = State.GotEnsureMark;
                        break;

                    case KeyWordTokenKind.Catch:
                        ProcessCatch();
                        break;

                    case KeyWordTokenKind.Select:
                    case KeyWordTokenKind.Insert:
                        _context.Recovery(_currToken);
                        Exit();
                        break;

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

                case TokenKind.CloseFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.String:
                case TokenKind.Number:
                case TokenKind.Var:
                case TokenKind.SystemVar:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

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

            case State.GotCatch:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Else:
                        _state = State.GotElseMark;
                        break;

                    case KeyWordTokenKind.Ensure:
                        _state = State.GotEnsureMark;
                        break;

                    case KeyWordTokenKind.Catch:
                        ProcessCatch();
                        break;

                    case KeyWordTokenKind.Select:
                    case KeyWordTokenKind.Insert:
                        _context.Recovery(_currToken);
                        Exit();
                        break;

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

                case TokenKind.CloseFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.String:
                case TokenKind.Number:
                case TokenKind.Var:
                case TokenKind.SystemVar:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

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

            case State.GotElseMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new FunctionBodyParser(_context);
                    parser.Run();
                    var statementsList = parser.Result;

#if DEBUG
                    //Log($"statementsList = {statementsList.WriteListToString()}");
#endif

                    _rawStatement.ElseStatements = statementsList;

                    _state = State.GotElseBody;
                }
                break;

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

            case State.GotElseBody:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Ensure:
                        _state = State.GotEnsureMark;
                        break;

                    case KeyWordTokenKind.Select:
                    case KeyWordTokenKind.Insert:
                        _context.Recovery(_currToken);
                        Exit();
                        break;

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

                case TokenKind.CloseFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.String:
                case TokenKind.Number:
                case TokenKind.Var:
                case TokenKind.SystemVar:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

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

            case State.GotEnsureMark:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new FunctionBodyParser(_context);
                    parser.Run();
                    var statementsList = parser.Result;

#if DEBUG
                    //Log($"statementsList = {statementsList.WriteListToString()}");
#endif

                    _rawStatement.EnsureStatements = statementsList;

                    _state = State.GotEnsureBody;
                }
                break;

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

            case State.GotEnsureBody:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Select:
                    case KeyWordTokenKind.Insert:
                        _context.Recovery(_currToken);
                        Exit();
                        break;
                    }
                    break;

                case TokenKind.CloseFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.String:
                case TokenKind.Number:
                case TokenKind.Var:
                case TokenKind.SystemVar:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

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

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }
コード例 #3
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.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.On:
                        _state = State.WaitForCondition;
                        break;

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

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

            case State.WaitForCondition:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Init:
                        _inlineTrigger.Kind = KindOfInlineTrigger.SystemEvent;
                        _inlineTrigger.KindOfSystemEvent = KindOfSystemEventOfInlineTrigger.Init;
                        _state = State.GotCondition;
                        break;

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

                case TokenKind.OpenFactBracket:
                {
                    _inlineTrigger.Kind = KindOfInlineTrigger.LogicConditional;

                    _context.Recovery(_currToken);

                    var parser = new LogicalQueryParser(_context);
                    parser.Run();

                    _inlineTrigger.Condition = parser.Result;

                    _state = State.GotCondition;
                }
                break;

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

            case State.GotCondition:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Lambda:
                    _state = State.WaitForAction;
                    break;

                case TokenKind.OpenRoundBracket:
                {
                    _context.Recovery(_currToken);

                    var parser = new InlineTriggerBindingVariablesParser(_context);
                    parser.Run();

#if DEBUG
                    //Log($"parser.Result = {parser.Result.WriteListToString()}");
#endif

                    _inlineTrigger.BindingVariables = new BindingVariables(parser.Result);

                    _state = State.GotBindingVariables;
                }
                break;

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

            case State.GotBindingVariables:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Lambda:
                    _state = State.WaitForAction;
                    break;

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

            case State.WaitForAction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new FunctionBodyParser(_context);
                    parser.Run();
                    var statementsList = parser.Result;
                    _inlineTrigger.Statements           = statementsList;
                    _inlineTrigger.CompiledFunctionBody = _context.Compiler.Compile(statementsList);
                    _state = State.GotAction;
                }
                break;

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

            case State.GotAction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.CloseFigureBracket:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.On:
                        _context.Recovery(_currToken);
                        Exit();
                        break;

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

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

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

            switch (_state)
            {
            case State.Init:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    switch (_currToken.KeyWordTokenKind)
                    {
                    case KeyWordTokenKind.Fun:
                        _state = State.GotNamedFunctionMark;
                        break;

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

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

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

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

            case State.GotName:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenRoundBracket:
                {
                    _context.Recovery(_currToken);

                    var parser = new FunctionParametersParser(_context);
                    parser.Run();

                    _namedFunction.Arguments = parser.Result;

                    _state = State.GotParameters;
                }
                break;

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

            case State.GotParameters:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Lambda:
                    _state = State.WaitForAction;
                    break;

                case TokenKind.OpenFigureBracket:
                    _context.Recovery(_currToken);
                    _state = State.WaitForAction;
                    break;

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

            case State.WaitForAction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.OpenFigureBracket:
                {
                    _context.Recovery(_currToken);
                    var parser = new FunctionBodyParser(_context);
                    parser.Run();
                    var statementsList = parser.Result;

                    _namedFunction.Statements           = statementsList;
                    _namedFunction.CompiledFunctionBody = _context.Compiler.Compile(statementsList);
                    _state = State.GotAction;
                }
                break;

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

            case State.GotAction:
                switch (_currToken.TokenKind)
                {
                case TokenKind.Word:
                    _context.Recovery(_currToken);
                    Exit();
                    break;

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

            default:
                throw new ArgumentOutOfRangeException(nameof(_state), _state, null);
            }
        }