<commit_before>{Node} = require './node'

class EmptyElement extends Node
  constructor: (options) ->
    super options
    @type = 'empty element'
    @name = options.name

  @parse: (s) ->
    { level, node } = Node.parseBasic s
    if node.match(/^<\/\S+$/)
      new EmptyElement level: level, name: node.substring 2

  append: (prev) ->
    if @level > prev.level
      prev.appendChild @
    else if @level is prev.level
      prev.parent.appendChild @
    else if @level < prev.level
      p = prev
      p = p.parent until p.level is @level
      p.parent.appendChild @
    @

  write: ->
    attributes = (" #{k}=\"#{v}\"" for k, v of @attributes).join ''
    '<' + @name + attributes + ' />'

module.exports.EmptyElement = EmptyElement<commit_msg>refactor EmptyElement<commit_after>{Node} = require './node'

class EmptyElement extends Node
  constructor: ({ level, @name }) ->
    super { level }

  @parse: (s) ->
    { level, node } = Node.parseBasic s
    m = node.match /^<\/(\S+)$/
    if m?
      new EmptyElement { level, name: m[1] }

  append: (prev) ->
    if @level > prev.level
      prev.appendChild @
    else if @level is prev.level
      prev.parent.appendChild @
    else if @level < prev.level
      p = prev
      p = p.parent until p.level is @level
      p.parent.appendChild @
    @

  write: ->
    attributes = (" #{k}=\"#{v}\"" for k, v of @attributes).join ''
    '<' + @name + attributes + ' />'

module.exports.EmptyElement = EmptyElement
{'fraction_non_alphanumeric': 0.15639810426540285, 'fraction_numerical': 0.0013540961408259986, 'mean_word_length': 2.389908256880734, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '482499', 'n_tokens_mistral': 483, 'n_tokens_neox': 471, 'n_words': 133}