<commit_before>
require_relative 'token'
require_relative '../verifier/expression'

# TODO: Properly set the precedences.

# Unary operators which prefix things
PREFIX_UNARY_OPERATORS = {
  '!' => { :precedence => 10, :sym => :! }, # Logical not
  '-' => { :precedence => 10, :sym => :- }, # Negation
}

POSTFIX_UNARY_OPERATORS = {
  '!' => { :precedence => 10, :sym => :! }, # Factorial
}

BINARY_OPERATORS = {
  # Arithmetic
  '+' => { :precedence => 10, :sym => :+ }, # Addition
  '-' => { :precedence => 10, :sym => :- }, # Subtraction
  '*' => { :precedence => 10, :sym => :* }, # Multiplication
  '/' => { :precedence => 10, :sym => :/ }, # Division
  '^' => { :precedence => 10, :sym => :^ }, # Power

  # Comparisons
  '<'  => { :precedence => 10, :sym => :< }, # Less than
  '<=' => { :precedence => 10, :sym => :<= }, # Less than or equal to
  '>'  => { :precedence => 10, :sym => :> }, # Greater than
  '>=' => { :precedence => 10, :sym => :>= }, # Greater than or equal to
  '==' => { :precedence => 10, :sym => :== }, # Equals
  '!=' => { :precedence => 10, :sym => :!= }, # Not-equal-to

  # Logical
  '&&' => { :precedence => 10, :sym => :"&&" }, # And
  '||' => { :precedence => 10, :sym => :"||" }, # Or
}

def precedence_binop(op)
  if op.nil? || !op.is_symbol?
    return -1
  end

  info = BINARY_OPERATORS[op.value]

  if info
    info[:precedence]
  else
    -1<commit_msg>Filled in operator precedences table<commit_after>
require_relative 'token'
require_relative '../verifier/expression'

# TODO: Properly set the precedences.

# Unary operators which prefix things
PREFIX_UNARY_OPERATORS = {
  '!' => { :precedence => 100, :sym => :! }, # Logical not
  '-' => { :precedence => 100, :sym => :- }, # Negation
  '+' => { :precedence => 100, :sym => :+ }, # No-operation
}

POSTFIX_UNARY_OPERATORS = {
  '!' => { :precedence => 10, :sym => :! }, # Factorial
}

BINARY_OPERATORS = {
  # Arithmetic
  '+' => { :precedence => 70, :sym => :+ }, # Addition
  '-' => { :precedence => 70, :sym => :- }, # Subtraction
  '*' => { :precedence => 80, :sym => :* }, # Multiplication
  '/' => { :precedence => 80, :sym => :/ }, # Division
  '^' => { :precedence => 10, :sym => :^ }, # Power

  '++' => { :precedence => 100, :sym => :"++" }, # Increment in place
  '--' => { :precedence => 100, :sym => :"--" }, # Decrement in place
  '+=' => { :precedence => 20,  :sym => :"+=" }, # Add in place
  '-=' => { :precedence => 20,  :sym => :"-=" }, # Subtract in place
  '*=' => { :precedence => 20,  :sym => :"*=" }, # Multiply in place
  '/=' => { :precedence => 20,  :sym => :"/=" }, # Divide in place

  # Comparisons
  '<'  => { :precedence => 60, :sym => :< }, # Less than
  '<=' => { :precedence => 60, :sym => :<= }, # Less than or equal to
  '>'  => { :precedence => 60, :sym => :> }, # Greater than
  '>=' => { :precedence => 60, :sym => :>= }, # Greater than or equal to
  '==' => { :precedence => 50, :sym => :== }, # Equals
  '!=' => { :precedence => 50, :sym => :!= }, # Not-equal-to

  # Logical
  '&&' => { :precedence => 40, :sym => :"&&" }, # And
  '||' => { :precedence => 30, :sym => :"||" }, # Or
}

def precedence_binop(op)
  if op.nil? || !op.is_symbol?
    return -1
  end

  info = BINARY_OPERATORS[op.value]

  if info
    info[:precedence]
  else
    -1
{'fraction_non_alphanumeric': 0.25966514459665146, 'fraction_numerical': 0.026484018264840183, 'mean_word_length': 3.0319018404907974, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 128, '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': '4585028', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1222, 'n_words': 265}