Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- pair:
elixir: 1.16
otp: 26
- pair:
elixir: 1.18
otp: 27
lint: lint
steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 13 additions & 2 deletions lib/makeup/lexers/erlang_lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,17 @@ defmodule Makeup.Lexers.ErlangLexer do
# Combinators that highlight expressions surrounded by a pair of delimiters.
punctuation =
word_from_list(
[","] ++ ~w[\[ \] : _ @ \" . \#{ { } ( ) | ; => := << >> || -> \#],
[","] ++ ~w[\[ \] : _ @ \" . \#{ { } ( ) | ; => := << >> || -> \# &&],
:punctuation
)

tuple = many_surrounded_by(parsec(:root_element), "{", "}")

syntax_operators =
word_from_list(~W[+ - +? ++ = == -- * / < > /= =:= =/= =< >= ==? <- ! ? ?!], :operator)
word_from_list(
~W[+ - +? ++ = == -- * / < > /= =:= =/= =< >= ==? <- <:- <= <:= ! ? ?!],
:operator
)

record =
token(string("#"), :operator)
Expand Down Expand Up @@ -409,6 +412,14 @@ defmodule Makeup.Lexers.ErlangLexer do
[{:punctuation, %{language: :erlang}, "]"}]
]
],
binary: [
open: [
[{:punctuation, %{language: :erlang}, "<<"}]
],
close: [
[{:punctuation, %{language: :erlang}, ">>"}]
]
],
tuple: [
open: [
[{:punctuation, %{language: :erlang}, "{"}]
Expand Down
109 changes: 102 additions & 7 deletions test/makeup/erlang_lexer/erlang_lexer_tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,25 @@ defmodule ErlangLexerTokenizer do

describe "binary" do
test "<<>> syntax" do
assert lex(~s/<<>>/) == [{:punctuation, %{}, "<<"}, {:punctuation, %{}, ">>"}]
assert lex(~s/<<>>/) == [
{:punctuation, %{group_id: "group-1"}, "<<"},
{:punctuation, %{group_id: "group-1"}, ">>"}
]
end

test "<<\"\">> syntax" do
assert lex(~s/<<"">>/) == [
{:punctuation, %{}, "<<"},
{:punctuation, %{group_id: "group-1"}, "<<"},
{:string, %{}, ~s/""/},
{:punctuation, %{}, ">>"}
{:punctuation, %{group_id: "group-1"}, ">>"}
]
end

test "<<\"string\">> syntax" do
assert lex(~s/<<"string">>/) == [
{:punctuation, %{}, "<<"},
{:punctuation, %{group_id: "group-1"}, "<<"},
{:string, %{}, ~s/"string"/},
{:punctuation, %{}, ">>"}
{:punctuation, %{group_id: "group-1"}, ">>"}
]
end
end
Expand Down Expand Up @@ -228,6 +231,95 @@ defmodule ErlangLexerTokenizer do
end
end

describe "comprehensions" do
test "list" do
assert lex("[A||A<-B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<-"},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]

assert lex("[A||A<-B,true]") ==
[
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<-"},
{:name, %{}, "B"},
{:punctuation, %{}, ","},
{:string_symbol, %{}, "true"},
{:punctuation, %{group_id: "group-1"}, "]"}
]
end

test "binary" do
assert lex("[A||A<=B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<="},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]

assert lex("<<A||A<=B,true>>") == [
{:punctuation, %{group_id: "group-1"}, "<<"},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<="},
{:name, %{}, "B"},
{:punctuation, %{}, ","},
{:string_symbol, %{}, "true"},
{:punctuation, %{group_id: "group-1"}, ">>"}
]
end

test "strict" do
assert lex("[A||A<:-B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<:-"},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]

assert lex("[A||A<:=B]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<:="},
{:name, %{}, "B"},
{:punctuation, %{group_id: "group-1"}, "]"}
]
end

test "parallel" do
assert lex("[A||A<-B&&C<-D]") == [
{:punctuation, %{group_id: "group-1"}, "["},
{:name, %{}, "A"},
{:punctuation, %{}, "||"},
{:name, %{}, "A"},
{:operator, %{}, "<-"},
{:name, %{}, "B"},
{:punctuation, %{}, "&&"},
{:name, %{}, "C"},
{:operator, %{}, "<-"},
{:name, %{}, "D"},
{:punctuation, %{group_id: "group-1"}, "]"}
]
end
end

describe "atoms" do
test "are tokenized as such" do
assert lex("atom") == [{:string_symbol, %{}, "atom"}]
Expand Down Expand Up @@ -309,6 +401,9 @@ defmodule ErlangLexerTokenizer do
assert lex("=") == [{:operator, %{}, "="}]
assert lex("!") == [{:operator, %{}, "!"}]
assert lex("<-") == [{:operator, %{}, "<-"}]
assert lex("<:-") == [{:operator, %{}, "<:-"}]
assert lex("<=") == [{:operator, %{}, "<="}]
assert lex("<:=") == [{:operator, %{}, "<:="}]
end

test "word operators are tokenized as operator" do
Expand Down Expand Up @@ -558,8 +653,8 @@ defmodule ErlangLexerTokenizer do
{:generic_prompt, %{selectable: false}, "1> "},
{:name_function, %{}, "list_to_binary"},
{:punctuation, %{group_id: "group-1"}, "("},
{:punctuation, %{}, "<<"},
{:punctuation, %{}, ">>"},
{:punctuation, %{group_id: "group-2"}, "<<"},
{:punctuation, %{group_id: "group-2"}, ">>"},
{:punctuation, %{group_id: "group-1"}, ")"},
{:punctuation, %{}, "."},
{:whitespace, %{}, "\n"},
Expand Down