public WhenThenClause SplitToWhenThenClause(string text) { if (text.StartsWith("when", StringComparison.InvariantCultureIgnoreCase) == false) throw new InvalidOperationException("statement should start with a when"); int thenIndex = text.IndexOf("then", StringComparison.InvariantCultureIgnoreCase); if (thenIndex == -1) throw new InvalidOperationException("statement should have a then"); WhenThenClause clause = new WhenThenClause(); string whenClause = text.Substring(4, thenIndex - 4).Trim(); ParseClause(whenClause, delegate(string[] parts) { ActionExpression item = new ActionExpression(); item.Left = parts[0]; item.Operator = parts[1]; item.Right = parts[2]; clause.When.Add(item); }); string thenClause = text.Substring(thenIndex + 4); ParseClause(thenClause, delegate(string[] parts) { ActionExpression item = new ActionExpression(); item.Left = parts[0]; item.Right= parts[1]; item.Operator = parts[2]; clause.Then.Add(item); }); return clause; }
public WhenThenClause SplitToWhenThenClause(string text) { if (text.StartsWith("when", StringComparison.InvariantCultureIgnoreCase) == false) { throw new InvalidOperationException("statement should start with a when"); } int thenIndex = text.IndexOf("then", StringComparison.InvariantCultureIgnoreCase); if (thenIndex == -1) { throw new InvalidOperationException("statement should have a then"); } WhenThenClause clause = new WhenThenClause(); string whenClause = text.Substring(4, thenIndex - 4).Trim(); ParseClause(whenClause, delegate(string[] parts) { ActionExpression item = new ActionExpression(); item.Left = parts[0]; item.Operator = parts[1]; item.Right = parts[2]; clause.When.Add(item); }); string thenClause = text.Substring(thenIndex + 4); ParseClause(thenClause, delegate(string[] parts) { ActionExpression item = new ActionExpression(); item.Left = parts[0]; item.Right = parts[1]; item.Operator = parts[2]; clause.Then.Add(item); }); return(clause); }
public ExternalDSLDemo(string text) { parsed = new Parser().Parse(text); }