Commit Graph
234 Commits
Author SHA1 Message Date
Eksperimental e974743475 Fix specs in EEx.Tokenizer (#9061)
Spec for t:token/0 was missing on element in the tuple

this created a series of Dialyzer errors when running `make dialyze`

/elixir/lib/eex/lib/eex/compiler.ex:44: The pattern <[{'expr', _line@1, _mark@1, _chars@1, _} | _rest@1], _buffer@1, _scope@1, _state@1> can never match the type <[{'text',binary() | maybe_improper_list(any(),binary() | [])} | {'end_expr',non_neg_integer(),[any()],binary() | maybe_improper_list(any(),binary() | [])} | {'expr',non_neg_integer(),[any()],binary() | maybe_improper_list(any(),binary() | [])} | {'middle_expr',non_neg_integer(),[any()],binary() | maybe_improper_list(any(),binary() | [])} | {'start_expr',non_neg_integer(),[any()],binary() | maybe_improper_list(any(),binary() | [])}],_,[],#{'engine':=_, 'file':=_, 'line':=non_neg_integer(), 'quoted':=[], 'start_line':='nil'}>
2019-05-21 09:26:33 +02:00
José Valim c50a8308cf Update EEx tokenizer tests 2019-04-24 08:21:40 +02:00
José Valim cf5d080656 Consistently trim on multiple lines, closes #8792 2019-04-24 07:59:32 +02:00
José Valim b3ac0608aa Raise on bad EEx state, closes #8790 (#8976) 2019-04-23 11:54:34 +02:00
Eksperimental 84f9128825 Replace use of "item(s)" with "element(s)" in Enum module (#8885) 2019-03-12 23:24:22 +01:00
Joe Yates 346f7240fe Explicity test EEx options in error messages (#8692) 2019-01-24 22:19:34 +01:00
Joe Yates 051d3b40eb Ensure we're testing the actual assignment metadata (#8691)
The existing test was not actually testing anything, as
the default argument to Keyword.get/3, 0, matched one of the
expected values.
2019-01-24 21:05:02 +01:00
Tobiasz Małecki 2afc16b623 EEx.SmartEngine moduledoc examples improvement (#8681) 2019-01-22 23:02:44 +01:00
Tobiasz Małecki 4d5f903cc3 EEx examples improvement (#8680) 2019-01-22 22:19:02 +01:00
José Valim 0ce62a2add Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
José Valim 52ff4ce544 Group tests and run the formatter 2019-01-04 14:45:52 +01:00
José Valim 92b41acc88 Properly handle closing brackets in do in EEx 2019-01-04 14:35:36 +01:00
Benjamin Milde 3d5d42afd4 Improve eex tokenizer further (#8594) 2019-01-04 14:30:23 +01:00
Benjamin Milde 74ca2ac5dc Allow more complex mixed expressions in EEx (#8591)
Closes #8590.
2019-01-04 09:07:02 +01:00
José Valim 0c1df34645 Standardize more TODOs 2018-12-21 13:42:54 +01:00
José Valim 9ff2a51f49 Streamline EEx.Engine docs 2018-11-21 14:58:23 +01:00
José Valim 721358cef0 Optimize EEx template rendering (#8413)
Consider the following template:

    one
    <%= arg1 %>
    two
    <% var2 = String.duplicate(arg2, 1) %>
    three
    <%= var2 %>
    four
    <% var3 = String.duplicate(arg3, 1) %>
    five
    <%= var3 %>
    six

Before this patch, it would compile to:

    (
      tmp1 = (
        tmp2 = (
          tmp1 = (
            tmp2 = (
              tmp1 = "" <> "one\n"
              tmp1 <> String.Chars.to_string(arg1)
            ) <> "\ntwo\n"
            var2 = String.duplicate(arg2, 1)
            tmp2
          ) <> "\nthree\n"
          tmp1 <> String.Chars.to_string(var2)
        ) <> "\nfour\n"
        var3 = String.duplicate(arg3, 1)
        tmp2
      ) <> "\nfive\n"
      tmp1 <> String.Chars.to_string(var3)
    ) <> "\nsix\n"

The issue with this approach is that it emits binary append
instructions, frequently copying binaries. This commit changes
it to extract all of the dynamic contents out, as originally
suggested by @tmbb:

    tmp0 = String.Chars.to_string(arg1)
    var2 = String.duplicate(arg2, 1)
    tmp1 = String.Chars.to_string(var2)
    var3 = String.duplicate(arg3, 1)
    tmp2 = String.Chars.to_string(var3)
    <<"one\n", tmp0::binary, "\ntwo\n", "\nthree\n", tmp1::binary, "\nfour\n", "\nfive\n", tmp2::binary, "\nsix\n">>

Which leads to code that compiles faster and also run faster
as there are less instructions.
2018-11-21 11:25:22 +01:00
Fernando Tapia Rico d58340d7ab Omit parens on calls with only do/end blocks (Macro.to_string) (#8396) 2018-11-16 20:51:14 +01:00
José Valim 7b17320f10 Use state instead of buffer for clarity 2018-09-20 11:07:28 +02:00
Peter Saxton 624608e775 Tidy EEx docs (#8159) 2018-09-02 10:18:42 +02:00
Devon Estes f3c610e921 Remove unnecessary "no_return" types in specs (#8092) 2018-08-16 16:31:57 +02:00
Andrea Leopardi 6023568bcf Deprecate using non-empty lists with the Collectable protocol (#7785)
Closes #7421.
2018-07-12 12:13:32 +02:00
Wojtek Mach daf5ed3d5c Add "@impl true" to Exception callbacks (#7681) 2018-05-16 09:28:58 +02:00
José Valim 75541cf472 Condititionally compile and lazily compute __STACKTRACE__ (#7648)
Erlang/OTP 20 warns if the stacktrace is read outside of a
catch/rescue. This commit mirrors this behaviour by consistently
warning on `System.stacktrace/0` being used outside of a
catch/rescue.

Erlang/OTP 21 warns whenever System.stacktrace/:erlang.get_stacktrace
are used. Therefore we need to promote the usage of `__STACKTRACE__`
and make sure to conditionally compile it according to the OTP version.
This requires changes to the Exception normalization mechanism
so we compute `__STACKTRACE__` only when strictly required.

In future Elixir releases, `System.stacktrace/0` will warn when
used even inside catch/rescue.
2018-05-07 15:33:36 +02:00
Aleksei Magusev e9dfa50c74 Format all the examples in the docs (#7318) 2018-02-06 07:27:13 +01:00
José Valim 794928efe1 Restrict next break fits and eols on operators and function calls
* Whitelist which operators support next_break_fits
  * No longer consider tuples as part of next_break_fits
  * Do not consider eol for = and ::
  * Do not consider eol for calls with one next_break_fits arg
2017-10-27 12:34:09 +02:00
José Valim 874fa06d1f Fixes to previously formatted files 2017-10-12 09:01:21 +02:00
Nathan Willson 871111f0d9 Run code formatter on tokenizer_text.exs (#6905) 2017-10-12 09:00:21 +02:00
José Valim 4bb7664e05 Format more files with little formatting requirement 2017-10-10 20:00:45 +02:00
José Valim f388f95398 Format more files with little formatting requirement 2017-10-10 19:19:32 +02:00
José Valim e2c83e51c7 Format more low hanging fruit files 2017-10-10 18:05:42 +02:00
Jerel Unruh 22c88893ee Run formatter on lib/eex/lib/eex/tokenizer.ex (#6816) 2017-10-10 17:02:30 +02:00
José Valim 6a2ae9f926 Improve formatting on eex_test 2017-10-10 16:33:01 +02:00
Zachary Gohr 96f1f83b86 Run code formatter on EExTest.Compiled (#6781) 2017-10-10 16:26:48 +02:00
Alessandro Nuzzo f763431c29 Run code formatter on EEx.Compiler (#6692) 2017-10-09 19:53:30 +02:00
Petr Stepchenko 45cb528158 Run the code formatter on test_helper.exs (#6671) 2017-10-09 13:56:40 +02:00
José Valim c90beb1476 Format first file and mix.exs scripts 2017-10-08 19:34:44 +02:00
José Valim 455c2c3f3b Rely on side effects for preserving comments
The previous implementation would not lead to parsing
errors in interpolations since code inside interpolation
is parsed immediately.
2017-10-05 13:27:25 +02:00
Pedro Medeiros 843bd0d9b7 Raise on middle expression without start expression in EEx (#6610) 2017-09-28 10:33:56 +02:00
Aleksei Magusev c6a0edcd32 Use MixProject instead of Mixfile in mix.exs files 2017-08-20 21:40:23 +02:00
José Valim 27918ffbc2 Add handle_begin and handle_end to EEx
Elixir v1.5.0 attempted to repurpose the value of init
to use throughout the engine but such was a breaking change.

To address this problem, we added handle_begin and
handle_end which were designed exactly to handle inner
buffers.

This comes with the benefit that EEx.Engine can now have
any data structure as state and no longer only quoted
expressions.

Closes #6391.
2017-07-29 22:05:38 +02:00
Tomek Gryszkiewicz 85bed94ec9 Allow markers "/" and "|" to be used in a custom EEx engine (#6281) 2017-07-03 22:02:37 +02:00
Wojtek Mach a701cc8bc2 Turn EEx.SyntaxError into a warning to keep backwards compatibility (#6220) 2017-06-14 17:51:41 +02:00
Wojtek Mach 55c40b465f Use new mix.exs style in docs, core apps mix.exs and generated README (#6215) 2017-06-12 10:05:41 +02:00
Eksperimental b89d010b1d Replace Keyword.t/0-1 types with built-in keyword/0-1 (#6124) 2017-06-04 11:11:57 +01:00
Mengxuan Xia a8fbcb2e28 More work regarding making CI on Windows green (#6150) 2017-05-26 00:50:58 +02:00
Sam Davies 481280e321 Dogfood new defoverridable syntax (#6100) 2017-05-22 23:58:47 +02:00
Leif Gensert 797fde6d14 Improve typespec of EEx.Engine.fetch_assign! (#6118)
Whenever EEx templates are used to pass variables via "assigns" whatever
this data structure is will be passed into "EEx.Engine.fetch_assign" and
then into "Access.fetch/2".

So it makes sense to use the same typespec for the both. Otherwise
dialyzer will complain about every instance where keyword lists are
passed into functions like "eval_string", "function_from_file" and
"function_from_string".
2017-05-18 15:20:42 +02:00
José Valim 2daf5829d9 Do not raise on invalid eex expression as it was accidentally supported 2017-03-07 12:38:59 +01:00
Aleksei Magusev 8c3f47be7b Improve code style in EEx.Compiler 2017-02-23 23:58:20 +01:00