public PermissionGroup(PermissionClass @class, string name, PermissionGroupType type, Dictionary <string, string> properties) { Class = @class; Name = name; Type = type; Permissions = new List <Permission>(); Properties = properties; }
public static PermissionClass Parse(Lexer <PermissionTokenType> lexer, string moduleID) { PermissionClass @class = new PermissionClass(moduleID); PermissionGroup premissionGroup = null; PermissionGroupType state = PermissionGroupType.Class; Token <PermissionTokenType> token = lexer.GetToken(); while (token != null) { if (token.Type == PermissionTokenType.TargetType) { if (state == PermissionGroupType.Class) { @class.AddPermission(ParsePermission(lexer)); } else if (premissionGroup != null) { premissionGroup.AddPermission(ParsePermission(lexer)); } } else if (token.Type == PermissionTokenType.Bracket) { PermissionGroup group = ParseBracket(lexer, @class); state = group.Type; if (state == PermissionGroupType.Class) { @class.Properties = group.Properties; } else { premissionGroup = group; @class.AddPermissionGroup(group); } } else { lexer.NextToken(); } token = lexer.GetToken(); } return(@class); }
static PermissionGroup ParseBracket(Lexer <PermissionTokenType> lexer, PermissionClass @class) { PermissionGroupType type = PermissionGroupType.Method; string name = ""; Token <PermissionTokenType> token = lexer.GetToken(); if (token.Type == PermissionTokenType.Bracket && token.Value != "<") { throw new Exception($"Wrong token got {token.Value} expected <"); } token = lexer.NextToken(); if (token.Type == PermissionTokenType.Type) { type = Enum.Parse <PermissionGroupType>(token.Value, true); token = lexer.NextToken(); } if (token.Type == PermissionTokenType.Colon) { token = lexer.NextToken(); } if (token.Type == PermissionTokenType.Text && lexer.Peek(1)?.Type != PermissionTokenType.Colon) { name = token.Value; } else if (lexer.Peek(1)?.Type != PermissionTokenType.Colon) { throw new Exception($"Wrong token type got {token.Type} expected Type or Text"); } Dictionary <string, string> properties = ParseProperties(lexer); token = lexer.GetToken(); if (token.Type == PermissionTokenType.Bracket && token.Value == ">") { lexer.NextToken(); return(new PermissionGroup(@class, name, type, properties)); } else { throw new Exception($"Wrong token got {token.Value} expected >"); } }