Commit Graph
145 Commits
Author SHA1 Message Date
Andrea Leopardi dd78780363 Fix a few typos introduced in 904e89782d 2016-09-21 11:11:16 +02:00
Steven Blowers 904e89782d Fixing spelling mistakes of specially -> especially. (#5235) 2016-09-21 10:27:34 +02:00
Aleksei Magusev 34bf464bc1 Remove trailing period in error message for missing terminator 2016-08-13 00:44:49 +02:00
ottolin 5eb2e30b1a Enhancing error message for token matching failure (#5123) 2016-08-10 13:55:03 +02:00
Mike Stok 05431f6010 keep tokenizer's column counts in sync for numbers with _ characters
For providing better feedback in credo and tools like it we should be
able to map a token back to its original source.  This makes sure that
`_` characters in numbers are properly accounted for so that they stay
in sync after we've encountered something like 123_456_789.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-06-30 10:25:43 +01:00
eksperimental 4ceb41e71b Formmating: Add white space around vertical bar (#4507) 2016-04-25 00:55:49 +02:00
eksperimental bed9816549 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 8619d26c4d 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
Martin Frost bcb26f661b Remove unused escape_char/1 function 2016-01-01 15:30:18 +01:00
José Valim 90db34cdac Remove deprecated and outdated code 2016-01-01 12:09:26 +01:00
José Valim 7b5f4a5842 Improve error message for invalid do/do: 2015-11-20 17:30:40 +08:00
José Valim 3487d00ddb Warn when piping into functions without parens, closes #3642 2015-11-16 13:26:05 +01:00
José Valim f7654bf66a Ensure we print unicode codepoints on errors, closes #3804 2015-09-29 15:03:55 +02:00
eksperimental ed5671b4f8 Standardize use of backticks and quotes; including Error messages and Title Case commands
This is a large commit that does the following:
* Removes backticks from messages and comments.
  All references to backticks have been replaced with double quotes everywhere the
  code is not interpreted as Markdown, (ie. anywhere outside documentation and
  markdown files, such as in code comments, or error messages).

* Variables in Exception messages are printed using `inspect`
  The way no-matching error message are printed, have changed because now we use inspect for printing
  variables. The following file and their respective test have been changed:
  - lib/elixir/lib/exception.ex
  - lib/elixir/lib/inspect/algebra.ex
  - lib/elixir/test/elixir/inspect_test.exs
  - lib/ex_unit/test/ex_unit/formatter_test.exs
  - lib/elixir/test/elixir/exception_test.exs

* Properly use Title Case for Mix, Git, Dializer

* Use backticks when citing a command

****************************************************
CONVENTION FOR RENAMING USING BACKTICKS AND QUOTES

https://github.com/elixir-lang/elixir/pull/3697#issuecomment-138811747

1. Backticks should never be printed in error messages, neither be included anywhere where Markdown code is not interpreted as such.

2. Do not use single quotes anywhere. We should favor double quotes everywhere, to avoid confusion

3. If you want to format something in error messages, use inspect. For example, if you want to show the dependency name and that is an atom, instead of the dependency "foo", let's show the dependency :foo. Less noise and may click better

4. Similarly, if you want to show something with double quotes, call inspect, as it handles escaping as well as the quotes

5. Things like "--all" just add verbosity, we can definitely read --all without ambiguity.

6. When using switches with a single hyphen (such as "-o"), we can make it explicit in the text: e.g. "... give the switch -o when choosing ..."

****************************************************
SHELL COMMANDS TO DETECT CODE BREAKING THE RULES

* Detect values surrounded by single-quotes where we want double-quotes.

    # regular variables
    ag "'#{"
    # constants or ENV variables
    ag "'[A-Z][A-Z0-9_-]+"
    # switches
    ag -i "(?<!(\[))'--?[a-z0-9][a-z0-9_-]+'"
    # atoms
    ag -i "(?<!(\[))':[a-z0-9][a-z0-9_-]+'"

    # DETECT BACKTICKS OUTSIDE DOCS
    ag "^\s+(?<!(#))#[^#\r\n]*\`" --ignore "*.md"
    ag '^\s+["%].*`' --ignore "*.md"
    ag -s '(raise|Error)\b(?!(`|/)).*\`'

* Spot mentions to running a command that is not using backticks:

    commands="elixir|elixirc|mix|iex|ex_doc|git|make|rebar|dialyzer|erl|rm|cd|mkdir|rmdir|ln|ls|pwd"
    actions="runs?|running|executes?|executing|types?|typing|enters?|entering|calls?|calling"
    ag '(?i)('${actions}')(?-i)\b[^`\r\n/]+[\ \t]+(?!(`))('${commands}')'
    ag '(?-i)\b(?!(`))('${commands}')[\ \t]+[^`\r\n/]+(?i)(commands?)'

* Spot where a command is mentioned:

    #commands="erlang|elixir|eex|iex|ex_unit|ex_doc|logger|elixirc|git|make|rebar|dialyzer|erl|rm|cd|mkdir|rmdir|ln|ls|pwd"
    commands="mix|elixirc|git|make|rebar|dialyzer|erl|rm|cd|mkdir|rmdir|ln|ls|pwd"
    ag -s '(?<!(\`))(?<!(\.))(?<!(/))(?<!(:))(?<!(_))\b('${commands}')\b(?!(:))(?!(\?))(?!(_))(?!(-))(?!(\.))(?!(\`))(?!(/))(?!(>))' \
    --ignore "*.erl" --ignore "*.yrl" --ignore "*.src"
2015-09-11 18:49:51 +07:00
José Valim c838bcd3cb Improve unexpected token error messages 2015-09-01 00:32:46 +02:00
ꗈ ꘐ ꗈ b8ee8c3e73 Raise if heredic terminator in invalid location
issue #3503

This will raise:
```elixir
foo = """
this """
```

This will not:
```elixir
foo = """
this \"\"\"
"""
```
2015-08-17 12:08:38 -07:00
José Valim c2813ac1ea Also perform new line checking with structs 2015-08-16 20:47:53 +02:00
José Valim 970f84382b Allow operators to work still after comments
Closes #3316
2015-08-16 20:11:11 +02:00
José Valim 4f265b12d6 Also fail on do after , and ;
Closes #3293
2015-08-16 19:49:04 +02:00
José Valim 84830d37ef Deprecate ?\x in favor of simply 0x 2015-08-16 18:00:10 +02:00
ꗈ ꘐ ꗈ add22f4b5b capture non-symbolic operators (&and/2, &not/1, &c.)
partial fix for issue #3486
pin operator  is a different issue and will take some more investgation to find the cause.
2015-08-11 11:25:26 -07:00
José Valim d235533b45 Remove reference to dynamic operators in table 2015-07-14 09:27:44 +02:00
José Valim 91ce4a6b57 Properly offset columns on dot 2015-06-24 19:04:54 +02:00
José Valim 577fcf5d30 Use the given length instead of calculating it 2015-06-24 18:53:31 +02:00
José Valim 2d4385a622 Fix reversed Line, Column in tokenizer 2015-06-24 18:19:52 +02:00
Roger Braun 196c750e8d Ensure that a digit follows the underscore in binary, octal, hex notations. 2015-06-13 19:20:59 +02:00
Roger Braun 0598f00aef Allows underscores in binary, octal and hex literals. 2015-06-12 12:55:34 +02:00
eksperimental 61675c3ea8 Add space after comma: Format consistently 2015-03-17 22:55:27 +07:00
José Valim c28bc3be3f Use identifier instead of name
Identifier is the correct term parser/tokenizer wise.
2015-02-28 19:33:46 +01:00
Or Neeman 5eed2991c8 Improve tokenization of identifiers and k: v keys
Closes #3113:
- Fix tokenization of `a@b: ` and `A!: `
- Add error for `a@b` (previously tokenized like `a @b`)
- Extend error for `a:b` to cover `a:+`, etc.
- Unify tokenization of upper- and lower-case `k: v` keys
- Fix end-column value for `a: `
- Add tests as appropriate
2015-02-28 12:07:14 -06:00
Xavier Defrang 7381cbee02 Invert the order of non matching token messages (closes #2993) 2015-01-10 09:40:44 +01:00
Alexander Ivanov b35a683647 Fix column counting in elixir_interpolation.erl 2015-01-06 16:57:00 +02:00
Alexander Ivanov 3177e2ebd0 Count \\ as just one character in column info in tokenizer 2015-01-06 14:49:23 +02:00
Alexander Ivanov c76a186687 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 a288ddd326 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
James Brennan 827f9ad873 Allow U (upper case u) as an option for sigil_r 2014-09-14 18:23:33 -07:00
José Valim 843706e36e Add free operators
<<~, ~>>, <~, ~>, <~>, <|>
2014-09-07 12:42:10 +02:00
José Valim 172bfdb128 Revert "Merge pull request #2702 from alexrp/master"
<~ is already a valid expression in Elixir.

This reverts commit 2c741ec6ae, reversing
changes made to 12a457829f.
2014-09-07 12:12:35 +02:00
Alex Rønne Petersen c8bcd89c7c Introduce new operators intended for use by parser combinator libraries.
The expected definitions (which are by no means required) in
parser combinator speak are:

* `p  ~>> f`   =  `bind(p, f)`
* `p1 ~>  p2`  =  `pair_right(p1, p2)`
* `p1 <~  p2`  =  `pair_left(p1, p2)`
* `p1 <~> p2`  =  `pair_both(p1, p2)`
* `p  |~> f`   =  `map(p, f)`
* `1p <|> p2`  =  `either(p1, p2)`
2014-09-02 01:57:50 +02:00
Eric Meadows-Jönsson c6fa951520 Better error message on nbsp 2014-08-19 17:00:58 +02:00
José Valim e6e71675ac Make a distinction between eol and ; 2014-08-12 16:27:45 +02:00
José Valim 4d763846c3 Ensure code escape \ works in IEx 2014-08-11 10:05:24 +02:00
Aleksei Magusev c6f27541c1 Bind value to proper name in elixir_tokenizer 2014-08-10 19:41:13 +04:00
José Valim 2d9c3fb6f0 Print warnings when used ? with characters with escape codes
Closes #2640
2014-08-08 11:13:13 +02:00
José Valim 6a6ba9f50d Remove deprecated code 2014-08-02 22:35:57 +02:00
José Valim 6874eb7ce8 Deprecate octal and upcase char syntaxes 2014-07-29 20:33:42 +02:00
Yuki Ito 81ed03ffb2 Parse unary/binary operators regardless of number of spaces
closes #2534.
2014-07-26 20:03:38 +09:00
José Valim 058b157b36 Remove deprecated features and deprecate soft ones 2014-07-12 16:23:17 +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 b4415f2a14 Change precedence of & to not special case / 2014-06-28 11:16:51 +02:00