public static void IsStructureNameTest(string value, bool expectedResult) { var result = StringValidator.IsStructureName(value); Assert.AreEqual(expectedResult, result); }
/// <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); }