anchor.diff:              |> directedGraph.AppendChild
   
           // Add the rules/states/transitions to the graph
  -        compiledSpec.CompiledRules
  -        |> Map.iter (fun ruleId compiledRule ->
  +        let categoryColors =
  +            Palette.random compiledSpec.CompiledRules.Count
  +        (0, compiledSpec.CompiledRules)
  +        ||> Map.fold (fun ruleIndex ruleId compiledRule ->
               // Add a category for this rule.
               let ruleCategory =
                   dgmlDoc.CreateElement ("Category", directedGraph.NamespaceURI)
  
positive.code:     // NOTE : The backslash must be double-escaped so it is handled
      // correctly in the generated DGML file.
      let private escapedChar = function
          | '\u0000' -> "\\0x00"
          | '\u0001' -> "SOH"
          | '\u0002' -> "STX"
          | '\u0003' -> "ETX"
          | '\u0004' -> "EOT"
          | '\u0005' -> "ENQ"
          | '\u0006' -> "ACK"
          | '\u0007' -> "\\a"
          | '\u0008' -> "\\b"
          | '\u0009' -> "\\t"
          | '\u000a' -> "\\n"
          | '\u000b' -> "VT"
          | '\u000c' -> "\\f"
          | '\u000d' -> "\\r"
          | '\u000e' -> "SO"
          | '\u000f' -> "SI"
          | '\u0010' -> ""
          | '\u0011' -> ""
          | '\u0012' -> ""
          | '\u0013' -> ""
          | '\u0014' -> ""
          | '\u0015' -> ""
          | '\u0016' -> ""
          | '\u0017' -> ""
          | '\u0018' -> ""
          | '\u0019' -> ""
          | '\u001a' -> ""
          | '\u001b' -> ""
          | '\u001c' -> ""
          | '\u001d' -> ""
          | '\u001e' -> ""
          | '\u001f' -> ""
          | c ->
              if int c < 0x20 || int c = 0x7f then
                  sprintf "\\0x%02x" (int c)
              else
                  c.ToString ()
  
  
  //    // Emits DGML where each DFA is a separate component of the graph.
  //    let emitCombined (compiledSpec : CompiledSpecification) (options : CompilationOptions) =
  //        //
  //        let dgmlDoc = XmlDocument ()
  //        let xmlDecl = dgmlDoc.CreateXmlDeclaration ("1.0", "utf-8", null)
  //        
  //        let directedGraphNode =
  //            dgmlDoc.CreateElement ("DirectedGraph", "http://schemas.microsoft.com/vs/2009/dgml")
  //            |> dgmlDoc.AppendChild
  //
  //        let nodes =
  //            dgmlDoc.CreateElement "Nodes"
  //            |> directedGraphNode.AppendChild
  //
  //        let links =
  //            dgmlDoc.CreateElement "Links"
  //            |> directedGraphNode.AppendChild
  //
  //        // Add the rules/states/transitions to the graph
  //        (0, compiledSpec.CompiledRules)
  //        ||> Map.fold (fun ruleStartDfaStateId ruleId compiledRule ->
  //            //
  //            let dfaStateCount = compiledRule.Dfa.Transitions.VertexCount
  //
  //            // Add the nodes for this rule's DFA.
  //            for dfaStateId = 0 to dfaStateCount - 1 do
  //                let dfaStateId = Int32WithMeasure dfaStateId
  //
  //                /// The Node element representing this DFA state.
  //                let vertexNode =
  //                    dgmlDoc.CreateElement "Node"
  //                    |> nodes.AppendChild
  //
  //                // Set the Id attribute value.
  //                // This isn't shown on the graph, it's only used as a unique identifier for the node.
  //                let idAttr = dgmlDoc.CreateAttribute "Id"
  //                vertexNode.Attributes.Append idAttr |> ignore
  //                idAttr.Value <- dfaStateUniqueNodeId ruleId dfaStateId
  //                
  //                // Set the Label attribute value.
  //                // This is the label shown for this node when the graph is rendered.
  //                let labelAttr = dgmlDoc.CreateAttribute "Label"
  //                vertexNode.Attributes.Append labelAttr |> ignore
  //                labelAttr.Value <- string dfaStateId
  //
  //                // Set the Category attribute value.
  //                // We use this to group the nodes from each DFA together.
  //                let categoryAttr = dgmlDoc.CreateAttribute "Category"
  //                vertexNode.Attributes.Append categoryAttr |> ignore
  //                categoryAttr.Value <- ruleId
  //
  //            // Add the transitions for this rule's DFA.
  //            compiledRule.Dfa.Transitions.AdjacencyMap
  //            |> Map.iter (fun edgeKey edgeSet ->
  //                
  //
  //
  //                ())
  //
  //            // 
  //            ruleStartDfaStateId + dfaStateCount)
  //        |> ignore
  //
  //        // TEMP : Normally we'll write this directly to a file, but for testing
  //        // purposes write the document to a StringBuilder.
  //        let sb = StringBuilder ()
  //        using (new StringWriter (sb)) dgmlDoc.Save        
  //        sb.ToString ()
  
      // Emits DGML where each DFA is a separate component of the graph.
      let emitSeparate (compiledSpec : CompiledSpecification) (options : CompilationOptions) =
  
negative.code:             dgmlDoc.CreateElement ("DirectedGraph", "http://schemas.microsoft.com/vs/2009/dgml")
              |> dgmlDoc.AppendChild
  
          do
              // Add property definitions
              let properties =
                  dgmlDoc.CreateElement ("Properties", directedGraph.NamespaceURI)
                  |> directedGraph.AppendChild
  
              // Accepted Rule Clause Index property
              let acceptedRuleClauseIndexProperty =
                  dgmlDoc.CreateElement ("Property", directedGraph.NamespaceURI)
                  |> properties.AppendChild
  
              let idAttr = dgmlDoc.CreateAttribute "Id"
              acceptedRuleClauseIndexProperty.Attributes.Append idAttr |> ignore
              idAttr.Value <- "AcceptedRuleClauseIndex"
  
              let labelAttr = dgmlDoc.CreateAttribute "Label"
              acceptedRuleClauseIndexProperty.Attributes.Append labelAttr |> ignore
              labelAttr.Value <- "Accepted Rule-Clause Index"
  
              let dataTypeAttr = dgmlDoc.CreateAttribute "DataType"
              acceptedRuleClauseIndexProperty.Attributes.Append dataTypeAttr |> ignore
              dataTypeAttr.Value <- "System.Int32"
  
  //        do
  //            // Add style definitions
  //            let styles =
  //                dgmlDoc.CreateElement ("Styles", directedGraph.NamespaceURI)
  //                |> directedGraph.AppendChild
  //
  //            // Final (accepting) state style
  //            let finalStateStyle =
  //                dgmlDoc.CreateElement ("Style", directedGraph.NamespaceURI)
  //                |> styles.AppendChild
  //
  //            let targetTypeAttr = dgmlDoc.CreateAttribute "Id"
  //            finalStateStyle.Attributes.Append targetTypeAttr |> ignore
  //            targetTypeAttr.Value <- "Node"
  //
  //            let groupLabelAttr = dgmlDoc.CreateAttribute "Final"
  //            finalStateStyle.Attributes.Append groupLabelAttr |> ignore
  //            groupLabelAttr.Value <- "Final (Accepting) State"
  //
  //            // TODO
  //            ()
  
          let nodes =
              dgmlDoc.CreateElement ("Nodes", directedGraph.NamespaceURI)
              |> directedGraph.AppendChild
  