aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-03 22:51:17 +0000
committerGitHub <[email protected]>2020-02-03 22:51:17 +0000
commit918547dbe9a2907401102eba491ac25cebe1404d (patch)
treee0aa3bdcec597e81f022ac1ce388d42724a92f51 /crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt
parentb090ee5a65f9630146c2842bc51fcfcc8da08da1 (diff)
parenta3e5663ae0206270156fbeb926a174a40abbddb0 (diff)
Merge #2911
2911: Implement collecting errors while tokenizing r=matklad a=Veetaha Now we are collecting errors from `rustc_lexer` and returning them in `ParsedToken { token, error }` and `ParsedTokens { tokens, errors }` structures **([UPD]: this is now simplified, see updates bellow)**. The main changes are introduced in `ra_syntax/parsing/lexer.rs`. It now exposes the following functions and types: ```rust pub fn tokenize(text: &str) -> ParsedTokens; pub fn tokenize_append(text: &str, parsed_tokens_to_append_to: &mut ParsedTokens); pub fn first_token(text: &str) -> Option<ParsedToken>; // allows any number of tokens in text pub fn single_token(text: &str) -> Option<ParsedToken>; // allows only a single token in text pub struct ParsedToken { pub token: Token, pub error: Option<SyntaxError> } pub struct ParsedTokens { pub tokens: Vec<Token>, pub errors: Vec<SyntaxError> } pub enum TokenizeError { /* Simple enum which reflects rustc_lexer tokenization errors */ } ``` In the first commit I implemented it with iterators, but then decided that since this crate is ad hoc for `rust-analyzer` and we clearly see the places of its usage it would be better to simplify it to vectors. This is currently WIP, because I want to add tests for error messages generated by the lexer. I'd like to listen to you thoughts how to define these tests in `ra_syntax/test-data` dir. Related issues: #223 **[UPD]** After the PR review the API was simplified: ```rust pub fn tokenize(text: &str) -> (Vec<Token>, Vec<SyntaxError>); // Both lex functions do not check for unescape errors pub fn lex_single_syntax_kind(text: &str) -> Option<(SyntaxKind, Option<SyntaxError>)>; pub fn lex_single_valid_syntax_kind(text: &str) -> Option<SyntaxKind>; // This will be removed in the next PR in favour of simlifying `SyntaxError` to `(String, TextRange)` pub enum TokenizeError { /* Simple enum which reflects rustc_lexer tokenization errors */ } // this is private, but may be made public if such demand would exist in future (least privilege principle) fn lex_first_token(text: &str) -> Option<(Token, Option<SyntaxError>)>; ``` Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt')
-rw-r--r--crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt64
1 files changed, 64 insertions, 0 deletions
diff --git a/crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt b/crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt
new file mode 100644
index 000000000..22c00eefb
--- /dev/null
+++ b/crates/ra_syntax/test_data/lexer/ok/0011_keywords.txt
@@ -0,0 +1,64 @@
1ASYNC_KW 5 "async"
2WHITESPACE 1 " "
3FN_KW 2 "fn"
4WHITESPACE 1 " "
5USE_KW 3 "use"
6WHITESPACE 1 " "
7STRUCT_KW 6 "struct"
8WHITESPACE 1 " "
9TRAIT_KW 5 "trait"
10WHITESPACE 1 " "
11ENUM_KW 4 "enum"
12WHITESPACE 1 " "
13IMPL_KW 4 "impl"
14WHITESPACE 1 " "
15TRUE_KW 4 "true"
16WHITESPACE 1 " "
17FALSE_KW 5 "false"
18WHITESPACE 1 " "
19AS_KW 2 "as"
20WHITESPACE 1 " "
21EXTERN_KW 6 "extern"
22WHITESPACE 1 " "
23CRATE_KW 5 "crate"
24WHITESPACE 1 "\n"
25MOD_KW 3 "mod"
26WHITESPACE 1 " "
27PUB_KW 3 "pub"
28WHITESPACE 1 " "
29SELF_KW 4 "self"
30WHITESPACE 1 " "
31SUPER_KW 5 "super"
32WHITESPACE 1 " "
33IN_KW 2 "in"
34WHITESPACE 1 " "
35WHERE_KW 5 "where"
36WHITESPACE 1 " "
37FOR_KW 3 "for"
38WHITESPACE 1 " "
39LOOP_KW 4 "loop"
40WHITESPACE 1 " "
41WHILE_KW 5 "while"
42WHITESPACE 1 " "
43IF_KW 2 "if"
44WHITESPACE 1 " "
45MATCH_KW 5 "match"
46WHITESPACE 1 " "
47CONST_KW 5 "const"
48WHITESPACE 1 "\n"
49STATIC_KW 6 "static"
50WHITESPACE 1 " "
51MUT_KW 3 "mut"
52WHITESPACE 1 " "
53TYPE_KW 4 "type"
54WHITESPACE 1 " "
55REF_KW 3 "ref"
56WHITESPACE 1 " "
57LET_KW 3 "let"
58WHITESPACE 1 " "
59ELSE_KW 4 "else"
60WHITESPACE 1 " "
61MOVE_KW 4 "move"
62WHITESPACE 1 " "
63RETURN_KW 6 "return"
64WHITESPACE 1 "\n"