<commit_before>require "parslet"

class Smashcut
  class FountainParser < Parslet::Parser
    rule(:line_break) { match("\n") }
    rule(:scene_heading) { match("[A-Z \-\. ]").repeat(1) >> line_break.maybe >> line_break.maybe }
    rule(:action) { match("[a-zA-Z\s\.]").repeat(1) >> line_break.maybe >> line_break.maybe }
    rule(:screenplay_element) { scene_heading | action }
    rule(:screenplay) { (screenplay_element >> line_break.maybe >> line_break.maybe).repeat(1) }
    root(:screenplay)

    def parse(text)
      begin
        super(text)
      rescue Parslet::ParseFailed => error
        puts error.cause.ascii_tree
        raise error
      end
    end
  end
end

<commit_msg>more robust action rule<commit_after>require "parslet"

class Smashcut
  class FountainParser < Parslet::Parser
    rule(:line_break) { match("\n") }
    rule(:scene_heading) { match("[A-Z \-\. ]").repeat(1) >> line_break.maybe >> line_break.maybe }
    rule(:action) { match("[a-zA-Z\s\.\(\)\,0-9]").repeat(1) >> line_break.maybe >> line_break.maybe }
    rule(:dialogue) { match("[A-Z\s]").repeat(1) >> line_break >> match("[A-Za-z\s\.\?]").repeat(1) >> line_break.maybe >> line_break.maybe }
    rule(:screenplay_element) { scene_heading | action | dialogue }
    rule(:screenplay) { (screenplay_element >> line_break.maybe >> line_break.maybe).repeat(1) }
    root(:screenplay)

    def parse(text)
      begin
        super(text)
      rescue Parslet::ParseFailed => error
        puts error.cause.ascii_tree
        raise error
      end
    end
  end
end


{'fraction_non_alphanumeric': 0.16473616473616473, 'fraction_numerical': 0.006435006435006435, 'mean_word_length': 3.248633879781421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '5660877', 'n_tokens_mistral': 526, 'n_tokens_neox': 523, 'n_words': 92}