<<
path:
root/public/blog.git/html/src/gen/parser.jai
blob: c6431ba13cd73e446d9c681a20ced15e34281524
[raw]
[clear marker]
2PARSER_ERROR_MSG :: #string STR_END
3-- YOUR STRING ---------------------------
5------------------------------------------
7Could not find termination character: »%2«
12parser_is_at_end :: inline (idx: int, s: string) -> bool {
13 return idx > s.count-1;
16parser_peek :: inline (idx: int, s: string) -> u8 {
17 if idx > s.count-1 return "\0";
21parser_peek_forward :: inline (idx: int, s: string, offset: int) -> u8 {
22 if idx+offset > s.count-1 return "\0";
26parser_pop :: inline (idx: *int, s: string) -> u8 {
32parser_advance_by :: inline (idx: *int, offset: int) {
36parser_advance_by :: inline (idx: *int, s: string) {
40parser_match :: (s: string, substring: string, offset := 0) -> bool {
41 if substring.count + offset > s.count return false;
43 for substring if it != s[it_index + offset] return false;
48parser_consume_including :: inline (
55 return parser_consume_till(match_index, data, char, true);
58parser_consume_including :: inline (
65 return parser_consume_till(match_index, data, substring, true);
68parser_consume_till :: (
76 count := find_index_from_left(data, char, match_index);
77 if count == -1 return "";
79 offset := ifx include then 1 else 0;
80 my_slice := slice(data, match_index, count - match_index + offset);
81 return copy_string(my_slice);
84parser_consume_till :: (
92 last := substring[substring.count-1];
93 count := find_index_from_left(data, last, match_index);
94 if count == -1 return "";
96 if substring.count > 1 {
97 for < i: 0..substring.count-2 {
98 if substring[i] != data[count+i-1] return "";
102 offset := ifx include then 1 else 0;
103 my_slice := slice(data, match_index, count - match_index + offset);
104 return copy_string(my_slice);
107parse_to_int :: (s: string, $T: Type = int, loc := #caller_location) -> T #expand {
108 for s if !is_digit(it) {
111 "Your input is not a digit: '%'. Invalid character: %",
117 maybe_integer, ok := parse_int(*s, T);
120 log_error("%: Could not parse digits: '%'", loc, s);
124 return maybe_integer;