Commit Graph
54 Commits
Author SHA1 Message Date
Jonatan Männchen e1d171e5c7 Add inline License / Copyright to Erlang files (#14255) 2025-02-05 13:50:00 +01:00
José Valim 14f3a1e372 Deprecate single quotes as charlists 2023-10-29 13:30:03 +01:00
Vinícius Müller 0349240827 Add MistmatchedDelimiterError (#12918) 2023-09-12 12:18:51 +02:00
Zach Allaun 2d65a4613b Fix column count when tokenizing escaped interpolations (#12504) 2023-03-30 22:24:23 +02:00
José Valim b8c7bfa1bf Add prune_binding to Code.eval_quoted_with_env/4 2022-10-29 20:42:51 +02:00
José Valim bee0bb56be Do not emit warnings when formatting code
Closes #11595.
2022-01-26 13:37:53 +01:00
José Valim 851ac27272 Run unicode security linting on more tokens 2022-01-21 10:50:02 +01:00
José Valim e480151fe7 Add Code.Fragment.container_cursor_to_quoted/2 (#11315) 2021-10-16 15:12:09 +02:00
José Valim 35a066dd0b Fix warning on Erlang suite 2021-06-08 08:56:10 +02:00
Wojtek Mach 63be6419ee Add :column to Code.string_to_quoted*/2 2020-01-12 15:41:36 +01:00
José Valim dbf8a7a9fe Use version metadata in Erlang pass 2019-11-16 02:45:55 +01:00
José Valim ab71fef4a9 Reduce private API surface 2019-07-29 15:20:13 +02:00
José Valim d9af62f7e5 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim fc8de8a440 Warn on unnecessary quotes (#7838) 2018-07-10 10:27:02 +02:00
José Valim 216d6d6edf 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
José Valim 703e3000a6 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 a33cbcd32a Format errors_test.exs 2017-10-12 09:35:58 +02:00
José Valim 0f14e2bd99 Update tokenizer and interpolation tests 2017-10-05 19:29:47 +02:00
José Valim 1bee120b5a Add more formatter metadata 2017-08-30 17:21:17 +02:00
José Valim 61903399f4 Do not unescape interpolation 2017-08-28 14:17:12 +02:00
Andrea Leopardi 7b111ac593 Merge integer tokens into the "int" token (#6499) 2017-08-23 11:55:12 +02:00
Andrea Leopardi db65e4a6ab Change the format of tokens (#6495)
Right now, tokens are "{Token, Location}" or "{Token, Location, Value}".
This commit changes "Location" from "{Line, StartColumn, EndColumn}" to
"{Line, {StartColumn, EndColumn}, Meta}" where "Meta" can be anything.
This will be used for things such as storing the format of integers.
2017-08-22 21:12:30 +02:00
Alex Jiao a1caeeb5ec Augment integer literals with representation info (#6344) 2017-07-18 14:40:59 +02:00
José Valim 2f663ce3a2 Add non-quoted Unicode atoms and variables (#6158)
It follows Unicode Annex #31.

See the Unicode Syntax document for a more in-depth reference.
2017-05-27 22:43:05 +02:00
José Valim c6aad4518f Ensure variables in function clauses are not reused, closes #4815
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-06-15 16:14:48 +02:00
eksperimental ba111fb9b3 Formatting: add white space after comma (#4491)
Standardizes the use of comma leaving a white space after it whenever applicable.

Note: It does not enforce this in quantifiers in regular expressions such as in: `x{1,3}`
2016-04-19 01:23:50 +02:00
Andrea Leopardi a00fe5a017 Handle chars literals in the parser for better syntax errors
Before this commit, we handled char literals (like `?a`) in the
tokenizer, turning a literal like `?a` into the token `{:number, _,
97}` (thus indistinguishable from the literal `97` at the parsing
stage). This led to error messages with the integer for the character
instead of the character literal, e.g.:

    iex> :ok ?a
    ** (SyntaxError) iex:11: syntax error before: 97

With this commit, we now turn `?a` into the token `{:char, _,
97}` (which is the same token used by Erlang for Erlang char literals
like `$a`); since it's the same token as in Erlang, the parser will now
output the char literal as an Erlang char (`?a` would be printed as
`$a`). We hijack the error message in elixir_errors.erl to end up with
the correct message:

    iex> :ok ?a
    ** (SyntaxError) iex:11: syntax error before: ?a
2016-04-04 21:29:15 +02:00
José Valim 6497c614d3 Improve unexpected token error messages 2015-09-01 00:32:46 +02:00
eksperimental f9bcdd5c1c Add space after comma: Format consistently 2015-03-17 22:55:27 +07:00
Alexander Ivanov fa5921fa33 Fix column counting in elixir_interpolation.erl 2015-01-06 16:57:00 +02:00
Alexander Ivanov 1a456768d5 Change location info format in tokenizer
Start column counting in tokenizer from 1, store location info in a tuple `{Line, BeginColumn, EndColumn}` instead of a list
2015-01-05 13:35:23 +02:00
Alexander Ivanov d7e00557d0 Add column info in tokenizer, #2987
Add column info for each token in elixir_tokenizer.
Change the format of location info from `Line` to `[Line, BeginColumn,
EndColumn]`. Pass the current column after the current line in
`elixir_tokenizer:tokenize`. Reflect the change in related modules.
2015-01-05 03:34:53 +02:00
Eric Meadows-Jönsson 83f7fa5ca0 Move elixir.hrl to src/ 2014-08-19 17:00:58 +02:00
José Valim c11af58d93 Make a distinction between eol and ; 2014-08-12 16:27:45 +02:00
José Valim 28264c6792 Improvements to the operator table
* |>, <<<, >>> and ^^^ were made left associative

  * <, >, <=, >= were given higher precedence than
    comparison ones (==, !=, etc)

  * xor is deprecated
2014-06-29 16:18:33 +02:00
José Valim c22e8e85dc Convert exceptions to structs 2014-05-16 00:01:49 +02:00
José Valim 56f15d9f4e Do not add spaces after { and before }
This makes the source code consistent with the result
returned by inspect/2.
2014-04-21 19:06:35 +02:00
Yuki Ito 013303a44e Support end-of-line backslash in quoted expressions
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2014-02-19 12:23:30 +01:00
José Valim f8b019c7c8 Move to the new expansion on the front-end 2013-12-28 23:14:55 +01:00
José Valim 0171e201fb Move parsing from elixir_interpolations to elixir_parser 2013-10-26 13:46:01 +02:00
José Valim 404f77421a Refactor string interpolation to delegate to the tokenizer
This refactoring helps us clean up the interpolation code and
guarantee it works as expected since it goes under the same
tokenization rules. It also helps provide better sigil handling
(going to be improved in upcoming commits).
2013-10-25 13:19:47 +02:00
elegua e63e4d44a3 Fixed interpolation per issue 1758 2013-10-24 11:25:34 -07:00
José Valim 0510512375 Deprecate to_binary in favor of to_string
We also rename Binary.Chars to String.Chars.

As Binary.Chars was the protocol used for interpolation,
it is semantically correct to have a protocol that works
on strings, instead of raw binaries.
2013-08-22 12:19:30 +02:00
José Valim a013b39b8f Do not double escape strings inside interpolation, closes #1494 2013-07-25 14:34:13 +02:00
José Valim 2c98c0999d An Elixir module now translates to Elixir.Module instead of Elixir-Module 2013-05-23 14:36:56 +02:00
José Valim 6024014482 Improve error message on unclosed interpolation/string, closes #794 2013-03-17 13:57:20 -06:00
José Valim 89cbe93bba The AST now allows metadata to be attached to each node
This means the second item in the AST is no longer an integer
(representing the line), but a keywords list. Code that relies
on the line information from AST or that manually generate AST
nodes need to be properly updated.
2013-01-21 15:42:03 -07:00
mururu 5711d74fd9 Support "\a" 2012-12-27 09:18:13 +09:00
mururu a00aaf48e3 Fix indent 2012-12-26 15:42:47 +09:00
Kim Shrier d5613ed380 add code and tests for case insensitive hex interpolation. 2012-12-21 23:32:01 -07:00