private ParameterDeclarationAst(
     QualifierListAst qualifierList,
     IdentifierToken parameterType,
     IdentifierToken parameterRef,
     IdentifierToken parameterName,
     bool parameterIsArray,
     PropertyValueAst defaultValue
     )
 {
     this.QualifierList    = qualifierList ?? new QualifierListAst.Builder().Build();
     this.ParameterType    = parameterType ?? throw new ArgumentNullException(nameof(parameterType));
     this.ParameterRef     = parameterRef;
     this.ParameterName    = parameterName ?? throw new ArgumentNullException(nameof(parameterName));
     this.ParameterIsArray = parameterIsArray;
     this.DefaultValue     = defaultValue;
 }
 private PropertyDeclarationAst(
     QualifierListAst qualifierList,
     IdentifierToken returnType,
     IdentifierToken returnTypeRef,
     IdentifierToken propertyName,
     bool returnTypeIsArray,
     PropertyValueAst initializer
     )
 {
     this.QualifierList     = qualifierList ?? new QualifierListAst.Builder().Build();
     this.ReturnType        = returnType ?? throw new ArgumentNullException(nameof(returnType));
     this.ReturnTypeRef     = returnTypeRef;
     this.PropertyName      = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
     this.ReturnTypeIsArray = returnTypeIsArray;
     this.Initializer       = initializer;
 }
Beispiel #3
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        ///
        /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf
        /// A.14 Complex type value
        ///
        ///     propertyValue = primitiveTypeValue / complexTypeValue / referenceTypeValue / enumTypeValue
        ///
        /// 7.3.5
        ///
        ///     primitiveTypeValue = literalValue / literalValueArray
        ///     primitiveType = DT_Integer / DT_Real / DT_STRING / DT_DATETIME / DT_BOOLEAN / DT_OCTETSTRING
        ///
        /// A.1
        ///
        ///     complexTypeValue = complexValue / complexValueArray
        ///
        /// A.19
        ///
        ///     referenceTypeValue  = referenceValue / referenceValueArray
        ///     referenceValueArray = "{" [ objectPathValue *( "," objectPathValue ) ] 1163 "}"
        ///
        /// A.7
        ///
        ///     enumTypeValue = enumValue / enumValueArray
        ///     enumDeclaration = enumTypeHeader enumName ":" enumTypeDeclaration ";"
        ///
        /// </remarks>
        internal static PropertyValueAst Parse(ParserStream stream)
        {
            var node = new PropertyValueAst();
            var peek = stream.Peek();

            // propertyValue = primitiveTypeValue / complexTypeValue / referenceTypeValue / enumTypeValue
            if (LiteralValueAst.IsLiteralValueToken(peek))
            {
                // primitiveTypeValue -> literalValue
                node.Value = PrimitiveTypeValueAst.Parse(stream);
            }
            else if (peek is BlockOpenToken)
            {
                // we need to read the subsequent token to work out whether
                // this is a complexValueArray, literalValueArray, referenceValueArray or enumValueArray
                stream.Read();
                peek = stream.Peek();
                if (LiteralValueAst.IsLiteralValueToken(peek))
                {
                    // literalValueArray
                    stream.Backtrack();
                    node.Value = LiteralValueArrayAst.Parse(stream);
                }
                else
                {
                    // complexValueType
                    stream.Backtrack();
                    node.Value = ComplexValueArrayAst.Parse(stream);
                }
            }
            else if (peek is AliasIdentifierToken)
            {
                // referenceTypeValue
                node.Value = ReferenceTypeValueAst.Parse(stream);
            }
            else
            {
                throw new UnexpectedTokenException(peek);
            }
            // return the result
            return(node);
        }
 /// <summary>
 /// </summary>
 /// <returns></returns>
 /// <remarks>
 /// 
 /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf
 /// A.14 Complex type value
 /// 
 ///     complexTypeValue  = complexValue / complexValueArray
 ///     complexValueArray = "{" [ complexValue *( "," complexValue) ] "}"
 ///     complexValue      = ( INSTANCE / VALUE ) OF
 ///                         ( structureName / className / associationName )
 ///                         [ alias ] propertyValueList ";"
 ///     propertyValueList = "{" *propertySlot "}"
 ///     propertySlot      = propertyName "=" propertyValue ";"
 ///     propertyValue     = primitiveTypeValue / complexTypeValue / referenceTypeValue / enumTypeValue
 ///     alias             = AS aliasIdentifier
 ///     INSTANCE          = "instance" ; keyword: case insensitive
 ///     VALUE             = "value"    ; keyword: case insensitive
 ///     AS                = "as"       ; keyword: case insensitive
 ///     OF                = "of"       ; keyword: case insensitive 
 /// 
 ///     propertyName      = IDENTIFIER
 /// 
 /// </remarks>
 internal static PropertyValueAst Parse(ParserStream stream)
 {
     var node = new PropertyValueAst();
     var peek = stream.Peek();
     // propertyValue = primitiveTypeValue / complexTypeValue / referenceTypeValue / enumTypeValue
     if (LiteralValueAst.IsLiteralValueToken(peek))
     {
         // primitiveTypeValue -> literalValue
         node.Value = PrimitiveTypeValueAst.Parse(stream);
     }
     else if (peek is BlockOpenToken)
     {
         // we need to read the subsequent token to work out whether
         // this is a complexValueArray or a literalValueArray
         stream.Read();
         peek = stream.Peek();
         if (LiteralValueAst.IsLiteralValueToken(peek))
         {
             // literalValueArray
             stream.Backtrack();
             node.Value = LiteralValueArrayAst.Parse(stream);
         }
         else
         {
             // complexValueType
             stream.Backtrack();
             node.Value = ComplexValueArrayAst.Parse(stream);
         }
     }
     else if (peek is AliasIdentifierToken)
     {
         // referenceTypeValue
         node.Value = ReferenceTypeValue.Parse(stream);
     }
     else
     {
         throw new InvalidOperationException();
     }
     // return the result
     return node;
 }
