Example #1
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
        ///
        ///     complexTypeValue  = complexValue / complexValueArray
        ///
        /// </remarks>
        internal static ComplexTypeValueAst Parse(ParserStream stream, QualifierListAst qualifiers)
        {
            var node = default(ComplexTypeValueAst);

            var peek = stream.Peek();

            if (peek is BlockOpenToken)
            {
                // complexValueArray
                node = ComplexValueArrayAst.Parse(stream);
            }
            else if (peek is IdentifierToken)
            {
                // complexValue
                node = ComplexValueAst.Parse(stream);
            }
            else
            {
                throw new UnexpectedTokenException(peek);
            }

            node.Qualifiers = qualifiers;

            return(node);
        }
Example #2
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
        ///
        ///     complexValueArray = "{" [ complexValue *( "," complexValue) ] "}"
        ///
        /// </remarks>
        internal new static ComplexValueArrayAst Parse(ParserStream stream)
        {
            // complexValueArray =
            var node = new ComplexValueArrayAst();

            // "{"
            stream.Read <BlockOpenToken>();
            // [ complexValue
            node.Values.Add(ComplexValueAst.Parse(stream));
            // *( "," complexValue) ]
            while (stream.Peek <CommaToken>() != null)
            {
                stream.Read <CommaToken>();
                node.Values.Add(ComplexValueAst.Parse(stream));
            }
            // "}"
            stream.Read <BlockCloseToken>();
            // return the result
            return(node);
        }
Example #3
0
 public static Instance FromAstNode(ComplexValueAst node)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     if (!node.IsInstance)
     {
         throw new ArgumentException("Value must represent an instance.", "node");
     }
     var instance = new Instance
     {
         ClassName = node.TypeName,
         Alias = node.Alias
     };
     foreach (var property in node.Properties)
     {
         var propertyValue = property.Value.Value;
         if ((propertyValue as LiteralValueArrayAst) != null)
         {
             var itemValues = ((LiteralValueArrayAst)propertyValue).Values
                                                                   .Select(Instance.GetLiteralValue)
                                                                   .ToArray();
             instance.Properties.Add(property.Key, itemValues);
         }
         else if ((propertyValue as LiteralValueAst) != null)
         {
             instance.Properties.Add(property.Key, Instance.GetLiteralValue((LiteralValueAst)propertyValue));
         }
         else if ((propertyValue as ReferenceTypeValue) != null)
         {
             instance.Properties.Add(property.Key, (((ReferenceTypeValue)propertyValue).Name));
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     return instance;
 }
 /// <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 new ComplexValueAst Parse(ParserStream stream)
 {
     // complexValue =
     var node = new ComplexValueAst();
     // ( INSTANCE / VALUE )
     var keyword = stream.ReadKeyword();
     switch (keyword.Name)
     {
         case "instance":
             node.IsInstance = true;
             node.IsValue = false;
             break;
         case "value":
             node.IsInstance = false;
             node.IsValue = true;
             break;
         default:
             throw new InvalidOperationException();
     }
     // OF
     stream.ReadKeyword("of");
     // ( structureName / className / associationName )
     node.TypeName = stream.Read<IdentifierToken>().Name;
     // [ alias ]
     if (stream.PeekKeyword("as"))
     {
         stream.ReadKeyword("as");
         // BUGBUG - PowerShell DSC MOFs allow schema names in an alias identifier
         //node.Alias = NameValidator.ValidateAliasIdentifier("$" + stream.Read<AliasIdentifierToken>().Name);
         node.Alias = stream.Read<AliasIdentifierToken>().Name;
     }
     // propertyValueList
     stream.Read<BlockOpenToken>();
     while (!stream.Eof && (stream.Peek<BlockCloseToken>() == null))
     {
         // propertyName
         var propertyName = NameValidator.ValidateIdentifier(stream.Read<IdentifierToken>().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;
 }
Example #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);
        }