 
 $ = require './symbols'
 
-# parse tree node builders
-parseTreeLeafNode = (type, value = null) -> {type, value}
-parseTreeBranchNode = (type, value = null, children = []) -> {type, value, children}
+# parse tree node factories
+ParseTreeLeafNode = (type, value = null) -> {type, value}
+ParseTreeBranchNode = (type, value = null, children = []) -> {type, value, children}
 
 module.exports = class Parser
   parse: (code, @opts = {}) ->
-    @parseTree = parseTreeBranchNode @opts.root or $.ROOT # concrete syntax tree (initialised with root node)
+    @parseTree = ParseTreeBranchNode @opts.root or $.ROOT # concrete syntax tree (initialised with root node)
     @activeStates = [@parseTree] # stack tracking current parse tree position (starting with root)
     @chunkLine = 0 # The start line for the current @chunk.
     @chunkColumn =  0 # The start column of the current @chunk.


    if attrName
      if doubleQuotedVal? # "value"
        @addLeafNodeToActiveBranch parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [
          parseTreeLeafNode($.CJSX_ATTR_KEY, "\"#{attrName}\"")
          parseTreeLeafNode($.CJSX_ATTR_VAL, "\"#{doubleQuotedVal}\"")
        ])
        return input.length
      else if singleQuotedVal? # 'value'
        @addLeafNodeToActiveBranch parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [
          parseTreeLeafNode($.CJSX_ATTR_KEY, "\"#{attrName}\"")
          parseTreeLeafNode($.CJSX_ATTR_VAL, "'#{singleQuotedVal}'")
        ])
        return input.length
      else if cjsxEscVal # {value}
        @pushActiveBranchNode parseTreeBranchNode $.CJSX_ATTR_PAIR
        @addLeafNodeToActiveBranch parseTreeLeafNode($.CJSX_ATTR_KEY, "\"#{attrName}\"")
        # on next iteration of parse loop, '{' will trigger CJSX_ESC state
        return input.indexOf('{') # consume up to start of cjsx escape
      else if bareVal # value
        @addLeafNodeToActiveBranch parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [
          parseTreeLeafNode($.CJSX_ATTR_KEY, "\"#{attrName}\"")
          parseTreeLeafNode($.CJSX_ATTR_VAL, bareVal)
        ])
        return input.length
      else # valueless attr
        @addLeafNodeToActiveBranch parseTreeBranchNode($.CJSX_ATTR_PAIR, null, [
          parseTreeLeafNode($.CJSX_ATTR_KEY, "\"#{attrName}\"")
          parseTreeLeafNode($.CJSX_ATTR_VAL, 'true')
        ])
        return input.length
    else if spreadAttr # {... x, y}
      @pushActiveBranchNode parseTreeBranchNode $.CJSX_ATTR_SPREAD
      # on next iteration of parse loop, '{' will trigger CJSX_ESC state and be
      # parsed as CJSX_ESC (which has similar properties), to be transformed later
      return input.indexOf('{')
    else if whitespace?
      @addLeafNodeToActiveBranch parseTreeLeafNode($.CJSX_WHITESPACE, whitespace)
      return input.length
    else
      throwSyntaxError \

    return 0 if regex.indexOf("\n") > -1 # no newlines in a normal regex
    # Avoid conflicts with floor division operator.
    return 0 if regex is '//'
    @addLeafNodeToActiveBranch ParseTreeLeafNode $.CS_REGEX, match
    match.length

  # Matches multiline extended regular expressions.
