Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: asummers/erlex
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.2.5
Choose a base ref
...
head repository: asummers/erlex
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 16 files changed
  • 2 contributors

Commits on Mar 9, 2020

  1. Copy the full SHA
    cb84676 View commit details
  2. Copy the full SHA
    23d4f51 View commit details

Commits on Oct 18, 2020

  1. Copy the full SHA
    df10b29 View commit details
  2. Copy the full SHA
    b125215 View commit details
  3. Copy the full SHA
    32a85d6 View commit details
  4. chore: Mix check (#50)

    asummers authored Oct 18, 2020
    Copy the full SHA
    3490a2c View commit details

Commits on Oct 19, 2020

  1. Copy the full SHA
    e320a90 View commit details

Commits on Jan 19, 2021

  1. doc: Misc. doc, README changes (#52)

    List of changes:
    - Update correct SPDX license id
    - Set changelog before readme in html doc
    - Set source reference by tagged version
    - Sort deps and format usage
    - Badges and more badges!
    - Add changelog link to hex info page
    - Update contributing instruction
    kianmeng authored Jan 19, 2021
    Copy the full SHA
    2f79a41 View commit details

Commits on May 27, 2021

  1. Copy the full SHA
    0548765 View commit details
Showing with 194 additions and 129 deletions.
  1. +11 −0 .check.exs
  2. +39 −0 .github/workflows/pulls.yml
  3. +33 −0 .github/workflows/release.yml
  4. +3 −1 .gitignore
  5. +0 −22 .travis.yml
  6. +4 −0 CHANGELOG.md
  7. +1 −4 CONTRIBUTING.md
  8. +4 −0 README.md
  9. +39 −54 lib/erlex.ex
  10. +28 −23 mix.exs
  11. +10 −19 mix.lock
  12. 0 .circleci/config.yml → priv/plts/.gitkeep
  13. +0 −2 src/lexer.xrl
  14. +3 −4 src/parser.yrl
  15. +8 −0 test/literals_pretty_print_test.exs
  16. +11 −0 test/pretty_print_test.exs
11 changes: 11 additions & 0 deletions .check.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
parallel: true,
skipped: true,

tools: [
{:unused_deps, command: "mix deps.unlock --check-unused"},
{:credo, "mix credo --strict --format oneline"},
{:compiler, "mix compile --warnings-as-errors"},
{:sobelow, false}
]
]
39 changes: 39 additions & 0 deletions .github/workflows/pulls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Elixir CI

on: [push, pull_request]

jobs:
ci:
name: ci
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.10.3, 1.11.0]
otp: [22.3, 23.1]
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles('**/mix.lock') }}
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix
- name: Restore Dialyzer PLT cache
uses: actions/cache@v2
with:
path: priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-${{ hashFiles('**/priv/plts/dialyzer.plt.hash') }}
restore-keys: |
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-${{ hashFiles('**/priv/plts/dialyzer.plt.hash') }}
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt
- name: Install dependencies
run: mix deps.get
- name: mix check
run: mix check
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
name: Release
strategy:
matrix:
otp: [23]
elixir: [1.11.0]
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-release-deps-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-release-deps-${{ hashFiles('**/mix.lock') }}
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-release-deps
- run: mix deps.get
- run: mix hex.publish --yes
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -8,4 +8,6 @@ erl_crash.dump
erlex-*.tar
.elixir_ls
src/parser.erl
src/lexer.erl
src/lexer.erl

/priv/plts/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

## [Unreleased]

## 0.2.6 - 2020-03-09
### Added
- Replace << parsing to fix nexted pattern matching binary bugs discovered from Phoenix 1.4.15.

## 0.2.5 - 2019-09-19
### Added
- Handle Erlang variables better with casing in guards.
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -25,10 +25,7 @@ Before submitting a pull request, make sure all of the following pass:

```
mix deps.get
mix format --check-formatted
mix compile --force --warnings-as-errors
mix credo list --strict
mix test
mix check
```

