PARSER_ERROR_MSG :: #string STR_END -- YOUR STRING --------------------------- %1 ------------------------------------------ Parsing error at: %3 Could not find termination character: »%2« STR_END; parser_is_at_end :: inline (idx: int, s: string) -> bool { return idx > s.count-1; } parser_peek :: inline (idx: int, s: string) -> u8 { if idx > s.count-1 return "\0"; return s[idx]; } parser_peek_forward :: inline (idx: int, s: string, offset: int) -> u8 { if idx+offset > s.count-1 return "\0"; return s[idx+offset]; } parser_pop :: inline (idx: *int, s: string) -> u8 { value := s[idx.*]; idx.* += 1; return value; } parser_advance_by :: inline (idx: *int, offset: int) { idx.* += offset; } parser_advance_by :: inline (idx: *int, s: string) { idx.* += s.count; } parser_match :: (s: string, substring: string, offset := 0) -> bool { if substring.count + offset > s.count return false; for substring if it != s[it_index + offset] return false; return true; } parser_consume_including :: inline ( match_index: int, data: string, char: u8 ) -> string { return parser_consume_till(match_index, data, char, true); } parser_consume_including :: inline ( match_index: int, data: string, substring: string ) -> string { return parser_consume_till(match_index, data, substring, true); } parser_consume_till :: ( match_index: int, data: string, char: u8, include := false, ) -> string { count := find_index_from_left(data, char, match_index); if count == -1 return ""; offset := ifx include then 1 else 0; my_slice := slice(data, match_index, count - match_index + offset); return copy_string(my_slice); } parser_consume_till :: ( match_index: int, data: string, substring: string, include := false ) -> string { last := substring[substring.count-1]; count := find_index_from_left(data, last, match_index); if count == -1 return ""; if substring.count > 1 { for < i: 0..substring.count-2 { if substring[i] != data[count+i-1] return ""; } } offset := ifx include then 1 else 0; my_slice := slice(data, match_index, count - match_index + offset); return copy_string(my_slice); } parse_to_int :: (s: string, $T: Type = int, loc := #caller_location) -> T #expand { for s if !is_digit(it) { log_error("%", loc); log_error( "Your input is not a digit: '%'. Invalid character: %", s, string.{ 1, *it } ); exit(1); } maybe_integer, ok := parse_int(*s, T); if !ok { log_error("%: Could not parse digits: '%'", loc, s); exit(1); } return maybe_integer; }