<commit_before>defmodule Dicer.Parser2 do
  def parse(input) when is_binary(input) do
    input
    |> Dicer.Lexer.tokenize
    |> _parse
    |> IO.inspect
  end

  defp _parse(input, acc \\ 0.0)
  defp _parse(input, acc) when is_list(input) do
    << a :: 32, b :: 32, c :: 32 >> = :crypto.rand_bytes(12)
    :random.seed(a,b,c)
    _expression(input, acc)
  end

### Expressions
  defp _expression([%Dicer.Tokens.End{} | _], acc) do
    {[], acc}
  end

  defp _expression([%Dicer.Tokens.Plus{} | tail], acc) do
      {remaining_input, factor1} = _factor(tail, acc)
      _expression(remaining_input, acc + factor1)
  end

  defp _expression([%Dicer.Tokens.Minus{} | tail], acc) do
      {remaining_input, factor1} = _factor(tail, acc)
      _expression(remaining_input, acc - factor1)
  end

  defp _expression(input, acc) do
      {remaining_input, factor1} = _factor(input, acc)
      _expression(remaining_input, factor1)
  end

### Factors
  defp _factor(input = [%Dicer.Tokens.End{} | _], acc) do
    {input, acc}
  end

  defp _factor([%Dicer.Tokens.Multiply{} | tail], acc) do
    {remaining_input, num} = _number_or_dice(tail)
    _factor(remaining_input, acc * num)
  end

  defp _factor([%Dicer.Tokens.Divide{} | tail], acc) do
     {remaining_input, num} = _number_or_dice(tail)
      _factor(remaining_input, acc / num)
  end

  defp _factor(input, acc) do
    case _number_or_dice(input) do
      {remaining_input, :not_a_num} ->
        {remaining_input, acc}
      {remaining_input, num} ->
        _factor(remaining_input, num)
      true ->
        raise "Unexpected input!"
    end
  end

### Numbers/Dice
  defp _number_or_dice([%Dicer.Tokens.LeftParenthesis{} | tail]) do
    {remaining_input, num} = _expression(tail, 0.0)
    case hd(remaining_input) do
      %Dicer.Tokens.RightParenthesis{} ->
        {tl(remaining_input), num}
      true ->
        raise "No Matching Parenthesis!"
    end
  end

  defp _number_or_dice(input = [%Dicer.Tokens.Dice{} | tail]) do
    {tail, _roll(hd(input))}
  end
<commit_msg>Changes<commit_after>defmodule Dicer.Parser2 do
  def parse(input) when is_binary(input) do
    input
    |> Dicer.Lexer.tokenize
    |> _parse
    |> IO.inspect
  end

  defp _parse(input, acc \\ 0.0)
  defp _parse(input, acc) when is_list(input) do
    << a :: 32, b :: 32, c :: 32 >> = :crypto.rand_bytes(12)
    :random.seed(a,b,c)
    _expression(input, acc)
  end

### Expressions
  defp _expression([%Dicer.Tokens.End{} | _], acc) do
    {[], acc}
  end

  defp _expression([%Dicer.Tokens.Plus{} | tail], acc) do
      {remaining_input, factor1} = _factor(tail, acc)
      _expression(remaining_input, acc + factor1)
  end

  defp _expression([%Dicer.Tokens.Minus{} | tail], acc) do
      {remaining_input, factor1} = _factor(tail, acc)
      _expression(remaining_input, acc - factor1)
  end

  defp _expression(input, acc) do
      {remaining_input, factor1} = _factor(input, acc)
      _expression(remaining_input, factor1)
  end

### Factors
  defp _factor(input = [%Dicer.Tokens.End{} | _], acc) do
    {input, acc}
  end

  defp _factor([%Dicer.Tokens.Multiply{} | tail], acc) do
    {remaining_input, num} = _number_or_dice(tail)
    _factor(remaining_input, acc * num)
  end

  defp _factor([%Dicer.Tokens.Divide{} | tail], acc) do
     {remaining_input, num} = _number_or_dice(tail)
      _factor(remaining_input, acc / num)
  end

  defp _factor(input, acc) do
    case _number_or_dice(input) do
      {remaining_input, :not_a_num} ->
        {remaining_input, acc}
      {remaining_input, num} ->
        _factor(remaining_input, num)
      true ->
        raise "Unexpected input!"
    end
  end

### Numbers/Dice
  # defp _number_or_dice([%Dicer.Tokens.LeftParenthesis{} | tail]) do
  #   {remaining_input, num} = _expression(tail, 0.0)
  # end

  # defp _number_or_dice([%Dicer.Tokens.RightParenthesis{} | tail]) do
    
  # end

  defp _number_or_dice(input = [%Dicer.Tokens.Dice{} | tail]) do
    {tail, _roll(hd(input))}
  end

{'fraction_non_alphanumeric': 0.1373777889195287, 'fraction_numerical': 0.00952619704186513, 'mean_word_length': 3.24468085106383, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '5680918', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1493, 'n_words': 317}