Beispiel #5
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        ///
        /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf
        /// A.14 Complex type value
        ///
        ///     complexValue      = ( INSTANCE / VALUE ) OF
        ///                         ( structureName / className / associationName )
        ///                         [ alias ] propertyValueList ";"
        ///     propertyValueList = "{" *propertySlot "}"
        ///     propertySlot      = propertyName "=" propertyValue ";"
        ///     propertyValue     = primitiveTypeValue / complexTypeValue / referenceTypeValue / enumTypeValue
        ///     alias             = AS aliasIdentifier
        ///     INSTANCE          = "instance" ; keyword: case insensitive
        ///     VALUE             = "value"    ; keyword: case insensitive
        ///     AS                = "as"       ; keyword: case insensitive
        ///     OF                = "of"       ; keyword: case insensitive
        ///
        ///     propertyName      = IDENTIFIER
        ///
        /// </remarks>
        internal new static ComplexValueAst Parse(ParserStream stream)
        {
            // complexValue =
            var node = new ComplexValueAst();

            // ( INSTANCE / VALUE )
            var keyword = stream.ReadIdentifier();

            switch (keyword.GetNormalizedName())
            {
            case Keywords.INSTANCE:
                node.IsInstance = true;
                node.IsValue    = false;
                break;

            case Keywords.VALUE:
                node.IsInstance = false;
                node.IsValue    = true;
                break;

            default:
                throw new UnexpectedTokenException(keyword);
            }

            // OF
            stream.ReadIdentifier(Keywords.OF);

            // ( structureName / className / associationName )
            node.TypeName = stream.Read <IdentifierToken>().Name;
            if (!StringValidator.IsStructureName(node.TypeName) &&
                !StringValidator.IsClassName(node.TypeName) &&
                !StringValidator.IsAssociationName(node.TypeName))
            {
                throw new InvalidOperationException("Identifer is not a structureName, className or associationName");
            }

            // [ alias ]
            if (stream.PeekIdentifier(Keywords.AS))
            {
                stream.ReadIdentifier(Keywords.AS);
                var aliasName = stream.Read <AliasIdentifierToken>().Name;
                if (!StringValidator.IsIdentifier(aliasName))
                {
                    throw new InvalidOperationException("Value is not a valid aliasIdentifier");
                }
                node.Alias = aliasName;
            }

            // propertyValueList
            stream.Read <BlockOpenToken>();
            while (!stream.Eof && (stream.Peek <BlockCloseToken>() == null))
            {
                // propertyName
                var propertyName = stream.Read <IdentifierToken>().Name;
                if (!StringValidator.IsIdentifier(propertyName))
                {
                    throw new InvalidOperationException("Value is not a valid property name.");
                }
                // "="
                stream.Read <EqualsOperatorToken>();
                // propertyValue
                var propertyValue = PropertyValueAst.Parse(stream);
                // ";"
                stream.Read <StatementEndToken>();
                node.Properties.Add(propertyName, propertyValue);
            }

            // "}"
            stream.Read <BlockCloseToken>();

            // ";"
            stream.Read <StatementEndToken>();

            // return the result
            return(node);
        }