If anyone is interested I think I kind of got to where I wanted like this:
defmodule Textprocessor do
@regex_find_chords ~r/\b(?:[BE]b?|[ACDFG]#?)(?:sus|m|maj|min|[-1-9\/m])?(?:sus|m|maj|min|[-1-9\/m])?\b#?/
@empty_line ~r/^\s*$/
@instruction ~r/^\[[\w+ ]+\]\s*$/
@moduledoc """
Documentation for `Textprocessor`.
"""
@doc """
Process song
## Examples
# iex> Textprocessor.process_file("./lyrics.text")
# :ok
"""
def process_file(filename) do
File.stream!(filename)
|> Enum.map(&String.trim/1)
|> Enum.each(&process_line/1)
end
defp process_line(line) do
cond do
String.match?(line, @regex_find_chords) ->
IO.puts("CHORDS: #{line}")
String.match?(line, @instruction) ->
IO.puts("INSTRUCTION: #{line}")
String.match?(line, @empty_line) ->
IO.puts("EMPTY: #{line}")
true ->
IO.puts("LYRICS: #{line}")
:ok
end
end
end
Not sure this is optimal but I would be interested in any criticism


















