/// <summary> /// Adds a constant rule to the context that affects all symbols in the specified array. This will throw an InvalidOperationException if called after the context is used to create tokens. /// </summary> /// <param name="symbols">The symbols to test for.</param> /// <param name="value">The token identifier to associate with the symbols.</param> /// <param name="ignoreCase">Specifies whether the rule should ignore capitalization.</param> /// <param name="priority">Determines whether the symbol should be tested before any regex rules.</param> public void Add(string[] symbols, T value, bool ignoreCase, SymbolPriority priority = SymbolPriority.Last) { if (_sorted) { throw new InvalidOperationException("Cannot add more rules after they have been used."); } if (symbols == null) { throw new ArgumentNullException(nameof(symbols)); } if (symbols.Length == 0) { throw new ArgumentException("Tried to use an empty symbol array."); } foreach (var s in symbols) { if (String.IsNullOrEmpty(s)) { throw new ArgumentException("One or more symbols in the provided array were empty or null."); } if (!Available(s)) { throw new InvalidOperationException("A rule with the symbol '" + s + "' already exists."); } (priority == SymbolPriority.First ? _listHigh : _listNormal).Add(_.Create(s, value, ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture)); _punctuation.Add(s[0]); } }
/// <summary> /// Adds a constant rule to the context. This will throw an InvalidOperationException if called after the context is used to create tokens. /// </summary> /// <param name="symbol">The symbol to test for.</param> /// <param name="value">The token identifier to associate with the symbol.</param> /// <param name="ignoreCase">Specifies whether the rule should ignore capitalization.</param> /// <param name="priority">Determines whether the symbol should be tested before any regex rules.</param> public void Add(string symbol, T value, bool ignoreCase, SymbolPriority priority = SymbolPriority.Last) { if (_sorted) { throw new InvalidOperationException("Cannot add more rules after they have been used."); } if (String.IsNullOrEmpty(symbol)) { throw new ArgumentException("Argument 'symbol' can neither be null nor empty."); } if (!Available(symbol)) { throw new InvalidOperationException("A rule with the symbol '" + symbol + "' already exists."); } (priority == SymbolPriority.First ? _listHigh : _listNormal).Add(_.Create(symbol, value, ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture)); _punctuation.Add(symbol[0]); }