 
 toHtml = (highlighted) ->
   crawl highlighted, (word, symbol, parent) ->
-    (word.ws or '') + colorize(theme[labelOf word], symbol)
-
-labelOf = (word) ->
-  word.malformed and 'malformed' or word.label or 'normal'
+    (word.ws or '') + colorize(theme[labelOf word, parent], symbol)
+
+labelOf = (word, parent) ->
+  word.malformed and 'malformed' or
+    parent.malformed and word.symbol in allDelims and 'malformed' or
+      word.label or 'normal'
 
 collapse = (nodes) ->
   collapsed = ""


    # TODO: defer for class declaration if not defined
    ## if not ctx.isClassDefined className    ...

    instance = (new Constrained freshConstraints,
      (new ClassConstraint instanceType.className, freshInstanceType.type))
    ## if overlaps ctx, instance
    ##   malformed 'instance overlaps with another', instance
    ## else
    ctx.addInstance instanceName, instance

    # """var #{instanceName} = new #{className}(#{listOf methods});"""
    (jsVarDeclaration (validIdentifier instanceName),
      (irDefinition (new Constrained freshConstraints, (tupleOfTypes methodTypes).type),
        (jsNew className, (join superClassInstances, methods))))

# Makes sure methods are typed explicitly and returns the instance constraint
# with renamed type variables to avoid clashes
assignMethodTypes = (ctx, instanceName, classDeclaration, instanceType, instanceConstraints) ->
  # First we must freshen the instance type, to avoid name clashes of type vars
  freshInstanceType = freshInstance ctx,
    (quantifyUnbound ctx,

    instanceName = ctx.definitionName()

    ctx.newScope()
    freshInstanceType = assignMethodTypes ctx, instanceConstraint, instanceName,
      classDefinition, instanceType, constraints
    definitions = pairs wheres
    methodsDeclarations = definitionList ctx,
      (prefixWithInstanceName definitions, instanceName)
