private static Declaration ParseDeclaration(Token token, FGDLexer lexer) { switch (token.Text) { case nameof(EntityClassType.BaseClass): case nameof(EntityClassType.PointClass): case nameof(EntityClassType.SolidClass): { var nextToken = lexer.GetNextToken(); //Optional editor properties var editorProperties = new List <EditorProperty>(); nextToken = ParseEditorProperties(lexer, nextToken, editorProperties); EnsureValidToken(TokenType.Assignment, "'='", nextToken); nextToken = lexer.GetNextToken(); EnsureValidToken(TokenType.UnquotedString, "entity class name", nextToken); var entityClassName = nextToken.Text; nextToken = lexer.PeekNextToken(); var description = string.Empty; if (nextToken.Type == TokenType.Colon) { lexer.GetNextToken(); nextToken = lexer.GetNextToken(); EnsureValidToken(TokenType.QuotedString, "entity description", nextToken); description = nextToken.Text; nextToken = lexer.PeekNextToken(); } var mapProperties = new List <MapProperty>(); ParseMapProperties(lexer, nextToken, mapProperties); var type = Enum.Parse <EntityClassType>(token.Text); return(new EntityClass(type, entityClassName, description, editorProperties, mapProperties)); } default: throw new FGDParseException($"Unknown declaration \'{token.Text}\'", token.Line, token.Column); } }
private EntityClass ParseEntityClass(DeclarationGrammar declarationGrammar, FGDLexer lexer) { var nextToken = lexer.GetNextToken(); //Optional editor properties var editorProperties = new List <EditorProperty>(); nextToken = ParseEditorProperties(lexer, nextToken, editorProperties); EnsureValidToken(TokenType.Assignment, "'='", nextToken); nextToken = lexer.GetNextToken(); EnsureValidToken(TokenType.UnquotedString, "entity class name", nextToken); var entityClassName = nextToken.Text; nextToken = lexer.PeekNextToken(); var description = string.Empty; if (nextToken.Type == TokenType.Colon) { lexer.GetNextToken(); nextToken = lexer.GetNextToken(); EnsureValidToken(TokenType.QuotedString, "entity description", nextToken); description = nextToken.Text; nextToken = lexer.PeekNextToken(); } var mapProperties = new List <MapProperty>(); ParseMapProperties(lexer, nextToken, mapProperties); var type = Enum.Parse <EntityClassType>(declarationGrammar.Name); return(new EntityClass(type, entityClassName, description, editorProperties, mapProperties)); }