1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::veryl_grammar_trait::*;
use crate::veryl_token::{Token, VerylToken};
use crate::veryl_walker::VerylWalker;
#[derive(Default)]
pub struct Finder {
pub line: usize,
pub column: usize,
pub token: Option<Token>,
pub token_group: Vec<Token>,
hit: bool,
in_group: bool,
}
impl Finder {
pub fn new() -> Self {
Default::default()
}
}
impl VerylWalker for Finder {
fn veryl_token(&mut self, arg: &VerylToken) {
if arg.token.line == self.line
&& arg.token.column <= self.column
&& self.column < arg.token.column + arg.token.length
{
self.token = Some(arg.token);
self.hit = true;
}
if self.in_group {
self.token_group.push(arg.token);
}
}
fn hierarchical_identifier(&mut self, arg: &HierarchicalIdentifier) {
self.hit = false;
self.in_group = true;
self.identifier(&arg.identifier);
self.in_group = false;
for x in &arg.hierarchical_identifier_list {
self.range(&x.range);
}
for x in &arg.hierarchical_identifier_list0 {
self.dot(&x.dot);
self.in_group = true;
self.identifier(&x.identifier);
self.in_group = false;
for x in &x.hierarchical_identifier_list0_list {
self.range(&x.range);
}
}
if !self.hit {
self.token_group.clear();
}
}
fn scoped_identifier(&mut self, arg: &ScopedIdentifier) {
self.hit = false;
self.in_group = true;
self.identifier(&arg.identifier);
self.in_group = false;
for x in &arg.scoped_identifier_list {
self.colon_colon(&x.colon_colon);
self.in_group = true;
self.identifier(&x.identifier);
self.in_group = false;
}
if !self.hit {
self.token_group.clear();
}
}
fn expression_identifier(&mut self, arg: &ExpressionIdentifier) {
self.hit = false;
if let Some(ref x) = arg.expression_identifier_opt {
self.dollar(&x.dollar);
}
self.in_group = true;
self.identifier(&arg.identifier);
self.in_group = false;
match &*arg.expression_identifier_group {
ExpressionIdentifierGroup::ColonColonIdentifierExpressionIdentifierGroupList(x) => {
self.colon_colon(&x.colon_colon);
self.in_group = true;
self.identifier(&x.identifier);
self.in_group = false;
for x in &x.expression_identifier_group_list {
self.colon_colon(&x.colon_colon);
self.in_group = true;
self.identifier(&x.identifier);
self.in_group = false;
}
}
ExpressionIdentifierGroup::ExpressionIdentifierGroupList0ExpressionIdentifierGroupList1(x) => {
for x in &x.expression_identifier_group_list0 {
self.range(&x.range);
}
for x in &x.expression_identifier_group_list1 {
self.dot(&x.dot);
self.in_group = true;
self.identifier(&x.identifier);
self.in_group = false;
for x in &x.expression_identifier_group_list1_list {
self.range(&x.range);
}
}
}
}
if !self.hit {
self.token_group.clear();
}
}
}