Esempio n. 1
0
        public static SourceCode Parse(string code)
        {
            var source = new SourceCode();

            code = code.Replace("\r", "");
            code = code.Replace("    ", "\t");
            var prevTabCount = 0;

            foreach (var line in code.Split('\n'))
            {
                var tabCount = line.CountTab();
                if (prevTabCount > tabCount)
                {
                    for (var i = 0; i < prevTabCount - tabCount; ++i)
                    {
                        source.IndentLeft();
                    }
                }
                else if (prevTabCount < tabCount)
                {
                    for (var i = 0; i < tabCount - prevTabCount; ++i)
                    {
                        source.IndentRight();
                    }
                }
                prevTabCount = tabCount;
                var trimmed = line.Trim();
                if (trimmed.StartsWith("<%") && trimmed.EndsWith("%>"))
                {
                    source.AddMarker(trimmed.Strip("<%", "%>"));
                }
                else
                {
                    source.Append(trimmed);
                }
            }
            return(source);
        }
Esempio n. 2
0
 public SourceCode Append(SourceCode other)
 {
     other._main.Codes.ForEach(c => Append(c));
     other._main.Parent = _currentBlock;
     return(this);
 }