<commit_before>class Node
  constructor: ({ @level, @name, @type, @value }) ->
    @parent = null
    @attributes = {}
    @children = []

  @parse: (s) ->
    match = s.match /^(\s*)(.+)$/
    throw new Error() unless match?
    [_, space, node] = match
    level = space.length
    parsed = null
    [
      (s) ->
        if s.match(/^<\/\S+$/)
          [s.substring(2), 'empty element']
      (s) ->
        if s.match(/^<\S+$/)
          [s.substring(1), 'element']
      (s) ->
        m = s.match(/^@(\S+)\s+(.+)$/)
        if m
          [m[1], 'attribute', m[2]]
      (s) ->
        if s.match(/^>.+$/)
          [s.substring(1), 'text']
      (s) ->
        [s, 'text']
    ].some (f) -><commit_msg>extract functions<commit_after>parseEmptyElement = (s) ->
  if s.match(/^<\/\S+$/)
    [s.substring(2), 'empty element']

parseElement = (s) ->
  if s.match(/^<\S+$/)
    [s.substring(1), 'element']

parseAttribute = (s) ->
  m = s.match(/^@(\S+)\s+(.+)$/)
  if m
    [m[1], 'attribute', m[2]]

parseText = (s) ->
  if s.match(/^>.+$/)
    [s.substring(1), 'text']

class Node
  constructor: ({ @level, @name, @type, @value }) ->
    @parent = null
    @attributes = {}
    @children = []

  @parse: (s) ->
    match = s.match /^(\s*)(.+)$/
    throw new Error() unless match?
    [_, space, node] = match
    level = space.length
    parsed = null
    [
      parseEmptyElement
      parseElement
      parseAttribute
      parseText
      (s) ->
        [s, 'text']
    ].some (f) ->
{'fraction_non_alphanumeric': 0.23663101604278075, 'fraction_numerical': 0.0066844919786096255, 'mean_word_length': 1.867816091954023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5127741', 'n_tokens_mistral': 566, 'n_tokens_neox': 555, 'n_words': 123}