Commit Graph
221 Commits
Author SHA1 Message Date
José Valim 69d085abd4 Improve errors for calls on aliases 2019-10-21 21:02:00 +02:00
Björn Gustavsson 9f8593fd6b Optimize elixir_tokenizer (#9347)
When comparing characters in `elixir_tokenizer`, replace `==` and `/=`
with the more efficient `=:=` and `=/=` operators.

The `=:=` and `=/=` operators are more efficient because they can
only return `true` if the operands have the same type:

    1> $* =:= 42.
    true
    2> $* =:= 42.0.
    false

In contrast, the `==` operator can return `true` when comparing
an integer and a float:

    3> $* == 42.0.
    true

Using `=:=` and `=/=` also gives the Erlang compiler more opportunites
for optimization. For example, when compiling the `is_sigil` macro,
the compiler can combine all eight comparisons into a single `select_val`
instruction instead of emitting eight separate instructions.
2019-09-14 12:42:07 +02:00
José Valim 9540e9fd6a Raise correct error message for incomplete interpolation in heredoc, closes #9252 2019-07-30 18:36:41 +02:00
José Valim f38895cebb Add literal encoder option to Code.string_to_quoted 2019-06-19 00:04:08 +02:00
kw7oe f44adfbeb0 Improve heredoc error message (#9048) 2019-05-19 10:10:11 +02:00
José Valim 0229358f88 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim 7cd6ce4a32 Also provide nice error message on null bytes 2019-05-06 16:37:54 +02:00
Tomáš Janoušek 8d079862dc Fix columns in tokenize of dot_call_op (#8995)
handle_dot already gets the column of `(` from strip_dot_space.
2019-04-29 23:34:08 +02:00
Arjan Scherpenisse cef19c9365 Implement static_atom_encoder tokenizer option (#8956) 2019-04-14 19:44:17 +02:00
José Valim 391e4f6c56 Improve invalid interpolation error message 2019-04-11 12:53:09 +02:00
Eksperimental 99d919e0c8 Use "code point" instead of "codepoint" (#8774)
That's the term it is used in the Unicode standard.
2019-02-06 11:21:03 +01:00
Eksperimental 5bd907d126 Use hexadecimal notation in code points in tokenizer error msg (#8669) 2019-01-22 13:39:40 +01:00
José Valim 0ce62a2add Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
José Valim 0c1df34645 Standardize more TODOs 2018-12-21 13:42:54 +01:00
Eksperimental f2d1b4209b ascii -> ASCII (#8499) 2018-12-10 09:24:34 +01:00
José Valim 050f10e849 Improve message for unnecessary quotes, closes #8197 2018-09-14 22:05:23 +02:00
José Valim 95ec1be78a Clean up private elixir_config API 2018-07-19 23:27:52 +02:00
Jean-Philippe Cugnet 3b030b009e Fix a typo in the unnecessary quotes warning (#7934)
[ci skip]
2018-07-19 19:44:58 +02:00
José Valim beb596d37c Warn on unnecessary quotes (#7838) 2018-07-10 10:27:02 +02:00
José Valim 6cf3d8c20a Return error tuple for long quoted atoms 2018-07-09 10:49:38 +02:00
Adrian Cruz dd880e209c Return an error tuple for interpolation in function call (#7836) 2018-07-09 10:24:26 +02:00
José Valim 2ece95c1db Handle other unescaped tokens in tokenizer 2018-07-03 12:14:16 +02:00
Adrian Cruz 9707843134 Return error on bad hex escaping (#7809)
As discussed in #7270, it would help if we return error tuples
instead of exceptions. This PR does it for string unescaping.
2018-07-03 12:03:43 +02:00
José Valim 22245a44fe Only show mismatch hints for fn+do/end 2018-06-21 14:08:30 +02:00
José Valim 5edb1d2739 Add hints on mismatched do/end and others pairs
When you are working on large files and you add new code,
you may forget to add a `do` or an `end`. In those cases,
the error message usually points to the first `do` or the
last `end` in the file, which are usually far away from
the source of the error.

This pull request adds a simple heuristic based on the
indentation of the tokens, to try to provide hints of
where the source may be. Those hints are not deterministic
but they may be able to point users to the source of the
problem.

For example, in this case:

    defmodule MyApp do
      def one do
      # end

      def two do
      end
    end

we know that we now that `def two do` is happening on the
same indentation as `def one do`, which may mean that
`def one do` was not closed properly. We store this as a
hint in case the terminators do not match later.

Similarly, in the case below:

    defmodule MyApp do
      def one
      end

      def two do
      end
    end

The `end` on line 3 will end-up closing the defmodule `do`,
on line 1. Because their indentation do not match, it may
be that there is a missing `do`, where the `end` was supposed
to align.

Some basic testing show those heuristics work on the majority
of the cases, but we will only be sure when we have enough
feedback from the community.
2018-06-10 13:55:49 +02:00
René Föhring 1ade3c0dd9 Fix column in :elixir_tokenizer for double quotes in keyword identifiers (#7722)
This fixes cases where `:elixir_tokenizer` does not account for double
quotes in keyword identifiers when determining the column for the next
token.
2018-06-04 16:06:42 +02:00
Andrea Leopardi 1aba6f72c6 Warn when a variable/atom that ends in / or ? is followed by = with no space (#7608) 2018-04-27 16:49:11 -03:00
José Valim cfaf9dbbcd Improve warning about escaped codepoints in ? 2018-04-11 09:25:42 +02:00
René Föhring 901752a4fe Fix column in :elixir_tokenizer for sigils with modifiers (#7529)
This fixes cases where :elixir_tokenizer does not account for sigil modifiers
when determining the column for the next token.
2018-04-03 13:16:02 +02:00
Andrea Leopardi ae6fb479b5 Remove a useless guard in elixir_tokenizer 2018-03-27 12:32:42 +02:00
Glauber Campinho 0757cf8028 Optimize tokenizer for commas (#7493)
Small optimization skipping the `handle_terminator` function
for commas since they don't require terminators.
2018-03-26 22:31:58 +02:00
Glauber Campinho add3a9666f Fix column count on heredoc tokenizer (#7486) 2018-03-25 12:37:15 +02:00
Andrea Leopardi f30b29aca1 Prevent operators with many of same char to have same char after them (#7344) 2018-02-14 09:43:55 +01:00
José Valim 4b134c8cf5 Raise on invalid map syntax, closes #7268 2018-01-28 11:04:25 -02:00
Andrea Leopardi 8c05bb078d Fix a typo in a heredoc-related warning
[ci skip]
2018-01-08 14:23:39 +01:00
José Valim f34d74913c Warn if heredoc is outdented, closes #7174 2018-01-07 17:46:42 +01:00
José Valim ad190b0889 Raise on reserved tokens, closes #6532 2017-11-06 17:15:44 +01:00
Blake Tan 554d595009 Better handling of non existing atoms (#6978) 2017-10-26 20:25:00 +02:00
José Valim d3a85bfd21 Remove end column information from tokens
If we want to store this information, we need to store it
alongside the end line, otherwise it is ambiguous.
2017-10-25 11:56:31 +02:00
José Valim c5f6271872 Keep integer/float underscores in the formatter, closes #6931 2017-10-16 16:44:53 +02:00
José Valim 34651f1034 Format errors_test.exs 2017-10-12 09:35:58 +02:00
José Valim 41ca9abfc7 Properly render :-> as an atom 2017-10-09 22:55:07 +02:00
José Valim 9b5af3303d Also preserve user newlines if trailing commas exist 2017-10-09 09:17:35 +02:00
José Valim 4387576126 Add more metadata to containers 2017-10-07 00:18:22 +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
Artur Cygan c0fd3d2655 Improve error message on oversized atom (#6612) 2017-09-28 14:04:29 +02:00
José Valim 28bd48ed21 Do not prematurely raise on end tokens, closes #6567 2017-09-12 21:58:46 +02:00
José Valim a8bafae468 Store eol info in arrow ops 2017-09-01 00:58:15 +02:00
José Valim 97ece16b11 Add more formatter metadata 2017-08-30 17:21:17 +02:00
José Valim 6030be5ae5 Add literal annotation for aliases 2017-08-28 23:59:45 +02:00