/// <summary> /// Gets the maximum length of operator symbols starting with <see cref="startingWith" />. /// </summary> /// <param name="type">The type of the operators.</param> /// <param name="startingWith">The starting with.</param> /// <returns>The maximum length</returns> /// <exception cref="System.ArgumentNullException">Thrown of <see cref="startingWith" /> is null.</exception> public static int GetMaxOperatorLength(EarleOperatorType type, string startingWith) { if (startingWith == null) throw new ArgumentNullException(nameof(startingWith)); var vals = GetOperatorSymbols(type) .Where(o => o.StartsWith(startingWith, StringComparison.InvariantCulture)) .ToArray(); return vals.Any() ? vals.Max(o => o.Length) : 0; }
protected OpCode GetOperator(EarleOperatorType type) { var str = ""; do { str += Lexer.Current.Value; Lexer.AssertMoveNext(); } while (Lexer.Current.Is(TokenType.Token) && EarleOperators.GetMaxOperatorLength(type, str) > str.Length); return EarleOperators.GetOperator(type, str); }
/// <summary> /// Initializes a new instance of the <see cref="OperatorAttribute" /> class. /// </summary> /// <param name="symbol">The symbol.</param> /// <param name="type">The type.</param> /// <param name="priority">The priority.</param> public OperatorAttribute(string symbol, EarleOperatorType type, int priority = 0) { Symbol = symbol; Type = type; Priority = priority; }
/// <summary> /// Gets the operator with the specified type and symbol /// </summary> /// <param name="type">The type.</param> /// <param name="symbol">The symbol.</param> /// <returns>The operation code of the operator.</returns> public static OpCode GetOperator(EarleOperatorType type, string symbol) { OpCode value; GetOperators(type).TryGetValue(symbol, out value); return value; }
/// <summary> /// Gets the operator symbols of the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>The operator symbols of the specified type.</returns> public static IEnumerable<string> GetOperatorSymbols(EarleOperatorType type) { return GetOperators(type).Keys; }
/// <summary> /// Gets the operators of the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns>The operators of the specified type.</returns> public static Dictionary<string, OpCode> GetOperators(EarleOperatorType type) { Dictionary<string, OpCode> value; if (!Operators.TryGetValue(type, out value)) Operators[type] = value = new Dictionary<string, OpCode>(); return value; }