示例#1
0
        // V -> S | Identifier | String | Boolean | Integer | Decimal
        private object MatchValue()
        {
            VerifyTokensExists();

            if ((TokenType)tokens.Peek().Id == TokenType.Terminal)
            {
                return(MatchElement());
            }

            Token  token = tokens.Pop();
            object constValue;

            switch ((TokenType)token.Id)
            {
            case TokenType.Identifier: constValue = token.Value; break;

            case TokenType.String: constValue = token.Value.Substring(1, token.Value.Length - 2).Replace("''", "'"); break;

            case TokenType.Boolean: constValue = BooleanParse(token.Value); break;

            case TokenType.Integer: constValue = Int32.Parse(token.Value); break;

            case TokenType.Decimal: constValue = Double.Parse(token.Value); break;

            default: throw new Granular.Exception("Can't parse \"{0}\", value is expected, \"{1}\" was found at index {2}", text, token.Value, token.Start);
            }

            return(constValue);
        }
示例#2
0
        private string MatchValue()
        {
            VerifyTokensExists();

            Token token = tokens.Pop();

            if ((TokenType)token.Id != TokenType.Value)
            {
                throw new Granular.Exception("Can't parse \"{0}\", \"{1}\" was not expected at index {2}", text, token.Value, token.Start);
            }

            return(token.Value);
        }
示例#3
0
            private SnapshotLineRange?ReadNormal()
            {
                do
                {
                    var oldStack = _stack;
                    if (oldStack.IsEmpty)
                    {
                        return(null);
                    }

                    var newStack = _stack.Pop();
                    var success  = oldStack == Interlocked.CompareExchange(ref _stack, newStack, oldStack);
                    if (success)
                    {
                        return(oldStack.Value);
                    }
                } while (true);
            }