internal RequisiteAnnotation Parse(List<Token> tokens) { if (tokens == null) { throw new ArgumentNullException(nameof(tokens)); } if (tokens.Count == 0) { throw new ArgumentException("tokens can't be empty"); } RequisiteAnnotation annotation = new RequisiteAnnotation { IsNegation = false, Attribute = string.Empty, Trait = string.Empty, Level = null }; ParseExpression(tokens, ref annotation); if (tokens.Count > 0) { throw new ArgumentException($"Extra tokens at the end of the expression. Next extra token is {tokens[0]}"); } return annotation; }
private void ParseExpression(List<Token> tokens, ref RequisiteAnnotation annotation) { Token current = tokens[0]; switch (current.TokenType) { case TokenType.Negation: annotation.IsNegation = true; tokens.RemoveAt(0); ParsePositiveExpression(tokens, ref annotation); break; case TokenType.Number: throw new ArgumentException($"Invalid token {current} found. Expected token types were: {nameof(TokenType.Negation)}, {nameof(TokenType.Attribute)}, {nameof(TokenType.Trait)}"); default: ParsePositiveExpression(tokens, ref annotation); break; } }
private void ParseNumber(List<Token> tokens, ref RequisiteAnnotation annotation) { if (tokens.Count == 0) { return; } Token current = tokens[0]; switch (current.TokenType) { case TokenType.Number: annotation.Level = int.Parse(current.Text); tokens.RemoveAt(0); break; default: throw new ArgumentException($"Invalid token {current} found. Expected token types were: {nameof(TokenType.Number)}"); } }
public static Requisite FromRequisiteAnnotation(RequisiteAnnotation annotation) { return Requisite.Default.Value; }