Commit Graph

350 Commits

Author SHA1 Message Date
Aleksey Kladov
30fa99e5b8 move constructors to top 2019-07-04 09:08:45 +03:00
Aleksey Kladov
601bad86b2 cleanup lexer constructors 2019-07-04 09:08:45 +03:00
Aleksey Kladov
256df83f64 remove peek_span_src_raw from StringReader 2019-07-04 09:08:39 +03:00
Aleksey Kladov
e9dc95c86e remove peek_token from StringReader 2019-07-04 09:01:37 +03:00
Aleksey Kladov
830ff4a592 remove StringReader::peek
The reader itself doesn't need ability to peek tokens, so it's better
if clients implement this functionality.

This hopefully becomes especially easy once we use iterator interface
for lexer, but this is not too easy at the moment, because of buffered
errors.
2019-07-04 09:01:37 +03:00
Mazdak Farrokhzad
c0ec567214 Rollup merge of #62297 - matklad:peek-delimited, r=petrochenkov
refactor check_for_substitution

No behavior change, just flatter and simpler code.

r? @petrochenkov
2019-07-04 01:38:55 +02:00
Aleksey Kladov
dc088b26ce refactor check_for_substitution
No behavior change, just flatter and simpler code
2019-07-02 11:16:33 +03:00
Aleksey Kladov
57db25e614 cleanup: rename name_from to symbol_from
Lexer uses Symbols for a lot of stuff, not only for identifiers, so
the "name" terminology is just confusing.
2019-06-25 22:30:21 +03:00
Aleksey Kladov
b75021b31e refactor lexer to use idiomatic borrowing 2019-06-25 21:02:19 +03:00
Mazdak Farrokhzad
d551880267 let_chains: Inline visit_expr_with_let_maybe_allowed. 2019-06-23 01:29:29 +02:00
bors
3f511ade5b Auto merge of #60669 - c410-f3r:attrs-fn, r=petrochenkov
Allow attributes in formal function parameters

Implements https://github.com/rust-lang/rust/issues/60406.

This is my first contribution to the compiler and since this is a large and complex project, I am not fully aware of the consequences of the changes I have made.

**TODO**

- [x] Forbid some built-in attributes.
- [x] Expand cfg/cfg_attr
2019-06-12 07:38:01 +00:00
bors
5e2c11034f Auto merge of #60793 - Xanewok:raw-string-cleanup, r=petrochenkov
lexer: Disallow bare CR in raw byte strings

Handles bare CR ~but doesn't translate `\r\n` to `\n` yet in raw strings yet~ and translates CRLF to LF in raw strings.

As a side-note I think it'd be good to change the `unescape_` to return plain iterators to reduce some boilerplate (e.g. `has_error` could benefit from collecting `Result<T>` and aborting early on errors) but will do that separately, unless I missed something here that prevents it.

@matklad @petrochenkov thoughts?
2019-06-10 23:32:12 +00:00
Igor Matuszewski
735ac057bb Actually translate CRLF in raw byte strings and unify unescape impl 2019-06-09 15:14:55 +02:00
Igor Matuszewski
3c1d352dc4 Add a doc comment for scan_raw_string 2019-06-09 14:20:29 +02:00
Caio
1eaaf440d5 Allow attributes in formal function parameters 2019-06-09 07:58:40 -03:00
Igor Matuszewski
d4632744fa Translate CRLF -> LF in raw (byte) strings 2019-06-09 00:33:21 +02:00
Igor Matuszewski
49d62e8d5a Prohibit bare CRs in raw byte strings 2019-06-08 22:58:53 +02:00
Igor Matuszewski
cab7e7fe76 Validate and transcribe raw strings via unescape module 2019-06-08 22:58:53 +02:00
Vadim Petrochenkov
0ca3c2f881 syntax: Move most of the TokenKind methods to Token 2019-06-08 22:38:12 +03:00
Igor Matuszewski
08ede49dcb Remove redundant, commented out code
It was commented out as part of
8a8e497ae7.
Done probably by accident, since the code in question was moved to a
match arm, along with newly introduced logic to detect bare CRs in raw
strings.
2019-06-08 20:05:02 +02:00
Igor Matuszewski
b8e3533b73 Separate a scan_raw_string (similar raw_byte variant) 2019-06-08 20:05:02 +02:00
Igor Matuszewski
5b17a5e30a Clean up minor bits 2019-06-08 20:05:02 +02:00
Vadim Petrochenkov
f745e5f9b6 syntax: Remove duplicate span from token::Ident 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
4c5d773b4d syntax: Remove duplicate span from token::Lifetime 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
5e693531ff syntax: Add some helper methods to Token 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
c0c57acd7b syntax: Use Token in StringReader and TokenTreesReader 2019-06-06 14:03:15 +03:00
Vadim Petrochenkov
e0127dbf81 syntax: Use Token in TokenTree::Token 2019-06-06 14:03:15 +03:00
Vadim Petrochenkov
a3425edb46 syntax: Rename TokenAndSpan into Token 2019-06-06 14:03:15 +03:00
Vadim Petrochenkov
99b27d749c syntax: Rename Token into TokenKind 2019-06-06 14:03:14 +03:00
Nicholas Nethercote
9c7d28d4fd Pre-intern "0", "1", ..., "9", and use where appropriate. 2019-05-27 13:58:38 +10:00
Vadim Petrochenkov
ca2a50fad7 syntax: Turn token::Lit into a struct 2019-05-23 12:46:24 +03:00
John Kåre Alsaker
a1f2dceaeb Move edition outside the hygiene lock and avoid accessing it 2019-05-21 18:17:05 +02:00
bors
024c25dc79 Auto merge of #60763 - matklad:tt-parser, r=petrochenkov
Move token tree related lexer state to a separate struct

