1 #include <fridh/lexer.hpp>
2 #include <ail/string.hpp>
6 void lexer::parse_string(line_of_code
& output
)
9 char string_character
= input
[i
];
11 std::size_t start
= i
;
20 lexer_error("Backslash at the end of the input");
24 char next_byte
= input
[i
];
29 string
.push_back('\r');
33 string
.push_back('\n');
37 if(ail::is_hex_digit(next_byte
))
40 lexer_error("Incomplete hex number escape sequence at the end of the input");
42 if(!ail::is_hex_digit(input
[i
+ 1]))
43 lexer_error("Invalid hex number escape sequence");
45 std::string hex_string
= input
.substr(i
, 2);
47 char new_byte
= ail::string_to_number
<char>(hex_string
, std::ios_base::hex
);
48 string
.push_back(new_byte
);
51 lexer_error("Invalid escape sequence: " + ail::hex_string_8(static_cast<uchar
>(next_byte
)));
56 lexer_error("Detected a newline in a string");
61 if(byte
== string_character
)
63 output
.lexemes
.push_back(lexeme(string
));
67 string
.push_back(byte
);
71 string
.push_back(byte
);
75 lexer_error("String lacks terminator");