Skip to content

Commit

Permalink
Properly deal with unicode chars in $
Browse files Browse the repository at this point in the history
Closes #27.
  • Loading branch information
josevalim committed May 9, 2024
1 parent 567c536 commit baa18c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/makeup/lexers/erlang_lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ defmodule Makeup.Lexers.ErlangLexer do
character =
string("$")
|> choice([
escape,
string("\\") |> ascii_char([?\s, ?%]),
ascii_char(not: ?\\)
string("\\") |> utf8_char([]),
utf8_char(not: ?\\)
])
|> token(:string_char)

Expand Down Expand Up @@ -247,7 +246,7 @@ defmodule Makeup.Lexers.ErlangLexer do
|> concat(token("/", :punctuation))
|> concat(number_integer)

# Erlang prompt
# Erlang prompt
erl_prompt =
string("\n")
|> optional(string("(") |> concat(atom_name) |> string(")"))
Expand Down
6 changes: 6 additions & 0 deletions test/makeup/erlang_lexer/erlang_lexer_tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ defmodule ErlangLexerTokenizer do
assert lex("") == []
end

test "character" do
assert lex("$a") == [{:string_char, %{}, "$a"}]
assert lex("$\\ ") == [{:string_char, %{}, "$\\ "}]
assert lex("$🫂") == [{:string_char, %{}, "$🫂"}]
end

test "comment" do
assert lex("%abc") == [{:comment_single, %{}, "%abc"}]
assert lex("% abc") == [{:comment_single, %{}, "% abc"}]
Expand Down

0 comments on commit baa18c5

Please sign in to comment.