This commit is contained in:
Aleksey Kladov 2018-08-13 17:42:43 +03:00
parent 5a56ac4b72
commit d1eceefeb8
7 changed files with 111 additions and 1 deletions

View file

@ -14,3 +14,4 @@ smol_str = { path = "../smol_str" }
[dev-dependencies] [dev-dependencies]
assert_eq_text = { path = "../assert_eq_text" } assert_eq_text = { path = "../assert_eq_text" }
walkdir = "2.2.0"

View file

@ -55,6 +55,7 @@ Grammar(
"enum", "enum",
"trait", "trait",
"impl", "impl",
"dyn",
"true", "true",
"false", "false",
"as", "as",
@ -134,6 +135,7 @@ Grammar(
"FN_POINTER_TYPE", "FN_POINTER_TYPE",
"FOR_TYPE", "FOR_TYPE",
"IMPL_TRAIT_TYPE", "IMPL_TRAIT_TYPE",
"DYN_TRAIT_TYPE",
"REF_PAT", "REF_PAT",
"BIND_PAT", "BIND_PAT",

View file

@ -11,9 +11,10 @@ pub(super) fn type_(p: &mut Parser) {
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
FOR_KW => for_type(p), FOR_KW => for_type(p),
IMPL_KW => impl_trait_type(p), IMPL_KW => impl_trait_type(p),
DYN_KW => dyn_trait_type(p),
_ if paths::is_path_start(p) => path_type(p), _ if paths::is_path_start(p) => path_type(p),
_ => { _ => {
p.error("expected type"); p.err_and_bump("expected type");
} }
} }
} }
@ -194,6 +195,16 @@ fn impl_trait_type(p: &mut Parser) {
m.complete(p, IMPL_TRAIT_TYPE); m.complete(p, IMPL_TRAIT_TYPE);
} }
// test dyn_trait_type
// type A = dyn Iterator<Item=Foo<'a>> + 'a;
fn dyn_trait_type(p: &mut Parser) {
assert!(p.at(DYN_KW));
let m = p.start();
p.bump();
type_params::bounds_without_colon(p);
m.complete(p, DYN_TRAIT_TYPE);
}
// test path_type // test path_type
// type A = Foo; // type A = Foo;
// type B = ::Foo; // type B = ::Foo;

View file

