Skip to main content

luaur_ast/methods/
parser_parse_index_name.rs

1use crate::records::ast_name::AstName;
2use crate::records::lexeme::Type;
3use crate::records::location::Location;
4use crate::records::name::Name;
5use crate::records::parser::Parser;
6use crate::records::position::Position;
7
8impl Parser {
9    pub fn parse_index_name(&mut self, context: &str, previous: &Position) -> Name {
10        if let Some(name) = self.parse_name_opt(context) {
11            return name;
12        }
13
14        // If we have a reserved keyword next at the same line, assume it's an incomplete name
15        let current = self.lexer.current();
16        if current.r#type >= Type::Reserved_BEGIN
17            && current.r#type < Type::Reserved_END
18            && current.location.begin.line == previous.line
19        {
20            let result = Name {
21                name: AstName {
22                    value: unsafe { current.data.name },
23                },
24                location: current.location,
25            };
26
27            self.next_lexeme();
28
29            return result;
30        }
31
32        let mut location = self.lexer.current().location;
33        location.end = location.begin;
34
35        Name {
36            name: self.name_error,
37            location,
38        }
39    }
40}