/// <summary> /// Skip whitespace, peek and raise error if not in range. /// </summary> /// <param name="exceptionToRaise">Exception to raise in case next char is not in range</param> /// <param name="acceptable">List of acceptable chars</param> public void Require(ReplExceptionCode exceptionToRaise = ReplExceptionCode.SyntaxError, params int[] acceptable) { var nextNonWhiteSpace = this.SkipWhitespace(); if (!acceptable.Contains(nextNonWhiteSpace)) { throw new ReplRuntimeException(exceptionToRaise); } }
/// <summary> /// Gets the message associated with <see cref="ReplExceptionCode"/> /// </summary> /// <param name="code">Whose message to set</param> /// <returns>Associated message if there is any otherwise null</returns> public static string GetMessage(this ReplExceptionCode code) { var members = ReplExceptionCodeType.GetMember(code.ToString()); if (members.Length == 0) { return(null); } var exceptionMessageAttribute = members[0].GetCustomAttribute <ExceptionMessageAttribute>(); return(exceptionMessageAttribute?.Message); }
public ReplRuntimeException(ReplExceptionCode code) : base($"REPL Exception: {code}") { Code = code; }