Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public TextExpression(string text, ExpressionPosition position = ExpressionPosition.Above)
 {
     Text     = text;
     Position = position;
 }
Пример #4
0
 internal DynamicLevelExpression(string symbol, string name, ExpressionPosition position = ExpressionPosition.Below)
 {
     Symbol   = symbol;
     Name     = name;
     Position = position;
 }
Пример #5
0
 internal ArticulationExpression(string name, ExpressionPosition position = ExpressionPosition.Below)
 {
     Name     = name;
     Position = position;
 }