asummers / erlex Goto Github PK
View Code? Open in Web Editor NEWConvert Erlang style structs and error messages to equivalent Elixir.
License: Other
Convert Erlang style structs and error messages to equivalent Elixir.
License: Other
While upgrading our app, I stumbled upon these warnings:
warning: in order to compile .yrl files, you must add "compilers: [:yecc] ++ Mix.compilers()" to the "def project" section of erlex's mix.exs
(mix 1.16.2) lib/mix/tasks/compile.yecc.ex:70: Mix.Tasks.Compile.Yecc.preload/1
(mix 1.16.2) lib/mix/compilers/erlang.ex:66: Mix.Compilers.Erlang.compile/6
(mix 1.16.2) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
(mix 1.16.2) lib/mix/tasks/compile.all.ex:124: Mix.Tasks.Compile.All.run_compiler/2
(mix 1.16.2) lib/mix/tasks/compile.all.ex:104: Mix.Tasks.Compile.All.compile/4
(mix 1.16.2) lib/mix/tasks/compile.all.ex:93: Mix.Tasks.Compile.All.with_logger_app/2
warning: in order to compile .xrl files, you must add "compilers: [:leex] ++ Mix.compilers()" to the "def project" section of erlex's mix.exs
(mix 1.16.2) lib/mix/tasks/compile.leex.ex:69: Mix.Tasks.Compile.Leex.preload/1
(mix 1.16.2) lib/mix/compilers/erlang.ex:66: Mix.Compilers.Erlang.compile/6
(mix 1.16.2) lib/mix/task.ex:478: anonymous fn/3 in Mix.Task.run_task/5
(mix 1.16.2) lib/mix/tasks/compile.all.ex:124: Mix.Tasks.Compile.All.run_compiler/2
(mix 1.16.2) lib/mix/tasks/compile.all.ex:104: Mix.Tasks.Compile.All.compile/4
(mix 1.16.2) lib/mix/tasks/compile.all.ex:93: Mix.Tasks.Compile.All.with_logger_app/2
==> erlex
Compiling 2 files (.erl)
Compiling 1 file (.ex)
Generated erlex app
Opening this so we can discuss it!
Expression produces a value of type:
%{:__struct__ => atom(), atom() => _}
but this value is unmatched.
When multiple contract heads are encountered, the output would be more reasonable if newline separated the contract heads.
Example from pretty_print_test.exs
expected_output =
"Contract head: (any(), nil) :: nilContract head: (Ecto.Queryable.t(), String.t()) :: String.t()"
I believe this to be more readable if it includes an additional newline:
expected_output =
"Contract head: (any(), nil) :: nil\nContract head: (Ecto.Queryable.t(), String.t()) :: String.t()"
Using Elixir 1.8.0 on OTP 21.2.2
==> erlex
Compiling 2 files (.erl)
/usr/lib64/erlang/lib/parsetools-2.1.5/include/yeccpre.hrl:60: Warning: erlang:get_stacktrace/0: deprecated; use the new try/catch syntax for retrieving the stack backtrace
Compiling 1 file (.ex)
Generated erlex app
This code fails on dialyxir master. It looks like we just need to keep a space after "when" in the spec we pass to the code formatter from pretty_print_contract
, Code.format_string! is complaining about 'ok'whenone
.
defmodule WhatTheSpec do
@type key :: atom()
@type transaction :: map()
def put(_, _, _ \\ nil)
@spec put(one, key(), any()) :: transaction() when one: transaction()
def put(t, _, _) when is_map(t), do: t
@spec put(one, any(), Keyword.t()) :: :ok when one: key()
def put(_, _, _), do: :ok
@spec put_foo(any()) :: :ok
def put_foo(value) do
put(:foo, value, nil) # note the explicit nil here
end
end
'(one,key(),any()) -> transaction() when one :: transaction();(one,any(),\'Elixir.Keyword\':t()) -> \'ok\' when one :: key()'
%SyntaxError{
description: "syntax error before: whenone",
file: "nofile",
line: 1
}
** (throw) {:error, :formatting, "@spec a(:one, any(), Keyword.t()) :: 'ok'whenone :: key()\ndef a() do\n :ok\nend\n"}
See e.g. #4
Nothing big, just noticing a potential couple bugs as I was running a new BEAM typer (it's a negative ML typer, not a weak positive typer like Dialyzer, Gradualizer, would make for an awesome addition into Dialyxir so I don't have to publish and keep up Gradualixir ^.^) over one of my projects and erlex had a couple things pop up that aren't entirely, though some are it's fault:
_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The variable _byte@1 on line 269 is expected to have type integer() but it has type term()
_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The pattern [61, 58, 61] on line 0 does not have type:
infix :: 'Elixir.String':t()
_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The pattern [112, 97, 116, 116, 101, 114, 110, 32 | _rest@1] on line 0 does not have type:
pattern :: 'Elixir.String':t()
_build/test/lib/erlex/ebin/parser.beam: The pattern {ok, [{atom, _, Symbol}], _} on line 74 doesn't have the type {error,
ErrorInfo :: error_info(),
non_neg_integer() | {line(), column()}} |
{ok,
Tokens :: tokens(),
non_neg_integer() | {line(), column()}}
And the lexer.erl
file is fine.
In essence it's saying that:
The lib/erlex.ex
file line 269 the byte
in the expression of <<byte::8>>
is supposed to have type integer, but it can potentially be any type, and thus can potentially fail, however that's because Elixir's Enum.into/3
isn't typespec'd properly, so that's entirely Elixir's fault.
The lib/erlex.ex
file on (not actually line 0) https://github.com/asummers/erlex/blob/master/lib/erlex.ex#L73 it has the line def pretty_print_infix('=:='), do: "==="
but it's typespec'd as @spec pretty_print_infix(infix :: String.t()) :: String.t()
and Elixir's String.t()
type is typespec'd as https://github.com/elixir-lang/elixir/blob/v1.9.2/lib/elixir/lib/string.ex#L213 :
@type t :: binary
And thus the character list is not a binary, hence it's failing (isn't dialyzer itself catching this one?!).
Same thing again on line https://github.com/asummers/erlex/blob/master/lib/erlex.ex#L96 with def pretty_print_pattern('pattern ' ++ rest) do
when it's typespec'd as @spec pretty_print_pattern(pattern :: String.t()) :: String.t()
binaries.
As for the parser file, no clue where it is complaining about, but it's missing a failure case and the success case is too tightly bound.
This was mostly just for fun, and the fact erlex only has 4 issues reported unlike the 4000 that most other libraries have. ^.^;
E.g. from failures on Atom.to_string
. See discussion in #8
Empty tuples are a thing, and this doesn't deal with them. I don't know how they're useful, but they're legal so we should parse them.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.