<commit_before>$:.unshift File.dirname(__FILE__) + "/../lib"

require 'parslet'
require 'parslet/convenience'

def prettify(str)
  puts " "*3 + " "*4 + "." + " "*4 + "10" + " "*3 + "." + " "*4 + "20"
  str.lines.each_with_index do |line, index|
    printf "%02d %s\n", 
      index+1, 
      line.chomp
  end
end

class Parser < Parslet::Parser

  # commons

  rule(:space) { match('[ \t]').repeat(1) }
  rule(:space?) { space.maybe }

  rule(:newline) { match('[\r\n]') }

  rule(:comment) { str('#') >> match('[^\r\n]').repeat }

  rule(:line_separator) {
    (space? >> ((comment.maybe >> newline) | str(';')) >> space?).repeat(1)
  }

  rule(:blank) { line_separator | space }
  rule(:blank?) { blank.maybe }

  rule(:identifier) { match('[a-zA-Z0-9_]').repeat(1) }

  # res_statement

  rule(:reference) {
    ((str('@@') | str('@')) >> identifier).as(:reference)
  }

  rule(:res_action_or_link) {
    str('.').as(:dot) >> (identifier >> str('?').maybe ).as(:name) >> str('()')
  }

  rule(:res_actions) {
    (
      reference
    ).as(:resources) >>
    (
      res_action_or_link.as(:res_action)
    ).repeat(0).as(:res_actions)
  }<commit_msg>. small simplification<commit_after>$:.unshift File.dirname(__FILE__) + "/../lib"

require 'parslet'
require 'parslet/convenience'

def prettify(str)
  puts " "*3 + " "*4 + "." + " "*4 + "10" + " "*3 + "." + " "*4 + "20"
  str.lines.each_with_index do |line, index|
    printf "%02d %s\n", 
      index+1, 
      line.chomp
  end
end

class Parser < Parslet::Parser

  # commons

  rule(:space) { match('[ \t]').repeat(1) }
  rule(:space?) { space.maybe }

  rule(:newline) { match('[\r\n]') }

  rule(:comment) { str('#') >> match('[^\r\n]').repeat }

  rule(:line_separator) {
    (space? >> ((comment.maybe >> newline) | str(';')) >> space?).repeat(1)
  }

  rule(:blank) { line_separator | space }
  rule(:blank?) { blank.maybe }

  rule(:identifier) { match('[a-zA-Z0-9_]').repeat(1) }

  # res_statement

  rule(:reference) {
    (str('@').repeat(1,2) >> identifier).as(:reference)
  }

  rule(:res_action_or_link) {
    str('.').as(:dot) >> (identifier >> str('?').maybe ).as(:name) >> str('()')
  }

  rule(:res_actions) {
    (
      reference
    ).as(:resources) >>
    (
      res_action_or_link.as(:res_action)
    ).repeat(0).as(:res_actions)
  }
{'fraction_non_alphanumeric': 0.2421098140942499, 'fraction_numerical': 0.016428880242109815, 'mean_word_length': 3.1996370235934664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '2849255', 'n_tokens_mistral': 924, 'n_tokens_neox': 880, 'n_words': 143}