Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Slime.Parser with parser generated from PEG (using neotoma) #113

Merged
merged 11 commits into from
May 9, 2017
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
erl_crash.dump
*.ez
/bench/snapshots
/src/slime_parser.peg
/src/slime_parser.erl
15 changes: 0 additions & 15 deletions bench/performance_bottlenecks_bench.exs

This file was deleted.

2 changes: 0 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use Mix.Config

config :slime, :keep_lines, false

if Mix.env == :test do
config :slime, :attr_list_delims, %{"[" => "]", "(" => ")"}
config :slime, :embedded_engines, %{
Expand Down
11 changes: 10 additions & 1 deletion lib/slime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ defmodule Slime do
@moduledoc """
Syntax exception which may appear during parsing and compilation processes
"""
defexception message: "Syntax error in slime file"
defexception [:line, :line_number, :column, message: "Syntax error", source: "INPUT"]

def message(exception) do
"""
#{exception.message}
#{exception.source}, Line #{exception.line_number}, Column #{exception.column}
#{exception.line}
#{String.duplicate(" ", exception.column - 1)}^
"""
end
end

defdelegate render(slime), to: Renderer
Expand Down
16 changes: 10 additions & 6 deletions lib/slime/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ defmodule Slime.Compiler do
end
end
defp render_attribute(name, value) do
value = cond do
is_binary(value) -> value
is_list(value) -> Enum.join(value, " ")
true -> to_string(value)
end
if value == true do
" #{to_string(name)}"
else
value = cond do
is_binary(value) -> value
is_list(value) -> Enum.join(value, " ")
true -> to_string(value)
end

~s( #{to_string(name)}="#{value}")
~s( #{to_string(name)}="#{value}")
end
end

defp render_branch(%DoctypeNode{content: text}), do: text
Expand Down
Loading