<commit_before>require 'parslet'
require 'openssl'

module DKIM
  module Query
    #
    # DKIM parser.
    #
    # @see https://tools.ietf.org/html/rfc6376#section-3
    #
    class Parser < Parslet::Parser

      root :record
      rule(:record) do
        (
          fws? >> key_tag >> fws? >>
          (str(';') >> fws? >> key_tag >> fws?).repeat(0) >> str(';').maybe
        ).as(:tag_list)
      end

      rule(:key_tag) do
        (
          key_v_tag |
          key_g_tag |
          key_h_tag |
          key_k_tag |
          key_n_tag |
          key_p_tag |
          key_s_tag |
          key_t_tag
        ).as(:tag)
      end

      def self.key_tag_rule(name,&block)
        rule(:"key_#{name}_tag") do
          str(name).as(:name) >>
          fws? >> str('=') >> fws? >>
          instance_eval(&block).as(:value)
        end
      end

      def symbol(name)
        str(name).as(:symbol)
      end

      key_tag_rule('v') { symbol('DKIM1') }<commit_msg>make key_tag_rule and symbol private.<commit_after>require 'parslet'
require 'openssl'

module DKIM
  module Query
    #
    # DKIM parser.
    #
    # @see https://tools.ietf.org/html/rfc6376#section-3
    #
    class Parser < Parslet::Parser

      root :record
      rule(:record) do
        (
          fws? >> key_tag >> fws? >>
          (str(';') >> fws? >> key_tag >> fws?).repeat(0) >> str(';').maybe
        ).as(:tag_list)
      end

      rule(:key_tag) do
        (
          key_v_tag |
          key_g_tag |
          key_h_tag |
          key_k_tag |
          key_n_tag |
          key_p_tag |
          key_s_tag |
          key_t_tag
        ).as(:tag)
      end

      private

      def self.key_tag_rule(name,&block)
        rule(:"key_#{name}_tag") do
          str(name).as(:name) >>
          fws? >> str('=') >> fws? >>
          instance_eval(&block).as(:value)
        end
      end

      def symbol(name)
        str(name).as(:symbol)
      end

      public

      key_tag_rule('v') { symbol('DKIM1') }
{'fraction_non_alphanumeric': 0.14456035767511177, 'fraction_numerical': 0.006954793840039742, 'mean_word_length': 1.582051282051282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 2, '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': '4193282', 'n_tokens_mistral': 725, 'n_tokens_neox': 704, 'n_words': 122}