From 29b2e0adcc35834dda2884222624bfcc268a3eff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 13 Jan 2018 11:55:03 +0300 Subject: G: allow self & super in paths --- src/parser/event_parser/grammar/paths.rs | 13 ++- src/syntax_kinds.rs | 135 ++++++++++++++++--------------- 2 files changed, 80 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 108545bc2..d6887a9ba 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -1,7 +1,7 @@ use super::*; pub(crate) fn use_path(p: &mut Parser) { - if !AnyOf(&[IDENT, COLONCOLON]).is_ahead(p) { + if !AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p) { return; } let mut prev = p.mark(); @@ -23,6 +23,15 @@ fn path_segment(p: &mut Parser, first: bool) { if first { p.eat(COLONCOLON); } - p.expect(IDENT); + match p.current() { + IDENT | SELF_KW | SUPER_KW => { + p.bump(); + }, + _ => { + p.error() + .message("expected identifier") + .emit(); + } + }; }) } \ No newline at end of file diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 84f1072b7..48f55fa97 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -16,73 +16,74 @@ pub const MOD_KW: SyntaxKind = SyntaxKind(11); pub const PUB_KW: SyntaxKind = SyntaxKind(12); pub const SELF_KW: SyntaxKind = SyntaxKind(13); pub const SUPER_KW: SyntaxKind = SyntaxKind(14); -pub const ERROR: SyntaxKind = SyntaxKind(15); -pub const IDENT: SyntaxKind = SyntaxKind(16); -pub const UNDERSCORE: SyntaxKind = SyntaxKind(17); -pub const WHITESPACE: SyntaxKind = SyntaxKind(18); -pub const INT_NUMBER: SyntaxKind = SyntaxKind(19); -pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(20); -pub const SEMI: SyntaxKind = SyntaxKind(21); -pub const COMMA: SyntaxKind = SyntaxKind(22); -pub const DOT: SyntaxKind = SyntaxKind(23); -pub const DOTDOT: SyntaxKind = SyntaxKind(24); -pub const DOTDOTDOT: SyntaxKind = SyntaxKind(25); -pub const DOTDOTEQ: SyntaxKind = SyntaxKind(26); -pub const L_PAREN: SyntaxKind = SyntaxKind(27); -pub const R_PAREN: SyntaxKind = SyntaxKind(28); -pub const L_CURLY: SyntaxKind = SyntaxKind(29); -pub const R_CURLY: SyntaxKind = SyntaxKind(30); -pub const L_BRACK: SyntaxKind = SyntaxKind(31); -pub const R_BRACK: SyntaxKind = SyntaxKind(32); -pub const L_ANGLE: SyntaxKind = SyntaxKind(33); -pub const R_ANGLE: SyntaxKind = SyntaxKind(34); -pub const AT: SyntaxKind = SyntaxKind(35); -pub const POUND: SyntaxKind = SyntaxKind(36); -pub const TILDE: SyntaxKind = SyntaxKind(37); -pub const QUESTION: SyntaxKind = SyntaxKind(38); -pub const COLON: SyntaxKind = SyntaxKind(39); -pub const COLONCOLON: SyntaxKind = SyntaxKind(40); -pub const DOLLAR: SyntaxKind = SyntaxKind(41); -pub const EQ: SyntaxKind = SyntaxKind(42); -pub const EQEQ: SyntaxKind = SyntaxKind(43); -pub const FAT_ARROW: SyntaxKind = SyntaxKind(44); -pub const NEQ: SyntaxKind = SyntaxKind(45); -pub const EXCL: SyntaxKind = SyntaxKind(46); -pub const LIFETIME: SyntaxKind = SyntaxKind(47); -pub const CHAR: SyntaxKind = SyntaxKind(48); -pub const BYTE: SyntaxKind = SyntaxKind(49); -pub const STRING: SyntaxKind = SyntaxKind(50); -pub const RAW_STRING: SyntaxKind = SyntaxKind(51); -pub const BYTE_STRING: SyntaxKind = SyntaxKind(52); -pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(53); -pub const PLUS: SyntaxKind = SyntaxKind(54); -pub const MINUS: SyntaxKind = SyntaxKind(55); -pub const STAR: SyntaxKind = SyntaxKind(56); -pub const SLASH: SyntaxKind = SyntaxKind(57); -pub const CARET: SyntaxKind = SyntaxKind(58); -pub const PERCENT: SyntaxKind = SyntaxKind(59); -pub const AMPERSAND: SyntaxKind = SyntaxKind(60); -pub const PIPE: SyntaxKind = SyntaxKind(61); -pub const THIN_ARROW: SyntaxKind = SyntaxKind(62); -pub const COMMENT: SyntaxKind = SyntaxKind(63); -pub const DOC_COMMENT: SyntaxKind = SyntaxKind(64); -pub const SHEBANG: SyntaxKind = SyntaxKind(65); -pub const FILE: SyntaxKind = SyntaxKind(66); -pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(67); -pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(68); -pub const FN_ITEM: SyntaxKind = SyntaxKind(69); -pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(70); -pub const ATTR: SyntaxKind = SyntaxKind(71); -pub const META_ITEM: SyntaxKind = SyntaxKind(72); -pub const MOD_ITEM: SyntaxKind = SyntaxKind(73); -pub const USE_ITEM: SyntaxKind = SyntaxKind(74); -pub const PATH: SyntaxKind = SyntaxKind(75); -pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(76); -pub const LITERAL: SyntaxKind = SyntaxKind(77); -pub const ALIAS: SyntaxKind = SyntaxKind(78); -pub const VISIBILITY: SyntaxKind = SyntaxKind(79); +pub const IN_KW: SyntaxKind = SyntaxKind(15); +pub const ERROR: SyntaxKind = SyntaxKind(16); +pub const IDENT: SyntaxKind = SyntaxKind(17); +pub const UNDERSCORE: SyntaxKind = SyntaxKind(18); +pub const WHITESPACE: SyntaxKind = SyntaxKind(19); +pub const INT_NUMBER: SyntaxKind = SyntaxKind(20); +pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(21); +pub const SEMI: SyntaxKind = SyntaxKind(22); +pub const COMMA: SyntaxKind = SyntaxKind(23); +pub const DOT: SyntaxKind = SyntaxKind(24); +pub const DOTDOT: SyntaxKind = SyntaxKind(25); +pub const DOTDOTDOT: SyntaxKind = SyntaxKind(26); +pub const DOTDOTEQ: SyntaxKind = SyntaxKind(27); +pub const L_PAREN: SyntaxKind = SyntaxKind(28); +pub const R_PAREN: SyntaxKind = SyntaxKind(29); +pub const L_CURLY: SyntaxKind = SyntaxKind(30); +pub const R_CURLY: SyntaxKind = SyntaxKind(31); +pub const L_BRACK: SyntaxKind = SyntaxKind(32); +pub const R_BRACK: SyntaxKind = SyntaxKind(33); +pub const L_ANGLE: SyntaxKind = SyntaxKind(34); +pub const R_ANGLE: SyntaxKind = SyntaxKind(35); +pub const AT: SyntaxKind = SyntaxKind(36); +pub const POUND: SyntaxKind = SyntaxKind(37); +pub const TILDE: SyntaxKind = SyntaxKind(38); +pub const QUESTION: SyntaxKind = SyntaxKind(39); +pub const COLON: SyntaxKind = SyntaxKind(40); +pub const COLONCOLON: SyntaxKind = SyntaxKind(41); +pub const DOLLAR: SyntaxKind = SyntaxKind(42); +pub const EQ: SyntaxKind = SyntaxKind(43); +pub const EQEQ: SyntaxKind = SyntaxKind(44); +pub const FAT_ARROW: SyntaxKind = SyntaxKind(45); +pub const NEQ: SyntaxKind = SyntaxKind(46); +pub const EXCL: SyntaxKind = SyntaxKind(47); +pub const LIFETIME: SyntaxKind = SyntaxKind(48); +pub const CHAR: SyntaxKind = SyntaxKind(49); +pub const BYTE: SyntaxKind = SyntaxKind(50); +pub const STRING: SyntaxKind = SyntaxKind(51); +pub const RAW_STRING: SyntaxKind = SyntaxKind(52); +pub const BYTE_STRING: SyntaxKind = SyntaxKind(53); +pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(54); +pub const PLUS: SyntaxKind = SyntaxKind(55); +pub const MINUS: SyntaxKind = SyntaxKind(56); +pub const STAR: SyntaxKind = SyntaxKind(57); +pub const SLASH: SyntaxKind = SyntaxKind(58); +pub const CARET: SyntaxKind = SyntaxKind(59); +pub const PERCENT: SyntaxKind = SyntaxKind(60); +pub const AMPERSAND: SyntaxKind = SyntaxKind(61); +pub const PIPE: SyntaxKind = SyntaxKind(62); +pub const THIN_ARROW: SyntaxKind = SyntaxKind(63); +pub const COMMENT: SyntaxKind = SyntaxKind(64); +pub const DOC_COMMENT: SyntaxKind = SyntaxKind(65); +pub const SHEBANG: SyntaxKind = SyntaxKind(66); +pub const FILE: SyntaxKind = SyntaxKind(67); +pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(68); +pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(69); +pub const FN_ITEM: SyntaxKind = SyntaxKind(70); +pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(71); +pub const ATTR: SyntaxKind = SyntaxKind(72); +pub const META_ITEM: SyntaxKind = SyntaxKind(73); +pub const MOD_ITEM: SyntaxKind = SyntaxKind(74); +pub const USE_ITEM: SyntaxKind = SyntaxKind(75); +pub const PATH: SyntaxKind = SyntaxKind(76); +pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(77); +pub const LITERAL: SyntaxKind = SyntaxKind(78); +pub const ALIAS: SyntaxKind = SyntaxKind(79); +pub const VISIBILITY: SyntaxKind = SyntaxKind(80); -static INFOS: [SyntaxInfo; 80] = [ +static INFOS: [SyntaxInfo; 81] = [ SyntaxInfo { name: "USE_KW" }, SyntaxInfo { name: "FN_KW" }, SyntaxInfo { name: "STRUCT_KW" }, @@ -98,6 +99,7 @@ static INFOS: [SyntaxInfo; 80] = [ SyntaxInfo { name: "PUB_KW" }, SyntaxInfo { name: "SELF_KW" }, SyntaxInfo { name: "SUPER_KW" }, + SyntaxInfo { name: "IN_KW" }, SyntaxInfo { name: "ERROR" }, SyntaxInfo { name: "IDENT" }, SyntaxInfo { name: "UNDERSCORE" }, @@ -186,6 +188,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option { "pub" => Some(PUB_KW), "self" => Some(SELF_KW), "super" => Some(SUPER_KW), + "in" => Some(IN_KW), _ => None, } } -- cgit v1.2.3