Example #1
0
        public static PropertyBag FromFile(string filename)
        {
            var lines = File.ReadAllLines(filename);
            //pre-proccess the text in file


            IEnumerable <string> includeText   = PropertyBagParser.ParseInclude(Path.GetDirectoryName(filename), lines);
            IEnumerable <string> noBlankText   = PropertyBagParser.StripEmptyLines(includeText);
            IEnumerable <string> noCommentText = PropertyBagParser.StripComment(noBlankText);

            ShowLines(noCommentText);
            IndentationTree tree = IndentationTree.Parse(noCommentText);

            PropertyBagParser.Parse(tree);

            return(new PropertyBag());
        }
Example #2
0
        public static IndentationTree Parse(IEnumerable <string> lines)
        {
            Stack <IndentationTree> stack = new Stack <IndentationTree>();
            IndentationTree         root  = new IndentationTree(-1, string.Empty);

            stack.Push(root);
            foreach (string line in lines)
            {
                Match match = sIndentRegex.Match(line);
                if (match.Success)
                {
                    int    cuurentIndent = Convert.ToInt32(match.Groups["indent"].Value);
                    string currentText   = match.Groups["text"].Value;

                    IndentationTree node = new IndentationTree(cuurentIndent, currentText);
                    //it is the sub-level
                    if (cuurentIndent > stack.Peek().Indent)
                    {
                        stack.Peek().mChildren.Add(node);
                        stack.Push(node);
                    }
                    else if (cuurentIndent <= stack.Peek().Indent)
                    {
                        while (cuurentIndent < stack.Peek().Indent)
                        {
                            stack.Pop();
                        }
                        stack.Peek().mChildren.Add(node);
                        stack.Push(node);
                    }
                }
                else
                {
                    throw new Exception("cannot match indent line");
                }
            }
            root.NormalizeIndentation(-1);
            return(root);
        }
Example #3
0
 public static PropertyBag Parse(IndentationTree tree)
 {
 }