Exemplo n.º 1
0
        public static ParsedExpressionList Parse(string expressions)
        {
            Regex regex = new Regex(@"\n?(?<indent>[ \t]*)(?<expression>\S+)(\s+(?<name>[^ \t=]+)\s*=\s*'(?<value>[^']+)')*");
            ParsedExpressionList currentList = new ParsedExpressionList();
            ParsedExpressionList rootList = currentList;
            int lastIndentLevel = -1;
            Stack expressionListStack = new Stack();

            foreach (Match match in regex.Matches(expressions))
            {
                string expression = null;
                Hashtable arguments = null;
                int currentIndentLevel = match.Groups["indent"].Length;

                {
                    Group names = match.Groups["name"];
                    Group values = match.Groups["value"];

                    expression = match.Groups["expression"].ToString();
                    arguments = new Hashtable(names.Captures.Count);

                    for (int counter = 0;counter < names.Captures.Count;++counter)
                    {
                        arguments[names.Captures[counter].ToString()] = values.Captures[counter].ToString();
                    }
                }

                if (lastIndentLevel == -1)
                {
                    lastIndentLevel = currentIndentLevel;
                }

                if (currentIndentLevel > lastIndentLevel)
                {
                    ParsedExpressionList lastList = currentList;

                    // Push the current guy on the stack, set up a new one

                    expressionListStack.Push(currentList);
                    currentList = new ParsedExpressionList();
                    lastList += currentList;
                }
                else if (currentIndentLevel < lastIndentLevel)
                {
                    // Pop lists until we get to this level
                    while (currentIndentLevel < currentList.IndentLevel)
                    {
                        currentList = (ParsedExpressionList) expressionListStack.Pop();
                    }
                }

                currentList += new ParsedExpression(expression, arguments, currentIndentLevel);
                lastIndentLevel = currentIndentLevel;
            }

            return rootList;
        }
Exemplo n.º 2
0
 public void AddExpression(ParsedExpression parsedExpression)
 {
     this.expressionList.Add(parsedExpression);
 }
Exemplo n.º 3
0
Arquivo: SDF.cs Projeto: bcr/sdf
 private static void MaybeCallPostCreateExpression(SDFState state, ParsedExpression expression, ParsedExpressionList children)
 {
     MethodInfo postCreateMethod = expression.Expression.GetType().GetMethod("PostCreateExpression");
     if (postCreateMethod != null)
     {
         postCreateMethod.Invoke(expression.Expression, new Object[] { state, expression.ExpressionName, expression.Arguments, children });
     }
 }