luaur_ast/methods/
parser_parse_char_array.rs1use crate::records::ast_array::AstArray;
2use crate::records::lexeme::Type;
3use crate::records::lexer::Lexer;
4use crate::records::parser::Parser;
5use core::ffi::c_char;
6use luaur_common::macros::luau_assert::LUAU_ASSERT;
7
8impl Parser {
9 pub(crate) fn parse_char_array(
10 &mut self,
11 original_string: Option<*mut AstArray<c_char>>,
12 ) -> Option<AstArray<c_char>> {
13 let current_lexeme = *self.lexer.current();
14 let current_type = current_lexeme.r#type;
15 LUAU_ASSERT!(
16 current_type == Type::QuotedString
17 || current_type == Type::RawString
18 || current_type == Type::InterpStringSimple
19 );
20
21 let data_ptr = unsafe { current_lexeme.data.data };
22 let length = current_lexeme.get_length() as usize;
23 let bytes = unsafe { core::slice::from_raw_parts(data_ptr as *const u8, length) };
24
25 if let Some(original) = original_string {
26 unsafe {
27 *original = self.copy_bytes(bytes);
28 }
29 }
30
31 let mut data = bytes.to_vec();
32
33 if current_type == Type::QuotedString || current_type == Type::InterpStringSimple {
34 if !Lexer::fixup_quoted_bytes(&mut data) {
35 self.next_lexeme();
36 return None;
37 }
38 } else {
39 Lexer::fixup_multiline_bytes(&mut data);
40 }
41
42 let value = self.copy_bytes(&data);
43 self.next_lexeme();
44 Some(value)
45 }
46}
47
48#[allow(non_snake_case)]
49pub fn parser_parse_char_array(
50 this: &mut Parser,
51 original_string: Option<*mut AstArray<c_char>>,
52) -> Option<AstArray<c_char>> {
53 this.parse_char_array(original_string)
54}