Esempio n. 1
0
        /// <summary>
        /// Sets the state based on current token type.
        /// </summary>
        protected void SetStateBasedOnCurrent()
        {
            StepTokenType currentObject = Peek();

            switch (currentObject)
            {
            case StepTokenType.STEP:
                _currentState = State.Express;
                break;

            case StepTokenType.Section:
                _currentState = State.Section;
                break;

            case StepTokenType.Entity:
                _currentState = State.Entity;
                break;

            case StepTokenType.Array:
                _currentState = State.Array;
                break;

            case StepTokenType.None:
                _currentState = State.Complete;
                break;

            default:
                throw CreateStepReaderException("While setting the reader state back to current object an unexpected ExpressType was encountered: {0}", currentObject);
            }
        }
Esempio n. 2
0
        private StepTokenType Pop()
        {
            StepTokenType value = Peek();

            _top--;

            return(value);
        }
Esempio n. 3
0
        private void ValidateEnd(StepToken endToken)
        {
            StepTokenType currentObject = Pop();

            if (GetTypeForCloseToken(endToken) != currentObject)
            {
                throw CreateStepReaderException("ExpressToken {0} is not valid for closing ExpressType {1}.", endToken, currentObject);
            }
        }
Esempio n. 4
0
        private StepTokenType Pop()
        {
            StepTokenType value = Peek();

            _stack.RemoveAt(_stack.Count - 1);
            _top--;
            _currentTypeContext = _stack[_top - 1];

            return(value);
        }
Esempio n. 5
0
 private void Push(StepTokenType value)
 {
     _top++;
     if (_stack.Count <= _top)
     {
         _stack.Add(value);
     }
     else
     {
         _stack[_top] = value;
     }
 }
Esempio n. 6
0
        private void WriteEnd(StepTokenType type)
        {
            logger.Debug(String.Format("WriteEnd( {0} ); //_currentState : {0}; _top : {1};", type, _currentState, _top));
            switch (type)
            {
            case StepTokenType.Entity:
                WriteEndObject();
                break;

            case StepTokenType.Array:
                WriteEndArray();
                break;

            default:
                throw new StepWriterException(String.Format(CultureInfo.InvariantCulture,
                                                            "Unexpected type when writing end: {0}", type));
            }
        }
Esempio n. 7
0
        private StepToken GetCloseTokenForType(StepTokenType type)
        {
            switch (type)
            {
            case StepTokenType.STEP:
                return(StepToken.EndSTEP);

            case StepTokenType.Section:
                return(StepToken.EndSection);

            case StepTokenType.Entity:
                return(StepToken.EndEntity);

            case StepTokenType.Array:
                return(StepToken.EndArray);

            default:
                throw CreateStepReaderException("Not an ExpressTokenType which can be closed");
            }
        }
Esempio n. 8
0
        private StepToken GetCloseTokenForType(StepTokenType type)
        {
            switch (type)
            {
            case StepTokenType.STEP:
                return(StepToken.EndSTEP);

            case StepTokenType.Section:
                return(StepToken.EndSection);

            case StepTokenType.Entity:
                return(StepToken.EndEntity);

            case StepTokenType.Array:
                return(StepToken.EndArray);

            case StepTokenType.LineIdentifier:
                return(StepToken.None);    //HACK

            default:
                throw new StepWriterException("No close token for type: " + type);
            }
        }
Esempio n. 9
0
 private StepToken GetCloseTokenForType(StepTokenType type)
 {
     switch (type)
     {
         case StepTokenType.STEP:
             return StepToken.EndSTEP;
         case StepTokenType.Section:
             return StepToken.EndSection;
         case StepTokenType.Entity:
             return StepToken.EndEntity;
         case StepTokenType.Array:
             return StepToken.EndArray;
         case StepTokenType.LineIdentifier:
             return StepToken.None; //HACK
         default:
             throw new StepWriterException("No close token for type: " + type);
     }
 }
Esempio n. 10
0
 private void WriteEnd(StepTokenType type)
 {
 	logger.Debug(String.Format("WriteEnd( {0} ); //_currentState : {0}; _top : {1};", type, _currentState, _top));
     switch (type)
     {
         case StepTokenType.Entity:
             WriteEndObject();
             break;
         case StepTokenType.Array:
             WriteEndArray();
             break;
         default:
             throw new StepWriterException(String.Format(CultureInfo.InvariantCulture,
                                                         "Unexpected type when writing end: {0}", type));
     }
 }
Esempio n. 11
0
 private void Push(StepTokenType value)
 {
     _top++;
     if (_stack.Count <= _top)
         _stack.Add(value);
     else
         _stack[_top] = value;
 }
Esempio n. 12
0
 private void Push(StepTokenType value)
 {
     _stack.Add(value);
     _top++;
     _currentTypeContext = value;
 }
Esempio n. 13
0
        private StepTokenType Pop()
        {
            StepTokenType value = Peek();
            _stack.RemoveAt(_stack.Count - 1);
            _top--;
            _currentTypeContext = _stack[_top - 1];

            return value;
        }
Esempio n. 14
0
 private void Push(StepTokenType value)
 {
     _stack.Add(value);
     _top++;
     _currentTypeContext = value;
 }
Esempio n. 15
0
 private StepToken GetCloseTokenForType(StepTokenType type){
     switch(type){
         case StepTokenType.STEP:
             return StepToken.EndSTEP;
         case StepTokenType.Section:
             return StepToken.EndSection;
         case StepTokenType.Entity:
             return StepToken.EndEntity;
         case StepTokenType.Array:
             return StepToken.EndArray;
         default:
             throw CreateStepReaderException("Not an ExpressTokenType which can be closed");
     }
 }
Esempio n. 16
0
        private void AutoCompleteClose(StepToken tokenBeingClosed)
        {
            // write closing symbol and calculate new state

            int levelsToComplete = 0;

            for (int i = 0; i < _top; i++)
            {
                int currentLevel = _top - i;

                if (_stack[currentLevel] == GetTypeForCloseToken(tokenBeingClosed))
                {
                    levelsToComplete = i + 1;
                    break;
                }
            }

            if (levelsToComplete == 0)
            {
                throw new StepWriterException("No token to close.");
            }

            for (int i = 0; i < levelsToComplete; i++)
            {
                StepToken token = GetCloseTokenForType(Pop());

                WriteEnd(token);
            }

            StepTokenType currentLevelType = Peek();

            switch (currentLevelType)
            {
            case StepTokenType.STEP:
                _currentState = State.STEP;
                break;

            case StepTokenType.Section:
                _currentState = State.Section;
                break;

            case StepTokenType.Entity:
                _currentState = State.Entity;
                break;

            case StepTokenType.Array:
                _currentState = State.Array;
                break;

            case StepTokenType.LineIdentifier:
                _currentState = State.LineIdentifier;
                break;

            case StepTokenType.None:
                _currentState = State.Start;
                break;

            default:
                throw new StepWriterException("Unknown StepType: " + currentLevelType);
            }
        }