aboutsummaryrefslogtreecommitdiff
path: root/lib/main.ex
blob: ad657ca2b0c601620696454d3d8fa27864c7bea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
defmodule ElixirMathParser.Main do
  def process_parse({:error, result}) do
    IO.puts("\nParse error")
    IO.inspect(result)
  end

  def process_parse({:ok, tree}) do
    IO.puts("\nParse tree")
    IO.inspect(tree, pretty: true)
    case ElixirMathParser.process_tree(tree) do
      {:ok, _} -> :ok 
      {:error, reason} -> reason
    end
  end

  def main(args) do
    filename = Enum.fetch!(args, 0)

    IO.puts("Parsing #{filename}")
    text = File.read!(filename)

    {:ok, tokens, line} = :elixir_math_parser_lexer.string(String.to_charlist(text))
    IO.puts("Parsed #{filename}, stopped at line #{line}")

    res = process_parse(:elixir_math_parser.parse(tokens))
    if res != :ok do
      IO.puts(res)
    end
  end
end