Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        /// <remarks>
        ///
        /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf
        /// A.1 Value definitions
        ///
        ///     literalValue       = integerValue / realValue /
        ///                          stringValue / octetStringValue
        ///                          booleanValue /
        ///                          nullValue /
        ///                          dateTimeValue
        ///
        /// </remarks>
        internal new static LiteralValueAst Parse(ParserStream stream)
        {
            //Note: This is a good candidate for the strategy pattern
            var peek = stream.Peek();

            if (peek is IntegerLiteralToken)
            {
                // integerValue
                return(IntegerValueAst.Parse(stream));
            }
            else if (peek is RealLiteralToken)
            {
                // doubleValue
                return(RealValueAst.Parse(stream));
            }
            else if (peek is StringLiteralToken)
            {
                // stringValue
                return(StringValueAst.Parse(stream));
            }
            else if (peek is BooleanLiteralToken)
            {
                // booleanValue
                return(BooleanValueAst.Parse(stream));
            }
            else if (peek is NullLiteralToken)
            {
                // nullValue
                return(NullValueAst.Parse(stream));
            }
            else
            {
                throw new UnexpectedTokenException(peek);
            }
        }
Beispiel #2
0
        internal static PrimitiveTypeValueAst ReadDefaultValue(ParserStream stream, IdentifierToken returnType)
        {
            switch (returnType.GetNormalizedName())
            {
            case Keywords.DT_UINT8:
            case Keywords.DT_UINT16:
            case Keywords.DT_UINT32:
            case Keywords.DT_UINT64:
            case Keywords.DT_SINT8:
            case Keywords.DT_SINT16:
            case Keywords.DT_SINT32:
            case Keywords.DT_SINT64:
            case Keywords.DT_REAL32:
            case Keywords.DT_REAL64:
            case Keywords.DT_STRING:
            case Keywords.DT_DATETIME:
            case Keywords.DT_BOOLEAN:
            case Keywords.DT_OCTECTSTRING:
                // primitiveType
                return(PrimitiveTypeValueAst.Parse(stream));

            default:
                /// structureOrClassName
                /// enumName
                /// classReference
                var peek = stream.Peek();
                if (peek is NullLiteralToken)
                {
                    return(NullValueAst.Parse(stream));
                }
                throw new UnsupportedTokenException(stream.Peek());
            }
        }