<commit_before># Evaluate expressions using a PrattParser.

require_relative "pratt_parser"

class PrattEvaluator
  def self.eval(expression)
    PrattEvaluator.new(expression).eval
  end

  def initialize(expression)
    @expression = expression
  end

  def eval
    PrattParser.new(@expression.each_char.lazy.map{|c|@@tokens[c]}).eval
  end

  class EqualsToken
    def lbp
      8
    end

    def led(evaluator, left)
      left == evaluator.expression(lbp)
    end
  end

  class AddToken
    def lbp
      10
    end

    def led(evaluator, left)
      left + evaluator.expression(lbp)
    end
  end

  class SubToken < AddToken
    def led(evaluator, left)
      left - evaluator.expression(lbp)
    end
  end

  class MulToken
    def lbp
      20
    end

    def led(evaluator, left)
      left * evaluator.expression(lbp)
    end
  end

  class DivToken < MulToken
    def led(evaluator, left)
      left / evaluator.expression(lbp)
    end
  end

  class DigitToken
    def initialize(value)
      @value = value
    end

    def lbp
      100
    end

    def nud(evaluator)
      @value
    end

    def led(evaluator, left)<commit_msg>Use "parser" instead of "evaluator".<commit_after># Evaluate expressions using a PrattParser.

require_relative "pratt_parser"

class PrattEvaluator
  def self.eval(expression)
    PrattEvaluator.new(expression).eval
  end

  def initialize(expression)
    @expression = expression
  end

  def eval
    PrattParser.new(@expression.each_char.lazy.map{|c|@@tokens[c]}).eval
  end

  class EqualsToken
    def lbp
      8
    end

    def led(parser, left)
      left == parser.expression(lbp)
    end
  end

  class AddToken
    def lbp
      10
    end

    def led(parser, left)
      left + parser.expression(lbp)
    end
  end

  class SubToken < AddToken
    def led(parser, left)
      left - parser.expression(lbp)
    end
  end

  class MulToken
    def lbp
      20
    end

    def led(parser, left)
      left * parser.expression(lbp)
    end
  end

  class DivToken < MulToken
    def led(parser, left)
      left / parser.expression(lbp)
    end
  end

  class DigitToken
    def initialize(value)
      @value = value
    end

    def lbp
      100
    end

    def nud(parser)
      @value
    end

    def led(parser, left)
{'fraction_non_alphanumeric': 0.07383136740934906, 'fraction_numerical': 0.0069899519440803845, 'mean_word_length': 2.2997118155619596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2084890', 'n_tokens_mistral': 790, 'n_tokens_neox': 756, 'n_words': 203}