@ -62,6 +62,7 @@ pub enum SyntaxKind {
ENUM_KW, ENUM_KW,
TRAIT_KW, TRAIT_KW,
IMPL_KW, IMPL_KW,
DYN_KW,
TRUE_KW, TRUE_KW,
FALSE_KW, FALSE_KW,
AS_KW, AS_KW,
@ -133,6 +134,7 @@ pub enum SyntaxKind {
FN_POINTER_TYPE, FN_POINTER_TYPE,
FOR_TYPE, FOR_TYPE,
IMPL_TRAIT_TYPE, IMPL_TRAIT_TYPE,
DYN_TRAIT_TYPE,
REF_PAT, REF_PAT,
BIND_PAT, BIND_PAT,
PLACEHOLDER_PAT, PLACEHOLDER_PAT,
@ -210,6 +212,7 @@ impl SyntaxKind {
| ENUM_KW | ENUM_KW
| TRAIT_KW | TRAIT_KW
| IMPL_KW | IMPL_KW
| DYN_KW
| TRUE_KW | TRUE_KW
| FALSE_KW | FALSE_KW
| AS_KW | AS_KW
@ -297,6 +300,7 @@ impl SyntaxKind {
ENUM_KW => &SyntaxInfo { name: "ENUM_KW" }, ENUM_KW => &SyntaxInfo { name: "ENUM_KW" },
TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" }, TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" },
IMPL_KW => &SyntaxInfo { name: "IMPL_KW" }, IMPL_KW => &SyntaxInfo { name: "IMPL_KW" },
DYN_KW => &SyntaxInfo { name: "DYN_KW" },
TRUE_KW => &SyntaxInfo { name: "TRUE_KW" }, TRUE_KW => &SyntaxInfo { name: "TRUE_KW" },
FALSE_KW => &SyntaxInfo { name: "FALSE_KW" }, FALSE_KW => &SyntaxInfo { name: "FALSE_KW" },
AS_KW => &SyntaxInfo { name: "AS_KW" }, AS_KW => &SyntaxInfo { name: "AS_KW" },
@ -368,6 +372,7 @@ impl SyntaxKind {
FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" },
FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" },
IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" },
DYN_TRAIT_TYPE => &SyntaxInfo { name: "DYN_TRAIT_TYPE" },
REF_PAT => &SyntaxInfo { name: "REF_PAT" }, REF_PAT => &SyntaxInfo { name: "REF_PAT" },
BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, BIND_PAT => &SyntaxInfo { name: "BIND_PAT" },
PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" },
@ -445,6 +450,7 @@ impl SyntaxKind {
"enum" => ENUM_KW, "enum" => ENUM_KW,
"trait" => TRAIT_KW, "trait" => TRAIT_KW,
"impl" => IMPL_KW, "impl" => IMPL_KW,
"dyn" => DYN_KW,
"true" => TRUE_KW, "true" => TRUE_KW,
"false" => FALSE_KW, "false" => FALSE_KW,
"as" => AS_KW, "as" => AS_KW,

View file

@ -0,0 +1,7 @@
pub struct Cache(
RefCell<HashMap<
TypeId,
Box<@ Any>,
>>
);

View file

@ -0,0 +1,82 @@
FILE@[0; 86)
STRUCT@[0; 84)
VISIBILITY@[0; 3)
PUB_KW@[0; 3)
WHITESPACE@[3; 4)
STRUCT_KW@[4; 10)
WHITESPACE@[10; 11)
NAME@[11; 16)
IDENT@[11; 16) "Cache"
L_PAREN@[16; 17)
WHITESPACE@[17; 22)
POS_FIELD@[22; 68)
PATH_TYPE@[22; 68)
PATH@[22; 68)
PATH_SEGMENT@[22; 68)
NAME_REF@[22; 29)
IDENT@[22; 29) "RefCell"
TYPE_ARG_LIST@[29; 68)
L_ANGLE@[29; 30)
TYPE_ARG@[30; 68)
PATH_TYPE@[30; 68)
PATH@[30; 68)
PATH_SEGMENT@[30; 68)
NAME_REF@[30; 37)
IDENT@[30; 37) "HashMap"
TYPE_ARG_LIST@[37; 68)
L_ANGLE@[37; 38)
WHITESPACE@[38; 47)
TYPE_ARG@[47; 53)
PATH_TYPE@[47; 53)
PATH@[47; 53)
PATH_SEGMENT@[47; 53)
NAME_REF@[47; 53)
IDENT@[47; 53) "TypeId"
COMMA@[53; 54)
WHITESPACE@[54; 63)
TYPE_ARG@[63; 68)
PATH_TYPE@[63; 68)
PATH@[63; 68)
PATH_SEGMENT@[63; 68)
NAME_REF@[63; 66)
IDENT@[63; 66) "Box"
TYPE_ARG_LIST@[66; 68)
L_ANGLE@[66; 67)
err: `expected type`
TYPE_ARG@[67; 68)
ERROR@[67; 68)
AT@[67; 68)
err: `expected COMMA`
err: `expected R_ANGLE`
err: `expected COMMA`
err: `expected R_ANGLE`
err: `expected COMMA`
err: `expected R_ANGLE`
err: `expected COMMA`
WHITESPACE@[68; 69)
POS_FIELD@[69; 72)
PATH_TYPE@[69; 72)
PATH@[69; 72)
PATH_SEGMENT@[69; 72)
NAME_REF@[69; 72)
IDENT@[69; 72) "Any"
err: `expected COMMA`
err: `expected type`
POS_FIELD@[72; 73)
ERROR@[72; 73)
R_ANGLE@[72; 73)
COMMA@[73; 74)
WHITESPACE@[74; 79)
err: `expected type`
POS_FIELD@[79; 80)
ERROR@[79; 80)
R_ANGLE@[79; 80)
err: `expected COMMA`
err: `expected type`
POS_FIELD@[80; 81)
ERROR@[80; 81)
R_ANGLE@[80; 81)
WHITESPACE@[81; 82)
R_PAREN@[82; 83)
SEMI@[83; 84)
WHITESPACE@[84; 86)

View file

@ -1,6 +1,7 @@
extern crate libsyntax2; extern crate libsyntax2;
#[macro_use] #[macro_use]
extern crate assert_eq_text; extern crate assert_eq_text;
extern crate walkdir;
use std::{ use std::{
fs, fs,