1 #include <frith/lexer.hpp>
2 #include <ail/string.hpp>
6 bool lexer::parse_string(line_of_code
& output
, std::string
& error_message
, std::string error_prefix
)
9 char string_character
= input
[i
];
11 std::size_t start
= i
;
21 error_message
= lexer_error(error_prefix
+ "Backslash at the end of the input");
27 char next_byte
= input
[i
];
32 string
.push_back('\r');
36 string
.push_back('\n');
40 if(ail::is_hex_digit(next_byte
))
44 error_message
= lexer_error(error_prefix
+ "Incomplete hex number escape sequence at the end of the input");
47 if(!ail::is_hex_digit(input
[i
+ 1]))
49 error_message
= lexer_error(error_prefix
+ "Invalid hex number escape sequence");
52 std::string hex_string
= input
.substr(i
, 2);
54 char new_byte
= ail::string_to_number
<char>(hex_string
, std::ios_base::hex
);
55 string
.push_back(new_byte
);
59 error_message
= lexer_error(error_prefix
+ "Invalid escape sequence: " + ail::hex_string_8(static_cast<uchar
>(next_byte
)));
66 error_message
= lexer_error(error_prefix
+ "Detected a newline in a string");
71 if(byte
== string_character
)
73 output
.lexemes
.push_back(lexeme(lexeme_type_string
, string
));
77 string
.push_back(byte
);
81 string
.push_back(byte
);
85 error_message
= lexer_error(error_prefix
+ "String lacks terminator");