27#define LUA_DEFINES_LIST_ELEMENT(key, const_value) \
28 if(parsers::is_fixed_token_ci(text.data(), text.data() + text.length(), #key)) { key = v; return; }
30#undef LUA_DEFINES_LIST_ELEMENT
35 char const* start = data.data();
36 char const* end = data.data() + data.length();
37 char const* position = start;
39 for(; position < end && isspace(*position); ++position)
41 auto first_non_ws = position;
43 for(; position < end && !isspace(*position) && *position !=
'='; ++position)
46 auto identifier_end = position;
48 for(; position < end && *position !=
'='; ++position)
51 for(; position < end && isspace(*position); ++position)
54 auto value_start = position;
55 for(; position < end && !isspace(*position) && *position !=
','; ++position)
58 auto value_end = position;
61 position = value_start;
63 for(; position < value_end && !isdigit(*position); ++position)
65 auto year_start = position;
66 for(; position < value_end && isdigit(*position); ++position)
68 auto year_end = position;
70 for(; position < value_end && !isdigit(*position); ++position)
72 auto month_start = position;
73 for(; position < value_end && isdigit(*position); ++position)
75 auto month_end = position;
77 for(; position < value_end && !isdigit(*position); ++position)
79 auto day_start = position;
80 for(; position < value_end && isdigit(*position); ++position)
82 auto day_end = position;
86 uint16_t(
parsers::parse_uint(std::string_view(month_start, month_end - month_start), line, err)),
87 uint16_t(
parsers::parse_uint(std::string_view(day_start, day_end - day_start), line, err))});
89 position = value_start;
91 for(; position < value_end && !isdigit(*position); ++position)
93 auto year_start = position;
94 for(; position < value_end && isdigit(*position); ++position)
96 auto year_end = position;
98 for(; position < value_end && !isdigit(*position); ++position)
100 auto month_start = position;
101 for(; position < value_end && isdigit(*position); ++position)
103 auto month_end = position;
105 for(; position < value_end && !isdigit(*position); ++position)
107 auto day_start = position;
108 for(; position < value_end && isdigit(*position); ++position)
110 auto day_end = position;
114 uint16_t(
parsers::parse_uint(std::string_view(month_start, month_end - month_start), line, err)),
115 uint16_t(
parsers::parse_uint(std::string_view(day_start, day_end - day_start), line, err))});
117 auto const value =
parsers::parse_float(std::string_view(value_start, value_end - value_start), line, err);
118 assign_define(state, line, std::string_view(first_non_ws, identifier_end - first_non_ws), value, err);
123 auto const remove_comments = [](std::string_view
text) -> std::string_view {
124 auto end_it =
text.end();
125 for(
auto it =
text.begin(); it !=
text.end(); it++) {
126 if(it !=
text.end() && (it + 1) !=
text.end() && it[0] ==
'-' && it[1] ==
'-') {
131 return text.substr(0, std::distance(
text.begin(), end_it));
134 auto start_it = data.begin();
136 for(
auto it = data.begin(); it != data.end(); it++) {
138 auto const line_text = data.substr(std::distance(data.begin(), start_it), std::distance(start_it, it));
139 parse_line(state, line_num, remove_comments(line_text), err);
146 state.defines.investment_score_factor *= 0.05f;
147 state.defines.base_truce_months = std::max(0.f, state.defines.base_truce_months);
std::string accumulated_errors
bool is_fixed_token_ci(char const *start, char const *end, char const (&t)[N])
int32_t parse_int(std::string_view content, int32_t line, error_handler &err)
float parse_float(std::string_view content, int32_t line, error_handler &err)
uint32_t parse_uint(std::string_view content, int32_t line, error_handler &err)
void parse_file(sys::state &state, std::string_view data, parsers::error_handler &err)
void parse_line(sys::state &state, int32_t line, std::string_view data, parsers::error_handler &err)
LUA_DEFINES_LIST void assign_define(sys::state &state, int32_t line, std::string_view key, float v, parsers::error_handler &err)