/// <summary> /// Will find all the (outer most ${} expressions in the code, and return their positions). /// Smart enough to figure out $${} escaping, but not much more /// </summary> private static IList <ExpressionPosition> GetExpressionsPositions(string code) { var bracesPositions = new List <ExpressionPosition>(); bool prevCharWasDollar = false; bool prevCharWasBang = false; for (int index = 0; index < code.Length; index++) { if (code[index] == '{') { bracesPositions.Add(new ExpressionPosition(index - 1, -1, prevCharWasDollar || prevCharWasBang, prevCharWasBang)); } if (code[index] == '}' && bracesPositions.Count > 0) { ExpressionPosition position = bracesPositions[bracesPositions.Count - 1]; if (ParentExpressionIsNotValid(bracesPositions, bracesPositions.Count)) { bracesPositions.RemoveAt(bracesPositions.Count - 1); } else if (position.End == -1) { position.End = index; } } //handles escaping expressions with $$ as well prevCharWasDollar = code[index] == '$' && !prevCharWasDollar; prevCharWasBang = code[index] == '!' && !prevCharWasBang; } bracesPositions.RemoveAll(obj => !obj.PrevCharWasDollarOrBang); return(bracesPositions); }
private static bool ParentExpressionIsNotValid(List <ExpressionPosition> bracesPositions, int index) { if (index - 2 < 0) { return(false); } ExpressionPosition parentExpression = bracesPositions[index - 2]; if (parentExpression.PrevCharWasDollarOrBang == false) { return(ParentExpressionIsNotValid(bracesPositions, index - 1)); } return(parentExpression.End == -1); }
public TextExpression(string text, ExpressionPosition position = ExpressionPosition.Above) { Text = text; Position = position; }
internal DynamicLevelExpression(string symbol, string name, ExpressionPosition position = ExpressionPosition.Below) { Symbol = symbol; Name = name; Position = position; }
internal ArticulationExpression(string name, ExpressionPosition position = ExpressionPosition.Below) { Name = name; Position = position; }