Just a types-based refactoring.

We only used a bunch of fields when tokenizing into a token tree, so let's move them out of the base lexer
2019-05-16 04:15:12 +00:00
Aleksey Kladov
b91e0a3786 move span and token to tt reader 2019-05-13 14:54:34 +03:00
Aleksey Kladov
d29f0d23c3 Move token tree related lexer state to a separate struct
We only used a bunch of fields when tokenizing into a token tree,
so let's move them out of the base lexer
2019-05-13 14:54:34 +03:00
Vadim Petrochenkov
3f064cae3d Move literal parsing code into a separate file
Remove some dead code
2019-05-11 16:03:16 +03:00
Mazdak Farrokhzad
39edc68c69 Rollup merge of #60188 - estebank:recover-block, r=varkor
Identify when a stmt could have been parsed as an expr

There are some expressions that can be parsed as a statement without
a trailing semicolon depending on the context, which can lead to
confusing errors due to the same looking code being accepted in some
places and not others. Identify these cases and suggest enclosing in
parenthesis making the parse non-ambiguous without changing the
accepted grammar.

Fix #54186, cc #54482, fix #59975, fix #47287.
2019-05-09 23:56:09 +02:00
Esteban Küber
54430ad53a review comments: fix typo and add comments 2019-05-06 16:00:21 -07:00
Aleksey Kladov
bfa5f27847 introduce unescape module
Currently, we deal with escape sequences twice: once when we lex a
string, and a second time when we unescape literals. This PR aims to
remove this duplication, by introducing a new `unescape` mode as a
single source of truth for character escaping rules
2019-05-02 15:31:57 +03:00
Esteban Küber
f007e6f442 Identify when a stmt could have been parsed as an expr
There are some expressions that can be parsed as a statement without
a trailing semicolon depending on the context, which can lead to
confusing errors due to the same looking code being accepted in some
places and not others. Identify these cases and suggest enclosing in
parenthesis making the parse non-ambiguous without changing the
accepted grammar.
2019-04-29 14:07:02 -07:00
Aleksey Kladov
28ce23fe8b simplify and avoid allocation 2019-04-23 00:05:06 +03:00
Aleksey Kladov
c29a98e40d remove obsolete and incorrect comment 2019-04-23 00:03:57 +03:00
bors
4530c528ba Auto merge of #59700 - matklad:simplify, r=eddyb
Simplify doc comment lexing

is_doc_comment function checks the first four chars, but this is
redundant, `doc_comment` local var has the same info.
2019-04-20 17:59:15 +00:00
Mazdak Farrokhzad
c89bc54d4f Rollup merge of #59128 - oli-obk:colorful_json, r=mark-i-m,eddyb
Emit ansi color codes in the `rendered` field of json diagnostics

cc @ljedrz

Implemented for https://github.com/rust-lang/rust/pull/56595#issuecomment-447645115 (x.py clippy)
2019-04-17 10:31:30 +02:00
Mazdak Farrokhzad
2e7be1ed6c Rollup merge of #59687 - matklad:shebang, r=petrochenkov
cleanup shebang handling in the lexer
2019-04-05 12:46:49 +02:00
Aleksey Kladov
606e0aff81 Simplify doc comment lexing
is_doc_comment function checks the first four chars, but this is
redundant, `doc_comment` local var has the same info.
2019-04-04 19:51:13 +03:00
Aleksey Kladov
fdb8752850 cleanup shebang handling in the lexer 2019-04-04 13:31:53 +03:00
Aleksey Kladov
1763aea7ba make StringReader methods private 2019-04-03 18:33:54 +03:00
Aleksey Kladov
555309d933 make StringReader fields private 2019-04-03 18:20:50 +03:00
Oliver Scherer
0a842e8c7a Update more unit test to new API 2019-04-02 16:14:59 +02:00