public void Indent(SourceLocation startLocation, SourceLocation endLocation, AstNode parent) { string prefix = Lines[startLocation.Line].Substring(0, startLocation.Column); if (!string.IsNullOrWhiteSpace(prefix)) { startLocation.Line++; } // FIXME: some token's location is (0, 0), so we need this to avoid wrong indention if (startLocation.Line == 0) { return; } if (endLocation.Line < startLocation.Line) { return; } Indentation[startLocation.Line] = true; if (!Unindentation.ContainsKey(endLocation.Line + 1)) { Unindentation[endLocation.Line + 1] = GetFirstLine(parent).Line; } }
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); }