Steps:
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[![Hex version badge](https://img.shields.io/hexpm/v/erlex.svg)](https://hex.pm/packages/erlex)
[![Hex docs badge](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/erlex/)
[![Total download badge](https://img.shields.io/hexpm/dt/erlex.svg)](https://hex.pm/packages/erlex)
[![License badge](https://img.shields.io/hexpm/l/erlex.svg)](https://github.com/asummers/erlex/blob/master/LICENSE.md)
[![Build status badge](https://img.shields.io/circleci/project/github/asummers/erlex/master.svg)](https://circleci.com/gh/asummers/erlex/tree/master)
[![Code coverage badge](https://img.shields.io/codecov/c/github/asummers/erlex/master.svg)](https://codecov.io/gh/asummers/erlex/branch/master)
[![Last Updated badge](https://img.shields.io/github/last-commit/asummers/erlex.svg)](https://github.com/asummers/erlex/commits/master)

# Erlex

@@ -64,6 +67,7 @@ iex> Erlex.pretty_print_contract(str)
binary()
) :: Plug.Conn.t()
```

## Contributing

We welcome contributions of all kinds! To get started, click [here](https://github.com/asummers/erlex/blob/master/CONTRIBUTING.md).
93 changes: 39 additions & 54 deletions lib/erlex.ex
Original file line number Diff line number Diff line change
@@ -135,14 +135,7 @@ defmodule Erlex do
else
joiner = "Contract head:\n"

pretty =
Enum.map_join([head | tail], "\n\n" <> joiner, fn contract ->
contract
|> to_charlist()
|> do_pretty_print_contract()
end)

joiner <> pretty
joiner <> Enum.map_join([head | tail], "\n\n" <> joiner, &do_pretty_print_contract/1)
end
end

@@ -217,13 +210,7 @@ defmodule Erlex do
end

defp do_pretty_print({:assignment, {:atom, atom}, value}) do
name =
atom
|> deatomize()
|> to_string()
|> strip_var_version()

"#{name} = #{do_pretty_print(value)}"
"#{normalize_name(atom)} = #{do_pretty_print(value)}"
end

defp do_pretty_print({:atom, [:_]}) do
@@ -376,26 +363,20 @@ defmodule Erlex do
end

defp do_pretty_print({:map, map_keys}) do
%{struct_name: struct_name, entries: entries} = struct_parts(map_keys)
case struct_parts(map_keys) do
%{name: name, entries: [{:map_entry, {:atom, [:_]}, {:atom, [:_]}}]} ->
"%#{name}{}"

if struct_name do
"%#{struct_name}{#{Enum.map_join(entries, ", ", &do_pretty_print/1)}}"
else
"%{#{Enum.map_join(entries, ", ", &do_pretty_print/1)}}"
%{name: name, entries: entries} ->
"%#{name}{#{Enum.map_join(entries, ", ", &do_pretty_print/1)}}"
end
end

defp do_pretty_print({:named_type_with_appended_colon, named_type, type})
when is_tuple(named_type) and is_tuple(type) do
case named_type do
{:atom, name} ->
name =
name
|> deatomize()
|> to_string()
|> strip_var_version()

"#{name}: #{do_pretty_print(type)}"
"#{normalize_name(name)}: #{do_pretty_print(type)}"

other ->
"#{do_pretty_print(other)}: #{do_pretty_print(type)}"
@@ -406,13 +387,7 @@ defmodule Erlex do
when is_tuple(named_type) and is_tuple(type) do
case named_type do
{:atom, name} ->
name =
name
|> deatomize()
|> to_string()
|> strip_var_version()

"#{name} :: #{do_pretty_print(type)}"
"#{normalize_name(name)} :: #{do_pretty_print(type)}"

other ->
"#{do_pretty_print(other)} :: #{do_pretty_print(type)}"
@@ -425,13 +400,7 @@ defmodule Erlex do
"#{atomize(name)}.#{deatomize(type)}()"

{:atom, name} ->
name =
name
|> deatomize()
|> to_string()
|> strip_var_version()

"#{name} :: #{deatomize(type)}()"
"#{normalize_name(name)} :: #{deatomize(type)}()"

other ->
name = do_pretty_print(other)
@@ -536,10 +505,16 @@ defmodule Erlex do
end)

when_names =
when_names
|> Enum.map(fn {_, v} -> v |> atomize() |> String.trim_leading(":") end)
Enum.map(when_names, fn {_, name} ->
name
|> atomize()
|> String.trim_leading(":")
end)

printed_whens = pretty_names |> Enum.reverse() |> Enum.join(", ")
printed_whens =
pretty_names
|> Enum.reverse()
|> Enum.join(", ")

{printed_whens, when_names}
end
@@ -572,8 +547,8 @@ defmodule Erlex do
end
end

defp atomize(<<atom>>) when is_number(atom) do
"#{atom}"
defp atomize(<<number>>) when is_number(number) do
to_string(number)
end

defp atomize(atom) do
@@ -582,7 +557,10 @@ defmodule Erlex do
if String.starts_with?(atom, "_") do
atom
else
inspect(:"#{String.trim(atom, "'")}")
atom
|> String.trim("'")
|> String.to_atom()
|> inspect()
end
end

@@ -596,19 +574,19 @@ defmodule Erlex do
end

defp struct_parts(map_keys) do
%{struct_name: struct_name, entries: entries} =
Enum.reduce(map_keys, %{struct_name: nil, entries: []}, &struct_part/2)
%{name: name, entries: entries} =
Enum.reduce(map_keys, %{name: "", entries: []}, &struct_part/2)

%{struct_name: struct_name, entries: Enum.reverse(entries)}
%{name: name, entries: Enum.reverse(entries)}
end

defp struct_part({:map_entry, {:atom, '\'__struct__\''}, {:atom, struct_name}}, struct_parts) do
struct_name =
struct_name
defp struct_part({:map_entry, {:atom, '\'__struct__\''}, {:atom, name}}, struct_parts) do
name =
name
|> atomize()
|> String.trim("\"")

Map.put(struct_parts, :struct_name, struct_name)
Map.put(struct_parts, :name, name)
end

defp struct_part(entry, struct_parts = %{entries: entries}) do
@@ -632,4 +610,11 @@ defmodule Erlex do
end

defp deatomize_char(char), do: char

defp normalize_name(name) do
name
|> deatomize()
|> to_string()
|> strip_var_version()
end
end
Loading