42 Commits

Author SHA1 Message Date
Russell Cohen
a93d31603f Fix bug in shebang handling
Shebang handling was too agressive in stripping out the first line in cases where it is actually _not_ a shebang, but instead, valid rust (#70528). This is a second attempt at resolving this issue (the first attempt was flawed, for, among other reasons, causing an ICE in certain cases (#71372, #71471).

The behavior is now codified by a number of UI tests, but simply:
For the first line to be a shebang, the following must all be true:
1. The line must start with `#!`
2. The line must contain a non whitespace character after `#!`
3. The next character in the file, ignoring comments & whitespace must not be `[`

I believe this is a strict superset of what we used to allow, so perhaps a crater run is unnecessary, but probably not a terrible idea.
2020-05-25 10:11:08 -04:00
Julian Wollersberger
43ae785454 Replace some usages of the old unescape_ functions in AST, clippy and tests. 2020-05-13 10:05:04 +02:00
Julian Wollersberger
1be5d1eabb Unified unescape_{char,byte,str,byte_str,raw_str,raw_byte_str} methods into one method unescape_literal with a mode argument. 2020-05-13 09:42:30 +02:00
Julian Wollersberger
e734e31340 Small doc improvements.
The phrasing is from the commit description of 395ee0b79f23b90593b01dd0a78451b8c93b0aa6 by @Matklad.
2020-05-09 13:46:03 +02:00
Eduard-Mihai Burtescu
4d67c8da55 Revert "Rollup merge of #71372 - ayushmishra2005:shebang_stripping, r=estebank"
This reverts commit 46a8dcef5c9e4de0d412c6ac3c4765cb4aef4f7f, reversing
changes made to f28e3873c55eb4bdcfc496e1f300b97aeb0d189c.
2020-04-28 13:02:58 +03:00
Ayush Kumar Mishra
1b362cd1d5 Minor refactoring 2020-04-21 22:29:20 +05:30
Ayush Kumar Mishra
365b3cc781 Fix formatting issue 2020-04-21 17:06:22 +05:30
Ayush Kumar Mishra
ee5a2120f9 Refactoring and added test-cases #70528 2020-04-21 16:48:58 +05:30
Ayush Kumar Mishra
0315864260 Fix #! (shebang) stripping account space issue #70528 2020-04-21 11:44:00 +05:30
Russell Cohen
f543689eb6 Handle unterminated raw strings with no #s properly
The modified code to handle parsing raw strings didn't properly account for the case where there was no "#" on either end and erroneously reported this strings as complete. This lead to a panic trying to read off the end of the file.
2020-04-02 01:02:55 -04:00
Russell Cohen
55a5eea763 Fix tests to handle debug_assert 2020-03-31 10:27:07 -04:00
Russell Cohen
20e21902bb Clean up redudant conditions and match exprs 2020-03-30 12:39:40 -04:00
Russell Cohen
c15f86b4b3 Cleanup error messages, improve docstrings 2020-03-29 11:12:48 -04:00
Russell Cohen
629e97a5a0 Improve error messages for raw strings (#60762)
This diff improves error messages around raw strings in a few ways:
- Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test)
- Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings
- Detect potentially intended terminators (longest sequence of "#*" is suggested)
2020-03-29 00:43:43 -04:00
Matthias Krüger
ad00e91887 remove redundant returns (clippy::needless_return) 2020-03-20 20:23:03 +01:00
Matthias Krüger
136ad015b6 fix various typos 2020-03-06 15:19:31 +01:00
Drew Ripberger
026dec5500
Spelling error "represening" to "representing" 2020-02-13 11:14:21 -05:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad
4ae2728fa8 move syntax::parse -> librustc_parse
also move MACRO_ARGUMENTS -> librustc_parse
2019-11-10 03:57:18 +01:00
Igor Aleksanov
31735b02c9 librustc_lexer: Make nth_char method private 2019-11-04 06:27:25 +03:00
Igor Aleksanov
e8b8d2a725 librustc_lexer: Reorder imports in lib.rs 2019-11-04 06:27:25 +03:00
Igor Aleksanov
ecd26739d4 librustc_lexer: Simplify "lifetime_or_char" method 2019-11-04 06:27:18 +03:00
Igor Aleksanov
6e350bd999 librustc_lexer: Simplify "raw_double_quoted_string" method 2019-11-03 12:55:50 +03:00
Igor Aleksanov
d6f722d79c librustc_lexer: Simplify "double_quoted_string" method 2019-11-03 12:55:05 +03:00
Igor Aleksanov
649a5247f5 librustc_lexer: Simplify "single_quoted_string" method 2019-11-03 12:54:23 +03:00
Igor Aleksanov
e0c45f7ee7 librustc_lexer: Make "eat_float_exponent" return bool instead of result 2019-11-03 11:43:47 +03:00
Igor Aleksanov
72767a8056 librustc_lexer: Introduce "eat_while" and "eat_identifier" methods 2019-11-03 11:42:08 +03:00
Igor Aleksanov
0825b357d8 librustc_lexer: Add methods "first" and "second" to the "Cursor" 2019-11-03 11:39:39 +03:00
Igor Aleksanov
993b920032 librustc_lexer: Enhance documentation
Apply review suggestions

Apply review suggestions
2019-10-27 20:08:08 +03:00
Aleksey Kladov
060fe88610 fill metadata in rustc_lexer's Cargo.toml
We publish this to crates.io, so having non-empty meta is useful
2019-09-05 23:03:50 +03:00
Aleksey Kladov
206fe8e1c3 flatten rustc_lexer::character_properties module
On the call site, `rustc_lexer::is_whitespace` reads much better than
`character_properties::is_whitespace`.
2019-09-04 15:13:29 +03:00
Aleksey Kladov
a0c186c34f remove XID and Pattern_White_Space unicode tables from libcore
They are only used by rustc_lexer, and are not needed elsewhere.

So we move the relevant definitions into rustc_lexer (while the actual
unicode data comes from the unicode-xid crate) and make the rest of
the compiler use it.
2019-09-04 13:11:11 +03:00
Aleksey Kladov
8b932dfda7 remove composite tokens support from the lexer 2019-08-19 21:59:09 +03:00
Aleksey Kladov
911398b96c remove special handling of \r\n from the lexer 2019-08-14 16:38:40 +03:00
Vadim Petrochenkov
36d8f86924 librustc_lexer: Unconfigure tests during normal build 2019-08-02 01:59:01 +03:00
topecongiro
98f29f5e38
Add comment 2019-07-27 22:10:09 +09:00
topecongiro
13b41000ea
Add lib section to rustc_lexer's Cargo.toml 2019-07-27 17:21:42 +09:00
Mark Rousskov
f11ffd3a6a
Rollup merge of #62869 - matklad:feature-gate, r=Mark-Simulacrum
add rustc_private as a proper language feature gate

At the moment, `rustc_private` as a (library) feature exists by
accident: `char::is_xid_start`, `char::is_xid_continue` methods in
libcore define it.

cc https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/How.20to.20declare.20new.20langauge.20feature.3F

I don't know if this is at all reasonable, but at least tests seem to pass locally. That probably means that we can remove/rename to something more resonable the feature in libcore in the next release?
2019-07-23 12:51:18 -04:00
Aleksey Kladov
7e612c19be
Update src/librustc_lexer/src/lib.rs
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-07-23 10:38:18 +03:00
Aleksey Kladov
27b703dd40 add rustc_private as a proper language feature gate
At the moment, `rustc_private` as a (library) feature exists by
accident: `char::is_xid_start`, `char::is_xid_continue` methods in
libcore define it.
2019-07-22 16:32:13 +03:00
Aleksey Kladov
e63fe150bf move unescape module to rustc_lexer 2019-07-21 16:46:11 +03:00
Aleksey Kladov
395ee0b79f Introduce rustc_lexer
The idea here is to make a reusable library out of the existing
rust-lexer, by separating out pure lexing and rustc-specific concerns,
like spans, error reporting an interning.

So, rustc_lexer operates directly on `&str`, produces simple tokens
which are a pair of type-tag and a bit of original text, and does not
report errors, instead storing them as flags on the token.
2019-07-20 21:12:34 +03:00