public static bool TryParse(string content, int start, int length, out KirinNode result) { result = null; if (!content.StartsWith(PreKeyword) || !content.EndsWith(PostKeyword)) { return(false); } result = new KirinSwitchCase(start, length) { RawCase = content.Substring(PreKeyword.Length, content.Length - PreKeyword.Length - PostKeyword.Length) }; return(true); }
public override object Execute(FiMClass reportClass) { if (!this.Complete) { throw new FiMException("Executing an incomplete switch statement"); } var variable = reportClass.GetVariable(this.RawVariable); if (variable == null) { throw new FiMException("Varible " + this.RawVariable + " does not exist"); } if (FiMHelper.IsTypeArray(variable)) { throw new FiMException("Cannot use array on a switch"); } Dictionary <object, string> CasesLookup = new Dictionary <object, string>(); foreach (var key in Cases.Keys) { if (!KirinSwitchCase.IsValidPlace(key, reportClass, out object value)) { throw new FiMException("Invalid case " + key); } if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, value))) { throw new FiMException("Duplicate case value " + key); } CasesLookup.Add(value, key); } KirinStatement s = DefaultCase; if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, variable.Value))) { s = Cases[CasesLookup.First(l => KirinValue.IsEqual(l.Key, variable.Value)).Value]; } if (s != null) { return(s.Execute(reportClass)); } return(null); }