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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use crate::veryl_grammar_trait::*;
use crate::veryl_token::{Token, VerylToken};
use crate::veryl_walker::VerylWalker;

#[derive(Default)]
pub struct Finder {
    pub line: u32,
    pub column: u32,
    pub token: Option<Token>,
    pub token_group: Vec<Token>,
    hit: bool,
    group_hit: bool,
    in_group: bool,
    lock_group: bool,
}

impl Finder {
    pub fn new() -> Self {
        Default::default()
    }
}

impl VerylWalker for Finder {
    /// Semantic action for non-terminal 'VerylToken'
    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;
            self.group_hit = true;
        }
        if self.in_group && !self.lock_group {
            self.token_group.push(arg.token);
        }
    }

    /// Semantic action for non-terminal 'HierarchicalIdentifier'
    fn hierarchical_identifier(&mut self, arg: &HierarchicalIdentifier) {
        self.group_hit = false;
        self.in_group = true;
        self.identifier(&arg.identifier);
        self.in_group = false;
        for x in &arg.hierarchical_identifier_list {
            self.select(&x.select);
        }
        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.select(&x.select);
            }
        }
        if self.group_hit {
            self.lock_group = true;
        } else if !self.lock_group {
            self.token_group.clear();
        }
    }

    /// Semantic action for non-terminal 'ScopedIdentifier'
    fn scoped_identifier(&mut self, arg: &ScopedIdentifier) {
        self.group_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.group_hit {
            self.lock_group = true;
        } else if !self.lock_group {
            self.token_group.clear();
        }
    }

    /// Semantic action for non-terminal 'ExpressionIdentifier'
    fn expression_identifier(&mut self, arg: &ExpressionIdentifier) {
        self.group_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::ColonColonIdentifierExpressionIdentifierGroupListExpressionIdentifierGroupList0(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;
                }
                for x in &x.expression_identifier_group_list0 {
                    self.select(&x.select);
                }
            }
            ExpressionIdentifierGroup::ExpressionIdentifierGroupList1ExpressionIdentifierGroupList2(x) => {
                for x in &x.expression_identifier_group_list1 {
                    self.select(&x.select);
                }
                for x in &x.expression_identifier_group_list2 {
                    self.dot(&x.dot);
                    self.in_group = true;
                    self.identifier(&x.identifier);
                    self.in_group = false;
                    for x in &x.expression_identifier_group_list2_list {
                        self.select(&x.select);
                    }
                }
            }
        }
        if self.group_hit {
            self.lock_group = true;
        } else if !self.lock_group {
            self.token_group.clear();
        }
    }

    /// Semantic action for non-terminal 'Veryl'
    fn veryl(&mut self, arg: &Veryl) {
        self.hit = false;
        self.lock_group = false;
        self.token_group.clear();

        self.start(&arg.start);
        for x in &arg.veryl_list {
            self.description_group(&x.description_group);
        }
    }
}