1 #include <fridh/lexer.hpp>
2 #include <ail/string.hpp>
6 bool lexer::parse_number(line_of_code
& output
)
11 if(ail::is_digit(byte
))
16 std::size_t remaining_bytes
= end
- i
;
17 if(remaining_bytes
> 1)
19 char next_byte
= input
[i
+ 1];
23 remaining_bytes
= end
- i
;
24 if(remaining_bytes
== 0)
25 number_parsing_error("Incomplete hex number at the end of the input");
27 std::size_t hex_start
= i
;
29 for(; i
< end
&& ail::is_hex_digit(input
[i
]); i
++);
31 std::size_t hex_length
= i
- hex_start
;
33 lexer_error("Incomplete hex number");
35 std::string hex_string
= input
.substr(hex_start
, i
- end
);
36 types::unsigned_integer value
= ail::string_to_number
<types::unsigned_integer
>(hex_string
, std::ios_base::hex
);
37 output
.lexemes
.push_back(lexeme(value
));
46 char last_byte
= byte
;
53 number_parsing_error("Encountered a floating point value containing multiple dots");
57 else if(!ail::is_digit(byte
))
64 number_parsing_error("Encountered a floating point value ending with a dot");
66 std::string number_string
= input
.substr(start
, i
- start
);
67 lexeme current_lexeme
;
69 current_lexeme
= lexeme(ail::string_to_number
<types::floating_point_value
>(number_string
));
71 current_lexeme
= lexeme(ail::string_to_number
<types::signed_integer
>(number_string
));
72 output
.lexemes
.push_back(current_lexeme
);