Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 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;
     }
 }
Exemplo n.º 3
0
        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)}");
            }
        }
Exemplo n.º 4
0
 public static Requisite FromRequisiteAnnotation(RequisiteAnnotation annotation)
 {
     return Requisite.Default.Value;
 }