From c111a1f7b8b9da2b4691c792e1658b2888ff5420 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 12 Jan 2018 20:59:19 +0300 Subject: [PATCH] Nest paths --- src/parser/event_parser/grammar/mod.rs | 2 +- src/parser/event_parser/grammar/paths.rs | 4 ++ .../data/parser/ok/0010_use_path_segments.txt | 38 +++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 76f62b714f..3c4b223a97 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -40,7 +40,7 @@ fn node(p: &mut Parser, node_kind: SyntaxKind, rest: F) p.finish(); } -fn many bool>(p: &mut Parser, f: F) { +fn many bool>(p: &mut Parser, mut f: F) { loop { let pos = p.pos(); if !f(p) { diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 16a8ce2396..108545bc21 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -4,12 +4,16 @@ pub(crate) fn use_path(p: &mut Parser) { if !AnyOf(&[IDENT, COLONCOLON]).is_ahead(p) { return; } + let mut prev = p.mark(); node(p, PATH, |p| { path_segment(p, true); }); many(p, |p| { + let curr = p.mark(); node_if(p, COLONCOLON, PATH, |p| { path_segment(p, false); + p.forward_parent(prev, curr); + prev = curr; }) }); } diff --git a/tests/data/parser/ok/0010_use_path_segments.txt b/tests/data/parser/ok/0010_use_path_segments.txt index 10f32793e9..a407be8268 100644 --- a/tests/data/parser/ok/0010_use_path_segments.txt +++ b/tests/data/parser/ok/0010_use_path_segments.txt @@ -1,16 +1,16 @@ FILE@[0; 40) USE_ITEM@[0; 21) USE_KW@[0; 3) - PATH@[3; 9) - PATH_SEGMENT@[3; 9) - WHITESPACE@[3; 4) - COLONCOLON@[4; 6) - IDENT@[6; 9) - PATH@[9; 14) - COLONCOLON@[9; 11) - PATH_SEGMENT@[11; 14) - IDENT@[11; 14) - PATH@[14; 19) + PATH@[3; 19) + PATH@[3; 14) + PATH@[3; 9) + PATH_SEGMENT@[3; 9) + WHITESPACE@[3; 4) + COLONCOLON@[4; 6) + IDENT@[6; 9) + COLONCOLON@[9; 11) + PATH_SEGMENT@[11; 14) + IDENT@[11; 14) COLONCOLON@[14; 16) PATH_SEGMENT@[16; 19) IDENT@[16; 19) @@ -18,15 +18,15 @@ FILE@[0; 40) WHITESPACE@[20; 21) USE_ITEM@[21; 40) USE_KW@[21; 24) - PATH@[24; 28) - PATH_SEGMENT@[24; 28) - WHITESPACE@[24; 25) - IDENT@[25; 28) - PATH@[28; 33) - COLONCOLON@[28; 30) - PATH_SEGMENT@[30; 33) - IDENT@[30; 33) - PATH@[33; 38) + PATH@[24; 38) + PATH@[24; 33) + PATH@[24; 28) + PATH_SEGMENT@[24; 28) + WHITESPACE@[24; 25) + IDENT@[25; 28) + COLONCOLON@[28; 30) + PATH_SEGMENT@[30; 33) + IDENT@[30; 33) COLONCOLON@[33; 35) PATH_SEGMENT@[35; 38) IDENT@[35; 38)