public ClassDeclarationAst(QualifierListAst qualifierList, IdentifierToken className, IdentifierToken superClass, ReadOnlyCollection <IClassFeatureAst> classFeatures) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.ClassName = className ?? throw new ArgumentNullException(nameof(className)); this.SuperClass = superClass; this.ClassFeatures = classFeatures ?? new ReadOnlyCollection <IClassFeatureAst>(new List <IClassFeatureAst>()); }
/// <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.12 Parameter declaration /// /// parameterDeclaration = [ qualifierList ] ( primitiveParamDeclaration / /// complexParamDeclaration / /// enumParamDeclaration / /// referenceParamDeclaration ) /// /// primitiveParamDeclaration = primitiveType parameterName [ array ] /// [ "=" primitiveTypeValue ] /// complexParamDeclaration = structureOrClassName parameterName [ array ] /// [ "=" ( complexTypeValue / aliasIdentifier ) ] /// enumParamDeclaration = enumName parameterName [ array ] /// [ "=" enumValue ] /// referenceParamDeclaration = classReference parameterName [ array ] /// [ "=" referenceTypeValue ] /// /// parameterName = IDENTIFIER /// /// </remarks> internal static ParameterDeclarationAst Parse(ParserStream stream) { var parameter = new ParameterDeclarationAst(); var qualifiers = default(QualifierListAst); if (stream.Peek <AttributeOpenToken>() != null) { qualifiers = QualifierListAst.Parse(stream); } parameter.Qualifiers = qualifiers; parameter.Type = stream.Read <IdentifierToken>(); if (stream.PeekIdentifier(Keywords.REF)) { stream.ReadIdentifier(Keywords.REF); parameter.IsRef = true; } else { parameter.IsRef = false; } parameter.Name = stream.Read <IdentifierToken>(); if (stream.Peek <AttributeOpenToken>() != null) { stream.Read <AttributeOpenToken>(); stream.Read <AttributeCloseToken>(); parameter.IsArray = true; } if (stream.Peek <EqualsOperatorToken>() != null) { stream.Read <EqualsOperatorToken>(); parameter.DefaultValue = ClassFeatureAst.ReadDefaultValue(stream, parameter.Type); } return(parameter); }
public StructureDeclarationAst(QualifierListAst qualifierList, IdentifierToken structureName, IdentifierToken superStructure, ReadOnlyCollection <IStructureFeatureAst> structureFeatures) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.StructureName = structureName ?? throw new ArgumentNullException(nameof(structureName)); this.SuperStructure = superStructure; this.StructureFeatures = structureFeatures ?? new ReadOnlyCollection <IStructureFeatureAst>(new List <IStructureFeatureAst>()); }
/// <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); }
public EnumerationDeclarationAst(QualifierListAst qualifierList, IdentifierToken enumName, IdentifierToken enumType, ReadOnlyCollection <EnumElementAst> enumElements) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.EnumName = enumName ?? throw new ArgumentNullException(nameof(enumName)); this.EnumType = enumType ?? throw new ArgumentNullException(nameof(enumType)); this.EnumElements = enumElements ?? new ReadOnlyCollection <EnumElementAst>( new List <EnumElementAst>() ); }
/// <summary> /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <remarks> /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0.pdf /// Section A.2 - MOF specification /// /// mofProduction = compilerDirective / /// structureDeclaration / /// classDeclaration / /// associationDeclaration / /// enumerationDeclaration / /// instanceDeclaration / /// qualifierDeclaration /// /// </remarks> internal static MofProductionAst Parse(ParserStream stream) { var peek = stream.Peek(); // compilerDirective var pragma = peek as PragmaToken; if (pragma != null) { return(CompilerDirectiveAst.Parse(stream)); } // all other mofProduction structures can start with an optional qualifierList var qualifiers = default(QualifierListAst); if (peek is AttributeOpenToken) { qualifiers = QualifierListAst.Parse(stream); } var identifier = stream.Peek <IdentifierToken>(); switch (identifier.GetNormalizedName()) { case Keywords.STRUCTURE: // structureDeclaration throw new UnsupportedTokenException(identifier); case Keywords.CLASS: // classDeclaration var @class = ClassDeclarationAst.Parse(stream, qualifiers); return(@class); case Keywords.ASSOCIATION: // associationDeclaration throw new UnsupportedTokenException(identifier); case Keywords.ENUMERATION: // enumerationDeclaration throw new UnsupportedTokenException(identifier); case Keywords.INSTANCE: case Keywords.VALUE: // instanceDeclaration var instance = ComplexTypeValueAst.Parse(stream, qualifiers); return(instance); case Keywords.QUALIFIER: // qualifierDeclaration throw new UnsupportedTokenException(identifier); default: throw new UnexpectedTokenException(peek); } #endregion }
/// <summary> /// </summary> /// <returns></returns> /// <remarks> /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf /// A.5 Class declaration /// /// classDeclaration = [ qualifierList ] CLASS className [ superClass ] /// "{" *classFeature "}" ";" /// /// className = elementName /// superClass = ":" className /// classFeature = structureFeature / /// methodDeclaration /// CLASS = "class" ; keyword: case insensitive /// /// </remarks> internal static ClassDeclarationAst ParseClassAst(ParserStream stream, QualifierListAst qualifiers) { var node = new ClassDeclarationAst(); // [ qualifierList ] node.Qualifiers = qualifiers; // CLASS stream.ReadIdentifier(Keywords.CLASS); // className var className = stream.Read <IdentifierToken>(); if (!StringValidator.IsClassName(className.Name)) { throw new InvalidOperationException("Identifer is not a valid class name."); } node.ClassName = className; // [ superClass ] if (stream.Peek <ColonToken>() != null) { stream.Read <ColonToken>(); var superclass = stream.Read <IdentifierToken>(); if (!StringValidator.IsClassName(className.Name)) { throw new InvalidOperationException("Identifer is not a valid superclass name."); } node.Superclass = superclass; } // "{" stream.Read <BlockOpenToken>(); // *classFeature while (!stream.Eof) { var peek = stream.Peek() as BlockCloseToken; if (peek != null) { break; } var classFeature = ClassFeatureAst.Parse(stream); node.Features.Add(classFeature); } // "}" ";" stream.Read <BlockCloseToken>(); stream.Read <StatementEndToken>(); return(node); }
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; }
private QualifierTypeDeclarationAst( QualifierListAst qualifierList, IdentifierToken qualifierKeyword, IdentifierToken qualifierName, IdentifierToken qualifierType, IdentifierToken qualifierScope, IdentifierToken qualifierPolicy, ReadOnlyCollection <string> flavors ) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.QualifierKeyword = qualifierKeyword ?? throw new ArgumentNullException(nameof(qualifierKeyword)); this.QualifierName = qualifierName ?? throw new ArgumentNullException(nameof(qualifierName)); this.QualifierType = qualifierType ?? throw new ArgumentNullException(nameof(qualifierType)); this.QualifierScope = qualifierScope ?? throw new ArgumentNullException(nameof(qualifierScope)); this.QualifierPolicy = qualifierPolicy ?? throw new ArgumentNullException(nameof(qualifierPolicy)); this.Flavors = flavors ?? throw new ArgumentNullException(nameof(flavors)); }
private MethodDeclarationAst( QualifierListAst qualifierList, IdentifierToken returnType, IdentifierToken returnTypeRef, bool returnTypeIsArray, IdentifierToken methodName, ReadOnlyCollection <ParameterDeclarationAst> parameters ) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.ReturnType = returnType ?? throw new ArgumentNullException(nameof(returnType)); this.ReturnTypeRef = returnTypeRef; this.ReturnTypeIsArray = returnTypeIsArray; this.Name = methodName ?? throw new ArgumentNullException(nameof(methodName)); this.Parameters = parameters ?? new ReadOnlyCollection <ParameterDeclarationAst>( new List <ParameterDeclarationAst>() ); }
internal static QualifierListAst Parse(ParserStream stream) { var ast = new QualifierListAst(); stream.Read <AttributeOpenToken>(); while (!stream.Eof) { ast.Qualifiers.Add(QualifierDeclarationAst.Parse(stream)); if (stream.Peek <CommaToken>() == null) { break; } stream.Read <CommaToken>(); } stream.Read <AttributeCloseToken>(); return(ast); }
/// <summary> /// </summary> /// <returns></returns> /// <remarks> /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf /// A.5 Class declaration /// /// classFeature = structureFeature / methodDeclaration /// /// structureFeature = structureDeclaration / ; local structure /// enumDeclaration / ; local enumeration /// propertyDeclaration /// /// structureDeclaration = [ qualifierList ] STRUCTURE structureName /// [ superstructure ] /// "{" *structureFeature "}" ";" /// /// enumDeclaration = enumTypeHeader /// enumName ":" enumTypeDeclaration ";" /// enumTypeHeader = [ qualifierList ] ENUMERATION /// /// propertyDeclaration = [ qualifierList ] ( primitivePropertyDeclaration / /// complexPropertyDeclaration / /// enumPropertyDeclaration /// referencePropertyDeclaration ) ";" /// /// methodDeclaration = [ qualifierList ] ( ( returnDataType [ array ] ) / /// VOID ) methodName /// "(" [ parameterList ] ")" ";" /// /// </remarks> internal static ClassFeatureAst Parse(ParserStream stream) { // all classFeatures start with an optional "[ qualifierList ]" var qualifierList = default(QualifierListAst); var peek = stream.Peek() as AttributeOpenToken; if ((peek as AttributeOpenToken) != null) { qualifierList = QualifierListAst.Parse(stream); } // we now need to work out if it's a structureDeclaration, enumDeclaration, // propertyDeclaration or methodDeclaration var identifier = stream.Peek <IdentifierToken>(); var identifierName = identifier.GetNormalizedName(); if (identifier == null) { throw new UnexpectedTokenException(peek); } else if (identifierName == Keywords.STRUCTURE) { // structureDeclaration throw new UnsupportedTokenException(identifier); } else if (identifierName == Keywords.ENUMERATION) { // enumDeclaration throw new UnsupportedTokenException(identifier); } else { // propertyDeclaration or methodDeclaration return(ClassFeatureAst.ParseMemberDeclaration(stream, qualifierList)); } }
internal static ClassDeclarationAst Parse(ParserStream stream, QualifierListAst qualifiers) { return(ClassDeclarationAst.ParseClassAst(stream, qualifiers)); }
public EnumElementAst(QualifierListAst qualifierList, IdentifierToken enumElementName, IEnumElementValueAst enumElementValue) { this.QualifierList = qualifierList ?? new QualifierListAst.Builder().Build(); this.EnumElementName = enumElementName; this.EnumElementValue = enumElementValue; }
/// <summary> /// </summary> /// <returns></returns> /// <remarks> /// See http://www.dmtf.org/sites/default/files/standards/documents/DSP0221_3.0.0a.pdf /// A.10 Property declaration /// Whitespace as defined in 5.2 is allowed between the elements of the rules in this ABNF section. /// /// propertyDeclaration = [ qualifierList ] ( primitivePropertyDeclaration / /// complexPropertyDeclaration / /// enumPropertyDeclaration / /// referencePropertyDeclaration) ";" /// /// primitivePropertyDeclaration = primitiveType propertyName [ array ] /// [ "=" primitiveTypeValue] /// complexPropertyDeclaration = structureOrClassName propertyName [ array ] /// [ "=" ( complexTypeValue / aliasIdentifier ) ] /// enumPropertyDeclaration = enumName propertyName [ array ] /// [ "=" enumTypeValue] /// referencePropertyDeclaration = classReference propertyName [ array ] /// [ "=" referenceTypeValue ] /// /// array = "[" "]" /// propertyName = IDENTIFIER /// structureOrClassName = IDENTIFIER /// classReference = DT_REFERENCE /// DT_REFERENCE = className REF /// REF = "ref" ; keyword: case insensitive /// /// A.11 Method declaration /// Whitespace as defined in 5.2 is allowed between the elements of the rules in this ABNF section. /// /// methodDeclaration = [ qualifierList ] ( ( returnDataType [ array ] ) / /// VOID ) methodName /// "(" [ parameterList ] ")" ";" /// /// returnDataType = primitiveType / /// structureOrClassName / /// enumName / /// classReference /// array = "[" "]" /// methodName = IDENTIFIER /// classReference = DT_REFERENCE /// DT_REFERENCE = className REF /// REF = "ref" ; keyword: case insensitive /// VOID = "void" ; keyword: case insensitive /// parameterList = parameterDeclaration *( "," parameterDeclaration ) /// private static ClassFeatureAst ParseMemberDeclaration(ParserStream stream, QualifierListAst qualifiers) { // primitiveType / structureOrClassName / enumName / classReference var returnType = stream.Read <IdentifierToken>(); var @ref = default(IdentifierToken); if (stream.PeekIdentifier(Keywords.REF)) { @ref = stream.ReadIdentifier(Keywords.REF); } // [ array ] var returnTypeIsArray = false; if (stream.Peek <AttributeOpenToken>() != null) { stream.Read <AttributeOpenToken>(); stream.Read <AttributeCloseToken>(); returnTypeIsArray = true; } // propertyName / methodName var memberName = stream.Read <IdentifierToken>(); if ((stream.Peek <ParenthesesOpenToken>() != null) && (@ref == null)) { // read the remainder of a methodDeclaration var ast = new MethodDeclarationAst { Qualifiers = qualifiers, Name = memberName, ReturnType = returnType, ReturnTypeIsArray = returnTypeIsArray }; // "(" stream.Read <ParenthesesOpenToken>(); // [ parameterList ] if (stream.Peek <ParenthesesCloseToken>() == null) { while (!stream.Eof) { if (ast.Parameters.Count > 0) { stream.Read <CommaToken>(); } var parameter = ParameterDeclarationAst.Parse(stream); ast.Parameters.Add(parameter); if (stream.Peek <ParenthesesCloseToken>() != null) { break; } } } // ")" ";" stream.Read <ParenthesesCloseToken>(); stream.Read <StatementEndToken>(); return(ast); } else { // read the remainder of a propertyDeclaration var ast = new PropertyDeclarationAst { Qualifiers = qualifiers, Name = memberName, Type = returnType, IsRef = (@ref != null) }; if (stream.Peek <AttributeOpenToken>() != null) { stream.Read <AttributeOpenToken>(); stream.Read <AttributeCloseToken>(); ast.IsArray = true; } if (stream.Peek <EqualsOperatorToken>() != null) { stream.Read <EqualsOperatorToken>(); ast.Initializer = ClassFeatureAst.ReadDefaultValue(stream, returnType); } stream.Read <StatementEndToken>(); return(ast); } }