Beispiel #1
0
        public int[] BuildDepthTable(ParseTreeNode root)
        {
            int currentDepth = 0;
            int lineCount    = GetLastLine(root).Line + 1;

            int[] depthTable = new int[lineCount];

            // the line index start from 0
            for (int line = 0; line < lineCount; line++)
            {
                // restore depth
                if (Unindentation.ContainsKey(line))
                {
                    currentDepth = depthTable[Unindentation[line]];
                }

                // indent
                if (Indentation.ContainsKey(line))
                {
                    if (Indentation[line] == true)
                    {
                        currentDepth     = currentDepth + 1;
                        depthTable[line] = currentDepth;
                    }
                    else
                    {
                        depthTable[line] = 0;
                    }
                }
                else
                {
                    depthTable[line] = currentDepth;
                }
            }

            return(depthTable);
        }