<commit_before>
# Paints a graphviz graph of your parser.

begin
  require 'ruby-graphviz'
rescue LoadError
  puts "Please install the 'ruby-graphviz' gem first."
  fail
end

require 'set'
require 'parslet/atoms/visitor'

module Parslet
  class GraphvizVisitor
    def initialize g
      @graph = g
      @known_links = Set.new
    end

    attr_reader :parent

    def visit_parser(root)
      recurse root, node('parser')
    end
    def visit_entity(name, block)
      s = node(name)

      downwards s
      recurse block.call, s
    end
    def visit_named(name, atom)<commit_msg>Avoid looping during graph construction<commit_after>
# Paints a graphviz graph of your parser.

begin
  require 'ruby-graphviz'
rescue LoadError
  puts "Please install the 'ruby-graphviz' gem first."
  fail
end

require 'set'
require 'parslet/atoms/visitor'

module Parslet
  class GraphvizVisitor
    def initialize g
      @graph = g
      @known_links = Set.new
      @visited = Set.new
    end

    attr_reader :parent

    def visit_parser(root)
      recurse root, node('parser')
    end
    def visit_entity(name, block)
      s = node(name)

      downwards s

      return if @visited.include?(name)
      @visited << name

      recurse block.call, s
    end
    def visit_named(name, atom)
{'fraction_non_alphanumeric': 0.07698289269051321, 'fraction_numerical': 0.0, 'mean_word_length': 2.763157894736842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6402235', 'n_tokens_mistral': 429, 'n_tokens_neox': 422, 'n_words': 130}