Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Luthor Testing

luthor_testing.livemd

Luthor Testing

Mix.install([
  {:lex_luthor, "~> 0.1.3"}
])

Simple String

defmodule StringLexer do
  use LexLuthor

  defrule(~r/^'/, fn _ -> :STRING end)
  defrule(~r/^[^']+/, :STRING, fn e -> {:string, e} end)
  defrule(~r/^'/, :STRING, fn _ -> nil end)
end
StringLexer.lex("'hello''world'")

Simple Expression

defmodule ElixirLexer do
  use LexLuthor

  defrule(~r/^\(/, fn _ -> :PAREN end)
  defrule(~r/^[^\)]+/, :PAREN, fn e -> {:paren, e} end)
  defrule(~r/^\)/, :PAREN, fn _ -> nil end)
end
ElixirLexer.lex("(aaa)")