1 #include <fridh/lexer.hpp>
2 #include <ail/string.hpp>
6 bool lexer::parse_number(line_of_code
& output
, bool & error_occured
)
10 error_occured
= false;
12 if(ail::is_digit(byte
))
17 std::size_t remaining_bytes
= end
- i
;
18 if(remaining_bytes
> 1)
20 char next_byte
= input
[i
+ 1];
24 remaining_bytes
= end
- i
;
25 if(remaining_bytes
== 0)
27 error
= number_parsing_error("Incomplete hex number at the end of the input", error_occured
);
31 std::size_t hex_start
= i
;
33 for(; i
< end
&& ail::is_hex_digit(input
[i
]); i
++);
35 std::size_t hex_length
= i
- hex_start
;
39 error
= lexer_error("Incomplete hex number");
43 std::string hex_string
= input
.substr(hex_start
, i
- end
);
44 types::unsigned_integer value
= ail::string_to_number
<types::unsigned_integer
>(hex_string
, std::ios_base::hex
);
45 output
.lexemes
.push_back(lexeme(value
));
54 char last_byte
= byte
;
62 error
= number_parsing_error("Encountered a floating point value containing multiple dots", error_occured
);
68 else if(!ail::is_digit(byte
))
76 error
= number_parsing_error("Encountered a floating point value ending with a dot", error_occured
);
80 std::string number_string
= input
.substr(start
, i
- start
);
81 lexeme current_lexeme
;
83 current_lexeme
= lexeme(ail::string_to_number
<types::floating_point_value
>(number_string
));
85 current_lexeme
= lexeme(ail::string_to_number
<types::signed_integer
>(number_string
));
86 output
.lexemes
.push_back(current_lexeme
);