/// <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); }
internal static ClassDeclarationAst Parse(ParserStream stream, QualifierListAst qualifiers) { return(ClassDeclarationAst.ParseClassAst(stream, qualifiers)); }
internal new static ClassDeclarationAst Parse(ParserStream stream) { return(ClassDeclarationAst.ParseClassAst(stream, null)); }