 
 class FSA extends Digraph
 
+
+  # How do you extend? from superclass?
+  class @Vertex
+    constructor: (@digraph, @value) ->
+      @arc_class = @digraph.constructor.Arc
+      @id = @digraph.next_vertex_id()
+      @_arcs = []
+
+    connect: (val, next_vertex) ->
+      arc = new @arc_class(@, @digraph.next_arc_id(), val, next_vertex)
+      @_arcs.push(arc)
+      arc
+
+    arcs: ->
+      @_arcs
+
+    find_arc: (val) ->
+      for arc in @_arcs
+        return arc if arc.value == val
+
+
+  class @Arc
+    constructor: (@vertex, @id, @value, @next_vertex) ->
+      @next_vertex ||= null
+
+    test: (value) ->
+      @value == value || @value == true
+
+    format_att: ->
+      "#{@vertex.id} #{@next_vertex.id} #{@formatValue(@value)}"
+
+    dotString: ->
+      edge = Graphviz.dotEdge(@vertex.id, @next_vertex.id)
+      attrs = Graphviz.dotAttrs({label: "#{@dot_label()}"})
+      output = "#{edge}#{attrs};\n"
+      if @next_vertex.value
+        node = Graphviz.dotNode(@next_vertex.id, {shape: "doublecircle"})
+        output += node
+
+      output
+
+    dot_label: ->
+      @formatValue(@value)
+
+    formatValue: (value) ->
+      if typeof(value) == "function"
+        "<lambda>"
+      else if value == true
+        return "<epsilon>"
+      else
+        value
+
   constructor: ->
-    super(State, Arc)
+    super()
     @final_states = {}
 
   finalize: (state, value) ->


class Digraph

  constructor: (@vertex_class, @arc_class) ->
    @vertex_id_counter = 0
    @arc_id_counter = 0
    @source = @create_vertex()

  create_vertex: (opts) ->
    opts ||= {}
    id = opts.id || @next_vertex_id()
    new @constructor.Vertex(@, opts.value)

  add_path: (array, options={}) ->
    digraph = @
