luaur_ast/methods/
lexer_read_long_string.rs1use crate::records::lexeme::{Lexeme, Type};
5use crate::records::lexer::Lexer;
6use crate::records::location::Location;
7use crate::records::position::Position;
8use luaur_common::LUAU_ASSERT;
9
10impl Lexer {
11 pub(crate) fn read_long_string(
12 &mut self,
13 start: &Position,
14 sep: i32,
15 ok: Type,
16 broken: Type,
17 ) -> Lexeme {
18 LUAU_ASSERT!(self.peekch() == '[');
20 self.consume();
21
22 let start_offset = self.offset;
23
24 while self.peekch() != '\0' {
25 if self.peekch() == ']' {
26 if self.skip_long_separator() == sep {
27 LUAU_ASSERT!(self.peekch() == ']');
28 self.consume(); let end_offset = self.offset - sep as u32 - 2;
31 LUAU_ASSERT!(end_offset >= start_offset);
32
33 return Lexeme::with_data(
34 Location::new(*start, self.position()),
35 ok,
36 unsafe { self.buffer.add(start_offset as usize) },
37 (end_offset - start_offset) as usize,
38 );
39 }
40 } else {
41 self.consume_any();
42 }
43 }
44
45 Lexeme::new(Location::new(*start, self.position()), broken)
46 }
47}