Skip to main content

luaur_ast/methods/
parser_parse_binding.rs

1use crate::records::binding::Binding;
2use crate::records::lexeme::Type;
3use crate::records::parser::Parser;
4use crate::records::position::Position;
5
6impl Parser {
7    pub fn parse_binding(&mut self, is_const: bool) -> Binding {
8        let name = self.parse_name_opt("variable name");
9
10        let name = name.unwrap_or_else(|| crate::records::name::Name {
11            name: self.name_error,
12            location: self.lexer.current().location,
13        });
14
15        let colon_position = if self.lexer.current().r#type == Type(':' as i32) {
16            self.lexer.current().location.begin
17        } else {
18            Position::missing()
19        };
20        let annotation = self.parse_optional_type();
21
22        if self.options.store_cst_data {
23            Binding::new(name, annotation, colon_position, is_const)
24        } else {
25            Binding::new(name, annotation, Position::missing(), is_const)
26        }
27    }
28}