From 89699c4803a0d12155adf653742f463872667610 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Jan 2018 22:11:44 +0300 Subject: G: leading colon is a part of path segment --- src/parser/event_parser/grammar/paths.rs | 14 +++++++++----- tests/data/parser/ok/0009_use_item.txt | 6 +++--- tests/data/parser/ok/0010_use_path_segments.txt | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 74b0e0ed4..16a8ce239 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -5,16 +5,20 @@ pub(crate) fn use_path(p: &mut Parser) { return; } node(p, PATH, |p| { - p.eat(COLONCOLON); - path_segment(p); + path_segment(p, true); }); many(p, |p| { node_if(p, COLONCOLON, PATH, |p| { - path_segment(p); + path_segment(p, false); }) }); } -fn path_segment(p: &mut Parser) -> bool { - node_if(p, IDENT, PATH_SEGMENT, |_| ()) +fn path_segment(p: &mut Parser, first: bool) { + node(p, PATH_SEGMENT, |p| { + if first { + p.eat(COLONCOLON); + } + p.expect(IDENT); + }) } \ No newline at end of file diff --git a/tests/data/parser/ok/0009_use_item.txt b/tests/data/parser/ok/0009_use_item.txt index f0b2981f2..f15c30940 100644 --- a/tests/data/parser/ok/0009_use_item.txt +++ b/tests/data/parser/ok/0009_use_item.txt @@ -10,8 +10,8 @@ FILE@[0; 19) USE_ITEM@[9; 19) USE_KW@[9; 12) PATH@[12; 18) - WHITESPACE@[12; 13) - COLONCOLON@[13; 15) - PATH_SEGMENT@[15; 18) + PATH_SEGMENT@[12; 18) + WHITESPACE@[12; 13) + COLONCOLON@[13; 15) IDENT@[15; 18) SEMI@[18; 19) diff --git a/tests/data/parser/ok/0010_use_path_segments.txt b/tests/data/parser/ok/0010_use_path_segments.txt index cad609087..10f32793e 100644 --- a/tests/data/parser/ok/0010_use_path_segments.txt +++ b/tests/data/parser/ok/0010_use_path_segments.txt @@ -2,9 +2,9 @@ FILE@[0; 40) USE_ITEM@[0; 21) USE_KW@[0; 3) PATH@[3; 9) - WHITESPACE@[3; 4) - COLONCOLON@[4; 6) - PATH_SEGMENT@[6; 9) + PATH_SEGMENT@[3; 9) + WHITESPACE@[3; 4) + COLONCOLON@[4; 6) IDENT@[6; 9) PATH@[9; 14) COLONCOLON@[9; 11) -- cgit v1.2.3