packcr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +73 -0
  4. data/lib/packcr/context.rb +1 -1
  5. data/lib/packcr/generated/context.rb +121 -78
  6. data/lib/packcr/generated/node/action_node.rb +2 -2
  7. data/lib/packcr/generated/node/alternate_node.rb +2 -2
  8. data/lib/packcr/generated/node/capture_node.rb +1 -1
  9. data/lib/packcr/generated/node/charclass_node.rb +9 -9
  10. data/lib/packcr/generated/node/eof_node.rb +1 -1
  11. data/lib/packcr/generated/node/error_node.rb +2 -2
  12. data/lib/packcr/generated/node/expand_node.rb +2 -2
  13. data/lib/packcr/generated/node/predicate_node.rb +2 -2
  14. data/lib/packcr/generated/node/quantity_node.rb +30 -31
  15. data/lib/packcr/generated/node/reference_node.rb +2 -2
  16. data/lib/packcr/generated/node/rule_node.rb +7 -7
  17. data/lib/packcr/generated/node/string_node.rb +4 -4
  18. data/lib/packcr/parser.rb +619 -613
  19. data/lib/packcr/templates/context/header.c.erb +3 -3
  20. data/lib/packcr/templates/context/source.c.erb +417 -403
  21. data/lib/packcr/templates/context/source.rb.erb +42 -25
  22. data/lib/packcr/templates/node/action.c.erb +2 -2
  23. data/lib/packcr/templates/node/alternate.c.erb +2 -2
  24. data/lib/packcr/templates/node/capture.c.erb +2 -2
  25. data/lib/packcr/templates/node/charclass.c.erb +4 -4
  26. data/lib/packcr/templates/node/charclass_any.c.erb +2 -2
  27. data/lib/packcr/templates/node/charclass_one.c.erb +4 -4
  28. data/lib/packcr/templates/node/charclass_utf8.c.erb +2 -2
  29. data/lib/packcr/templates/node/eof.c.erb +1 -1
  30. data/lib/packcr/templates/node/error.c.erb +4 -4
  31. data/lib/packcr/templates/node/expand.c.erb +2 -2
  32. data/lib/packcr/templates/node/predicate.c.erb +1 -1
  33. data/lib/packcr/templates/node/predicate_neg.c.erb +1 -1
  34. data/lib/packcr/templates/node/quantity_many.c.erb +9 -7
  35. data/lib/packcr/templates/node/quantity_one.c.erb +9 -7
  36. data/lib/packcr/templates/node/quantity_one.rb.erb +4 -4
  37. data/lib/packcr/templates/node/reference.c.erb +6 -6
  38. data/lib/packcr/templates/node/rule.c.erb +9 -9
  39. data/lib/packcr/templates/node/string_many.c.erb +2 -2
  40. data/lib/packcr/templates/node/string_one.c.erb +2 -2
  41. data/lib/packcr/util.rb +1 -1
  42. data/lib/packcr/version.rb +1 -1
  43. metadata +5 -3
@@ -16,14 +16,14 @@
16
16
 
17
17
  #ifndef _MSC_VER
18
18
  #if defined __GNUC__ && defined _WIN32 /* MinGW */
19
- #ifndef PCC_USE_SYSTEM_STRNLEN
20
- #define strnlen(str, maxlen) pcc_strnlen(str, maxlen)
21
- static size_t pcc_strnlen(const char *str, size_t maxlen) {
19
+ #ifndef PACKCR_USE_SYSTEM_STRNLEN
20
+ #define strnlen(str, maxlen) packcr_strnlen(str, maxlen)
21
+ static size_t packcr_strnlen(const char *str, size_t maxlen) {
22
22
  size_t i;
23
23
  for (i = 0; i < maxlen && str[i]; i++);
24
24
  return i;
25
25
  }
26
- #endif /* !PCC_USE_SYSTEM_STRNLEN */
26
+ #endif /* !PACKCR_USE_SYSTEM_STRNLEN */
27
27
  #endif /* defined __GNUC__ && defined _WIN32 */
28
28
  #endif /* !_MSC_VER */
29
29
 
@@ -48,221 +48,221 @@ static size_t pcc_strnlen(const char *str, size_t maxlen) {
48
48
  #define MARK_FUNC_AS_USED __attribute__((__unused__))
49
49
  #endif
50
50
 
51
- #ifndef PCC_BUFFER_MIN_SIZE
52
- #define PCC_BUFFER_MIN_SIZE 256
53
- #endif /* !PCC_BUFFER_MIN_SIZE */
51
+ #ifndef PACKCR_BUFFER_MIN_SIZE
52
+ #define PACKCR_BUFFER_MIN_SIZE 256
53
+ #endif /* !PACKCR_BUFFER_MIN_SIZE */
54
54
 
55
- #ifndef PCC_ARRAY_MIN_SIZE
56
- #define PCC_ARRAY_MIN_SIZE 2
57
- #endif /* !PCC_ARRAY_MIN_SIZE */
55
+ #ifndef PACKCR_ARRAY_MIN_SIZE
56
+ #define PACKCR_ARRAY_MIN_SIZE 2
57
+ #endif /* !PACKCR_ARRAY_MIN_SIZE */
58
58
 
59
- #ifndef PCC_POOL_MIN_SIZE
60
- #define PCC_POOL_MIN_SIZE 65536
61
- #endif /* !PCC_POOL_MIN_SIZE */
59
+ #ifndef PACKCR_POOL_MIN_SIZE
60
+ #define PACKCR_POOL_MIN_SIZE 65536
61
+ #endif /* !PACKCR_POOL_MIN_SIZE */
62
62
 
63
- #define PCC_DBG_EVALUATE 0
64
- #define PCC_DBG_MATCH 1
65
- #define PCC_DBG_NOMATCH 2
63
+ #define PACKCR_DBG_EVALUATE 0
64
+ #define PACKCR_DBG_MATCH 1
65
+ #define PACKCR_DBG_NOMATCH 2
66
66
 
67
- #define PCC_VOID_VALUE (~(size_t)0)
67
+ #define PACKCR_VOID_VALUE (~(size_t)0)
68
68
 
69
- typedef enum pcc_bool_tag {
70
- PCC_FALSE = 0,
71
- PCC_TRUE
72
- } pcc_bool_t;
69
+ typedef enum packcr_bool_tag {
70
+ PACKCR_FALSE = 0,
71
+ PACKCR_TRUE
72
+ } packcr_bool_t;
73
73
 
74
- typedef struct pcc_char_array_tag {
74
+ typedef struct packcr_char_array_tag {
75
75
  char *buf;
76
76
  size_t max;
77
77
  size_t len;
78
- } pcc_char_array_t;
78
+ } packcr_char_array_t;
79
79
 
80
- typedef struct pcc_range_tag {
80
+ typedef struct packcr_range_tag {
81
81
  size_t start;
82
82
  size_t end;
83
83
  <%- if @location -%>
84
- pcc_location_t start_loc;
85
- pcc_location_t end_loc;
84
+ packcr_location_t start_loc;
85
+ packcr_location_t end_loc;
86
86
  <%- end -%>
87
- } pcc_range_t;
87
+ } packcr_range_t;
88
88
 
89
- typedef <%= value_def %>pcc_value_t;
89
+ typedef <%= value_def %>packcr_value_t;
90
90
 
91
- typedef <%= auxil_def %>pcc_auxil_t;
91
+ typedef <%= auxil_def %>packcr_auxil_t;
92
92
 
93
- <% if prefix != "pcc" -%>
94
- typedef <%= prefix%>_context_t pcc_context_t;
93
+ <% if prefix != "packcr" -%>
94
+ typedef <%= prefix%>_context_t packcr_context_t;
95
95
 
96
96
  <% end -%>
97
- typedef struct pcc_value_table_tag {
98
- pcc_value_t *buf;
97
+ typedef struct packcr_value_table_tag {
98
+ packcr_value_t *buf;
99
99
  size_t max;
100
100
  size_t len;
101
- } pcc_value_table_t;
101
+ } packcr_value_table_t;
102
102
 
103
- typedef struct pcc_value_refer_table_tag {
104
- pcc_value_t **buf;
103
+ typedef struct packcr_value_refer_table_tag {
104
+ packcr_value_t **buf;
105
105
  size_t max;
106
106
  size_t len;
107
- } pcc_value_refer_table_t;
107
+ } packcr_value_refer_table_t;
108
108
 
109
- typedef struct pcc_capture_tag {
110
- pcc_range_t range;
109
+ typedef struct packcr_capture_tag {
110
+ packcr_range_t range;
111
111
  char *string; /* mutable */
112
- } pcc_capture_t;
112
+ } packcr_capture_t;
113
113
 
114
- typedef struct pcc_capture_table_tag {
115
- pcc_capture_t *buf;
114
+ typedef struct packcr_capture_table_tag {
115
+ packcr_capture_t *buf;
116
116
  size_t max;
117
117
  size_t len;
118
- } pcc_capture_table_t;
118
+ } packcr_capture_table_t;
119
119
 
120
- typedef struct pcc_capture_const_table_tag {
121
- const pcc_capture_t **buf;
120
+ typedef struct packcr_capture_const_table_tag {
121
+ const packcr_capture_t **buf;
122
122
  size_t max;
123
123
  size_t len;
124
- } pcc_capture_const_table_t;
125
-
126
- typedef struct pcc_thunk_tag pcc_thunk_t;
127
- typedef struct pcc_thunk_array_tag pcc_thunk_array_t;
128
-
129
- typedef void (*pcc_action_t)(pcc_context_t *, pcc_thunk_t *, pcc_value_t *);
130
-
131
- typedef enum pcc_thunk_type_tag {
132
- PCC_THUNK_LEAF,
133
- PCC_THUNK_NODE
134
- } pcc_thunk_type_t;
135
-
136
- typedef struct pcc_thunk_leaf_tag {
137
- pcc_value_refer_table_t values;
138
- pcc_capture_const_table_t capts;
139
- pcc_capture_t capt0;
140
- pcc_action_t action;
141
- } pcc_thunk_leaf_t;
142
-
143
- typedef struct pcc_thunk_node_tag {
144
- const pcc_thunk_array_t *thunks; /* just a reference */
145
- pcc_value_t *value; /* just a reference */
146
- } pcc_thunk_node_t;
147
-
148
- typedef union pcc_thunk_data_tag {
149
- pcc_thunk_leaf_t leaf;
150
- pcc_thunk_node_t node;
151
- } pcc_thunk_data_t;
152
-
153
- struct pcc_thunk_tag {
154
- pcc_thunk_type_t type;
155
- pcc_thunk_data_t data;
124
+ } packcr_capture_const_table_t;
125
+
126
+ typedef struct packcr_thunk_tag packcr_thunk_t;
127
+ typedef struct packcr_thunk_array_tag packcr_thunk_array_t;
128
+
129
+ typedef void (*packcr_action_t)(packcr_context_t *, packcr_thunk_t *, packcr_value_t *);
130
+
131
+ typedef enum packcr_thunk_type_tag {
132
+ PACKCR_THUNK_LEAF,
133
+ PACKCR_THUNK_NODE
134
+ } packcr_thunk_type_t;
135
+
136
+ typedef struct packcr_thunk_leaf_tag {
137
+ packcr_value_refer_table_t values;
138
+ packcr_capture_const_table_t capts;
139
+ packcr_capture_t capt0;
140
+ packcr_action_t action;
141
+ } packcr_thunk_leaf_t;
142
+
143
+ typedef struct packcr_thunk_node_tag {
144
+ const packcr_thunk_array_t *thunks; /* just a reference */
145
+ packcr_value_t *value; /* just a reference */
146
+ } packcr_thunk_node_t;
147
+
148
+ typedef union packcr_thunk_data_tag {
149
+ packcr_thunk_leaf_t leaf;
150
+ packcr_thunk_node_t node;
151
+ } packcr_thunk_data_t;
152
+
153
+ struct packcr_thunk_tag {
154
+ packcr_thunk_type_t type;
155
+ packcr_thunk_data_t data;
156
156
  };
157
157
 
158
- struct pcc_thunk_array_tag {
159
- pcc_thunk_t **buf;
158
+ struct packcr_thunk_array_tag {
159
+ packcr_thunk_t **buf;
160
160
  size_t max;
161
161
  size_t len;
162
162
  };
163
163
 
164
- typedef struct pcc_thunk_chunk_tag {
165
- pcc_value_table_t values;
166
- pcc_capture_table_t capts;
167
- pcc_thunk_array_t thunks;
164
+ typedef struct packcr_thunk_chunk_tag {
165
+ packcr_value_table_t values;
166
+ packcr_capture_table_t capts;
167
+ packcr_thunk_array_t thunks;
168
168
  size_t pos; /* the starting position in the character buffer */
169
169
  <%- if @location -%>
170
- pcc_location_t pos_loc;
170
+ packcr_location_t pos_loc;
171
171
  <%- end -%>
172
- } pcc_thunk_chunk_t;
172
+ } packcr_thunk_chunk_t;
173
173
 
174
- typedef struct pcc_lr_memo_tag pcc_lr_memo_t;
174
+ typedef struct packcr_lr_memo_tag packcr_lr_memo_t;
175
175
 
176
- struct pcc_lr_memo_tag {
176
+ struct packcr_lr_memo_tag {
177
177
  size_t offset;
178
178
  <%- if @location -%>
179
- pcc_location_t offset_loc;
179
+ packcr_location_t offset_loc;
180
180
  <%- end -%>
181
- pcc_lr_memo_t *hold;
182
- pcc_thunk_chunk_t *chunk;
183
- pcc_bool_t fail;
184
- pcc_bool_t grow;
181
+ packcr_lr_memo_t *hold;
182
+ packcr_thunk_chunk_t *chunk;
183
+ packcr_bool_t fail;
184
+ packcr_bool_t grow;
185
185
  };
186
186
 
187
- typedef struct pcc_rule_set_tag pcc_rule_set_t;
187
+ typedef struct packcr_rule_set_tag packcr_rule_set_t;
188
188
 
189
- typedef pcc_thunk_chunk_t *(*pcc_rule_t)(pcc_context_t *, size_t<% if @location %>, pcc_location_t<% end %>, pcc_rule_set_t*);
189
+ typedef packcr_thunk_chunk_t *(*packcr_rule_t)(packcr_context_t *, size_t<% if @location %>, packcr_location_t<% end %>, packcr_rule_set_t*);
190
190
 
191
- typedef struct pcc_rule_set_tag {
192
- pcc_rule_t *buf;
191
+ typedef struct packcr_rule_set_tag {
192
+ packcr_rule_t *buf;
193
193
  size_t max;
194
194
  size_t len;
195
- } pcc_rule_set_t;
195
+ } packcr_rule_set_t;
196
196
 
197
- typedef struct pcc_lr_memo_map_entry_tag {
198
- pcc_rule_t rule;
199
- pcc_lr_memo_t *memo;
200
- } pcc_lr_memo_map_entry_t;
197
+ typedef struct packcr_lr_memo_map_entry_tag {
198
+ packcr_rule_t rule;
199
+ packcr_lr_memo_t *memo;
200
+ } packcr_lr_memo_map_entry_t;
201
201
 
202
- typedef struct pcc_lr_memo_map_tag {
203
- pcc_lr_memo_map_entry_t *buf;
202
+ typedef struct packcr_lr_memo_map_tag {
203
+ packcr_lr_memo_map_entry_t *buf;
204
204
  size_t max;
205
205
  size_t len;
206
- } pcc_lr_memo_map_t;
206
+ } packcr_lr_memo_map_t;
207
207
 
208
- typedef struct pcc_lr_table_tag {
209
- pcc_lr_memo_map_t **buf;
208
+ typedef struct packcr_lr_table_tag {
209
+ packcr_lr_memo_map_t **buf;
210
210
  size_t max;
211
211
  size_t len;
212
212
  size_t ofs;
213
- } pcc_lr_table_t;
213
+ } packcr_lr_table_t;
214
214
 
215
- typedef struct pcc_memory_entry_tag pcc_memory_entry_t;
216
- typedef struct pcc_memory_pool_tag pcc_memory_pool_t;
215
+ typedef struct packcr_memory_entry_tag packcr_memory_entry_t;
216
+ typedef struct packcr_memory_pool_tag packcr_memory_pool_t;
217
217
 
218
- struct pcc_memory_entry_tag {
219
- pcc_memory_entry_t *next;
218
+ struct packcr_memory_entry_tag {
219
+ packcr_memory_entry_t *next;
220
220
  };
221
221
 
222
- struct pcc_memory_pool_tag {
223
- pcc_memory_pool_t *next;
222
+ struct packcr_memory_pool_tag {
223
+ packcr_memory_pool_t *next;
224
224
  size_t allocated;
225
225
  size_t unused;
226
226
  };
227
227
 
228
- typedef struct pcc_memory_recycler_tag {
229
- pcc_memory_pool_t *pool_list;
230
- pcc_memory_entry_t *entry_list;
228
+ typedef struct packcr_memory_recycler_tag {
229
+ packcr_memory_pool_t *pool_list;
230
+ packcr_memory_entry_t *entry_list;
231
231
  size_t element_size;
232
- } pcc_memory_recycler_t;
232
+ } packcr_memory_recycler_t;
233
233
 
234
234
  struct <%= prefix %>_context_tag {
235
235
  size_t buffer_start_position; /* the position in the input of the first character currently buffered */
236
236
  size_t position_offset; /* the current parsing position in the character buffer */
237
237
  <%- if @location -%>
238
- pcc_location_t buffer_start_position_loc;
239
- pcc_location_t position_offset_loc;
238
+ packcr_location_t buffer_start_position_loc;
239
+ packcr_location_t position_offset_loc;
240
240
  <%- end -%>
241
241
  size_t level;
242
- pcc_char_array_t buffer;
243
- pcc_lr_table_t lrtable;
244
- pcc_thunk_array_t thunks;
245
- pcc_auxil_t auxil;
246
- pcc_memory_recycler_t thunk_chunk_recycler;
247
- pcc_memory_recycler_t lr_memo_recycler;
242
+ packcr_char_array_t buffer;
243
+ packcr_lr_table_t lrtable;
244
+ packcr_thunk_array_t thunks;
245
+ packcr_auxil_t auxil;
246
+ packcr_memory_recycler_t thunk_chunk_recycler;
247
+ packcr_memory_recycler_t lr_memo_recycler;
248
248
  };
249
249
 
250
- #ifndef PCC_ERROR
251
- #define PCC_ERROR(auxil) pcc_error()
250
+ #ifndef PACKCR_ERROR
251
+ #define PACKCR_ERROR(auxil) packcr_error()
252
252
  MARK_FUNC_AS_USED
253
- static void pcc_error(void) {
253
+ static void packcr_error(void) {
254
254
  fprintf(stderr, "Syntax error\n");
255
255
  exit(1);
256
256
  }
257
- #endif /* !PCC_ERROR */
257
+ #endif /* !PACKCR_ERROR */
258
258
 
259
- #ifndef PCC_GETCHAR
260
- #define PCC_GETCHAR(auxil) getchar()
261
- #endif /* !PCC_GETCHAR */
259
+ #ifndef PACKCR_GETCHAR
260
+ #define PACKCR_GETCHAR(auxil) getchar()
261
+ #endif /* !PACKCR_GETCHAR */
262
262
 
263
- #ifndef PCC_MALLOC
264
- #define PCC_MALLOC(auxil, size) pcc_malloc_e(size)
265
- static void *pcc_malloc_e(size_t size) {
263
+ #ifndef PACKCR_MALLOC
264
+ #define PACKCR_MALLOC(auxil, size) packcr_malloc_e(size)
265
+ static void *packcr_malloc_e(size_t size) {
266
266
  void *const p = malloc(size);
267
267
  if (p == NULL) {
268
268
  fprintf(stderr, "Out of memory\n");
@@ -270,11 +270,11 @@ static void *pcc_malloc_e(size_t size) {
270
270
  }
271
271
  return p;
272
272
  }
273
- #endif /* !PCC_MALLOC */
273
+ #endif /* !PACKCR_MALLOC */
274
274
 
275
- #ifndef PCC_REALLOC
276
- #define PCC_REALLOC(auxil, ptr, size) pcc_realloc_e(ptr, size)
277
- static void *pcc_realloc_e(void *ptr, size_t size) {
275
+ #ifndef PACKCR_REALLOC
276
+ #define PACKCR_REALLOC(auxil, ptr, size) packcr_realloc_e(ptr, size)
277
+ static void *packcr_realloc_e(void *ptr, size_t size) {
278
278
  void *const p = realloc(ptr, size);
279
279
  if (p == NULL) {
280
280
  fprintf(stderr, "Out of memory\n");
@@ -282,259 +282,259 @@ static void *pcc_realloc_e(void *ptr, size_t size) {
282
282
  }
283
283
  return p;
284
284
  }
285
- #endif /* !PCC_REALLOC */
285
+ #endif /* !PACKCR_REALLOC */
286
286
 
287
- #ifndef PCC_FREE
288
- #define PCC_FREE(auxil, ptr) free(ptr)
289
- #endif /* !PCC_FREE */
287
+ #ifndef PACKCR_FREE
288
+ #define PACKCR_FREE(auxil, ptr) free(ptr)
289
+ #endif /* !PACKCR_FREE */
290
290
 
291
- #ifndef PCC_DEBUG
292
- #define PCC_DEBUG(auxil, event, rule, level, pos, buffer, length) ((void)0)
293
- #endif /* !PCC_DEBUG */
291
+ #ifndef PACKCR_DEBUG
292
+ #define PACKCR_DEBUG(auxil, event, rule, level, pos, buffer, length) ((void)0)
293
+ #endif /* !PACKCR_DEBUG */
294
294
 
295
- static char *pcc_strndup_e(pcc_auxil_t auxil, const char *str, size_t len) {
295
+ static char *packcr_strndup_e(packcr_auxil_t auxil, const char *str, size_t len) {
296
296
  const size_t m = strnlen(str, len);
297
- char *const s = (char *)PCC_MALLOC(auxil, m + 1);
297
+ char *const s = (char *)PACKCR_MALLOC(auxil, m + 1);
298
298
  memcpy(s, str, m);
299
299
  s[m] = '\0';
300
300
  return s;
301
301
  }
302
302
 
303
- static void pcc_char_array__init(pcc_auxil_t auxil, pcc_char_array_t *array) {
303
+ static void packcr_char_array__init(packcr_auxil_t auxil, packcr_char_array_t *array) {
304
304
  array->len = 0;
305
305
  array->max = 0;
306
306
  array->buf = NULL;
307
307
  }
308
308
 
309
- static void pcc_char_array__add(pcc_auxil_t auxil, pcc_char_array_t *array, char ch) {
309
+ static void packcr_char_array__add(packcr_auxil_t auxil, packcr_char_array_t *array, char ch) {
310
310
  if (array->max <= array->len) {
311
311
  const size_t n = array->len + 1;
312
312
  size_t m = array->max;
313
- if (m == 0) m = PCC_BUFFER_MIN_SIZE;
313
+ if (m == 0) m = PACKCR_BUFFER_MIN_SIZE;
314
314
  while (m < n && m != 0) m <<= 1;
315
315
  if (m == 0) m = n;
316
- array->buf = (char *)PCC_REALLOC(auxil, array->buf, m);
316
+ array->buf = (char *)PACKCR_REALLOC(auxil, array->buf, m);
317
317
  array->max = m;
318
318
  }
319
319
  array->buf[array->len++] = ch;
320
320
  }
321
321
 
322
- static void pcc_char_array__term(pcc_auxil_t auxil, pcc_char_array_t *array) {
323
- PCC_FREE(auxil, array->buf);
322
+ static void packcr_char_array__term(packcr_auxil_t auxil, packcr_char_array_t *array) {
323
+ PACKCR_FREE(auxil, array->buf);
324
324
  }
325
325
 
326
- static void pcc_value_table__init(pcc_auxil_t auxil, pcc_value_table_t *table) {
326
+ static void packcr_value_table__init(packcr_auxil_t auxil, packcr_value_table_t *table) {
327
327
  table->len = 0;
328
328
  table->max = 0;
329
329
  table->buf = NULL;
330
330
  }
331
331
 
332
332
  MARK_FUNC_AS_USED
333
- static void pcc_value_table__resize(pcc_auxil_t auxil, pcc_value_table_t *table, size_t len) {
333
+ static void packcr_value_table__resize(packcr_auxil_t auxil, packcr_value_table_t *table, size_t len) {
334
334
  if (table->max < len) {
335
335
  size_t m = table->max;
336
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
336
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
337
337
  while (m < len && m != 0) m <<= 1;
338
338
  if (m == 0) m = len;
339
- table->buf = (pcc_value_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t) * m);
339
+ table->buf = (packcr_value_t *)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_value_t) * m);
340
340
  table->max = m;
341
341
  }
342
342
  table->len = len;
343
343
  }
344
344
 
345
345
  MARK_FUNC_AS_USED
346
- static void pcc_value_table__clear(pcc_auxil_t auxil, pcc_value_table_t *table) {
347
- memset(table->buf, 0, sizeof(pcc_value_t) * table->len);
346
+ static void packcr_value_table__clear(packcr_auxil_t auxil, packcr_value_table_t *table) {
347
+ memset(table->buf, 0, sizeof(packcr_value_t) * table->len);
348
348
  }
349
349
 
350
- static void pcc_value_table__term(pcc_auxil_t auxil, pcc_value_table_t *table) {
351
- PCC_FREE(auxil, table->buf);
350
+ static void packcr_value_table__term(packcr_auxil_t auxil, packcr_value_table_t *table) {
351
+ PACKCR_FREE(auxil, table->buf);
352
352
  }
353
353
 
354
- static void pcc_value_refer_table__init(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
354
+ static void packcr_value_refer_table__init(packcr_auxil_t auxil, packcr_value_refer_table_t *table) {
355
355
  table->len = 0;
356
356
  table->max = 0;
357
357
  table->buf = NULL;
358
358
  }
359
359
 
360
- static void pcc_value_refer_table__resize(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t len) {
360
+ static void packcr_value_refer_table__resize(packcr_auxil_t auxil, packcr_value_refer_table_t *table, size_t len) {
361
361
  size_t i;
362
362
  if (table->max < len) {
363
363
  size_t m = table->max;
364
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
364
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
365
365
  while (m < len && m != 0) m <<= 1;
366
366
  if (m == 0) m = len;
367
- table->buf = (pcc_value_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t *) * m);
367
+ table->buf = (packcr_value_t **)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_value_t *) * m);
368
368
  table->max = m;
369
369
  }
370
370
  for (i = table->len; i < len; i++) table->buf[i] = NULL;
371
371
  table->len = len;
372
372
  }
373
373
 
374
- static void pcc_value_refer_table__term(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
375
- PCC_FREE(auxil, table->buf);
374
+ static void packcr_value_refer_table__term(packcr_auxil_t auxil, packcr_value_refer_table_t *table) {
375
+ PACKCR_FREE(auxil, table->buf);
376
376
  }
377
377
 
378
- static void pcc_capture_table__init(pcc_auxil_t auxil, pcc_capture_table_t *table) {
378
+ static void packcr_capture_table__init(packcr_auxil_t auxil, packcr_capture_table_t *table) {
379
379
  table->len = 0;
380
380
  table->max = 0;
381
381
  table->buf = NULL;
382
382
  }
383
383
 
384
384
  MARK_FUNC_AS_USED
385
- static void pcc_capture_table__resize(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t len) {
385
+ static void packcr_capture_table__resize(packcr_auxil_t auxil, packcr_capture_table_t *table, size_t len) {
386
386
  size_t i;
387
- for (i = len; i < table->len; i++) PCC_FREE(auxil, table->buf[i].string);
387
+ for (i = len; i < table->len; i++) PACKCR_FREE(auxil, table->buf[i].string);
388
388
  if (table->max < len) {
389
389
  size_t m = table->max;
390
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
390
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
391
391
  while (m < len && m != 0) m <<= 1;
392
392
  if (m == 0) m = len;
393
- table->buf = (pcc_capture_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_capture_t) * m);
393
+ table->buf = (packcr_capture_t *)PACKCR_REALLOC(auxil, table->buf, sizeof(packcr_capture_t) * m);
394
394
  table->max = m;
395
395
  }
396
396
  for (i = table->len; i < len; i++) {
397
397
  table->buf[i].range.start = 0;
398
398
  table->buf[i].range.end = 0;
399
399
  <%- if @location -%>
400
- pcc_location_init(&table->buf[i].range.start_loc);
401
- pcc_location_init(&table->buf[i].range.end_loc);
400
+ packcr_location_init(&table->buf[i].range.start_loc);
401
+ packcr_location_init(&table->buf[i].range.end_loc);
402
402
  <%- end -%>
403
403
  table->buf[i].string = NULL;
404
404
  }
405
405
  table->len = len;
406
406
  }
407
407
 
408
- static void pcc_capture_table__term(pcc_auxil_t auxil, pcc_capture_table_t *table) {
408
+ static void packcr_capture_table__term(packcr_auxil_t auxil, packcr_capture_table_t *table) {
409
409
  while (table->len > 0) {
410
410
  table->len--;
411
- PCC_FREE(auxil, table->buf[table->len].string);
411
+ PACKCR_FREE(auxil, table->buf[table->len].string);
412
412
  }
413
- PCC_FREE(auxil, table->buf);
413
+ PACKCR_FREE(auxil, table->buf);
414
414
  }
415
415
 
416
- static void pcc_capture_const_table__init(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
416
+ static void packcr_capture_const_table__init(packcr_auxil_t auxil, packcr_capture_const_table_t *table) {
417
417
  table->len = 0;
418
418
  table->max = 0;
419
419
  table->buf = NULL;
420
420
  }
421
421
 
422
- static void pcc_capture_const_table__resize(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t len) {
422
+ static void packcr_capture_const_table__resize(packcr_auxil_t auxil, packcr_capture_const_table_t *table, size_t len) {
423
423
  size_t i;
424
424
  if (table->max < len) {
425
425
  size_t m = table->max;
426
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
426
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
427
427
  while (m < len && m != 0) m <<= 1;
428
428
  if (m == 0) m = len;
429
- table->buf = (const pcc_capture_t **)PCC_REALLOC(auxil, (pcc_capture_t **)table->buf, sizeof(const pcc_capture_t *) * m);
429
+ table->buf = (const packcr_capture_t **)PACKCR_REALLOC(auxil, (packcr_capture_t **)table->buf, sizeof(const packcr_capture_t *) * m);
430
430
  table->max = m;
431
431
  }
432
432
  for (i = table->len; i < len; i++) table->buf[i] = NULL;
433
433
  table->len = len;
434
434
  }
435
435
 
436
- static void pcc_capture_const_table__term(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
437
- PCC_FREE(auxil, (void *)table->buf);
436
+ static void packcr_capture_const_table__term(packcr_auxil_t auxil, packcr_capture_const_table_t *table) {
437
+ PACKCR_FREE(auxil, (void *)table->buf);
438
438
  }
439
439
 
440
440
  MARK_FUNC_AS_USED
441
- static pcc_thunk_t *pcc_thunk__create_leaf(pcc_auxil_t auxil, pcc_action_t action, size_t valuec, size_t captc) {
442
- pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
443
- thunk->type = PCC_THUNK_LEAF;
444
- pcc_value_refer_table__init(auxil, &thunk->data.leaf.values);
445
- pcc_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
446
- pcc_capture_const_table__init(auxil, &thunk->data.leaf.capts);
447
- pcc_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
441
+ static packcr_thunk_t *packcr_thunk__create_leaf(packcr_auxil_t auxil, packcr_action_t action, size_t valuec, size_t captc) {
442
+ packcr_thunk_t *const thunk = (packcr_thunk_t *)PACKCR_MALLOC(auxil, sizeof(packcr_thunk_t));
443
+ thunk->type = PACKCR_THUNK_LEAF;
444
+ packcr_value_refer_table__init(auxil, &thunk->data.leaf.values);
445
+ packcr_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
446
+ packcr_capture_const_table__init(auxil, &thunk->data.leaf.capts);
447
+ packcr_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
448
448
  thunk->data.leaf.capt0.range.start = 0;
449
449
  thunk->data.leaf.capt0.range.end = 0;
450
450
  <%- if @location -%>
451
- pcc_location_init(&thunk->data.leaf.capt0.range.start_loc);
452
- pcc_location_init(&thunk->data.leaf.capt0.range.end_loc);
451
+ packcr_location_init(&thunk->data.leaf.capt0.range.start_loc);
452
+ packcr_location_init(&thunk->data.leaf.capt0.range.end_loc);
453
453
  <%- end -%>
454
454
  thunk->data.leaf.capt0.string = NULL;
455
455
  thunk->data.leaf.action = action;
456
456
  return thunk;
457
457
  }
458
458
 
459
- static pcc_thunk_t *pcc_thunk__create_node(pcc_auxil_t auxil, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
460
- pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
461
- thunk->type = PCC_THUNK_NODE;
459
+ static packcr_thunk_t *packcr_thunk__create_node(packcr_auxil_t auxil, const packcr_thunk_array_t *thunks, packcr_value_t *value) {
460
+ packcr_thunk_t *const thunk = (packcr_thunk_t *)PACKCR_MALLOC(auxil, sizeof(packcr_thunk_t));
461
+ thunk->type = PACKCR_THUNK_NODE;
462
462
  thunk->data.node.thunks = thunks;
463
463
  thunk->data.node.value = value;
464
464
  return thunk;
465
465
  }
466
466
 
467
- static void pcc_thunk__destroy(pcc_auxil_t auxil, pcc_thunk_t *thunk) {
467
+ static void packcr_thunk__destroy(packcr_auxil_t auxil, packcr_thunk_t *thunk) {
468
468
  if (thunk == NULL) return;
469
469
  switch (thunk->type) {
470
- case PCC_THUNK_LEAF:
471
- PCC_FREE(auxil, thunk->data.leaf.capt0.string);
472
- pcc_capture_const_table__term(auxil, &thunk->data.leaf.capts);
473
- pcc_value_refer_table__term(auxil, &thunk->data.leaf.values);
470
+ case PACKCR_THUNK_LEAF:
471
+ PACKCR_FREE(auxil, thunk->data.leaf.capt0.string);
472
+ packcr_capture_const_table__term(auxil, &thunk->data.leaf.capts);
473
+ packcr_value_refer_table__term(auxil, &thunk->data.leaf.values);
474
474
  break;
475
- case PCC_THUNK_NODE:
475
+ case PACKCR_THUNK_NODE:
476
476
  break;
477
477
  default: /* unknown */
478
478
  break;
479
479
  }
480
- PCC_FREE(auxil, thunk);
480
+ PACKCR_FREE(auxil, thunk);
481
481
  }
482
482
 
483
- static void pcc_thunk_array__init(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
483
+ static void packcr_thunk_array__init(packcr_auxil_t auxil, packcr_thunk_array_t *array) {
484
484
  array->len = 0;
485
485
  array->max = 0;
486
486
  array->buf = NULL;
487
487
  }
488
488
 
489
- static void pcc_thunk_array__add(pcc_auxil_t auxil, pcc_thunk_array_t *array, pcc_thunk_t *thunk) {
489
+ static void packcr_thunk_array__add(packcr_auxil_t auxil, packcr_thunk_array_t *array, packcr_thunk_t *thunk) {
490
490
  if (array->max <= array->len) {
491
491
  const size_t n = array->len + 1;
492
492
  size_t m = array->max;
493
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
493
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
494
494
  while (m < n && m != 0) m <<= 1;
495
495
  if (m == 0) m = n;
496
- array->buf = (pcc_thunk_t **)PCC_REALLOC(auxil, array->buf, sizeof(pcc_thunk_t *) * m);
496
+ array->buf = (packcr_thunk_t **)PACKCR_REALLOC(auxil, array->buf, sizeof(packcr_thunk_t *) * m);
497
497
  array->max = m;
498
498
  }
499
499
  array->buf[array->len++] = thunk;
500
500
  }
501
501
 
502
- static void pcc_thunk_array__revert(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t len) {
502
+ static void packcr_thunk_array__revert(packcr_auxil_t auxil, packcr_thunk_array_t *array, size_t len) {
503
503
  while (array->len > len) {
504
504
  array->len--;
505
- pcc_thunk__destroy(auxil, array->buf[array->len]);
505
+ packcr_thunk__destroy(auxil, array->buf[array->len]);
506
506
  }
507
507
  }
508
508
 
509
- static void pcc_thunk_array__term(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
509
+ static void packcr_thunk_array__term(packcr_auxil_t auxil, packcr_thunk_array_t *array) {
510
510
  while (array->len > 0) {
511
511
  array->len--;
512
- pcc_thunk__destroy(auxil, array->buf[array->len]);
512
+ packcr_thunk__destroy(auxil, array->buf[array->len]);
513
513
  }
514
- PCC_FREE(auxil, array->buf);
514
+ PACKCR_FREE(auxil, array->buf);
515
515
  }
516
516
 
517
- static void pcc_memory_recycler__init(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler, size_t element_size) {
517
+ static void packcr_memory_recycler__init(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler, size_t element_size) {
518
518
  recycler->pool_list = NULL;
519
519
  recycler->entry_list = NULL;
520
520
  recycler->element_size = element_size;
521
521
  }
522
522
 
523
- static void *pcc_memory_recycler__supply(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler) {
523
+ static void *packcr_memory_recycler__supply(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler) {
524
524
  if (recycler->entry_list) {
525
- pcc_memory_entry_t *const tmp = recycler->entry_list;
525
+ packcr_memory_entry_t *const tmp = recycler->entry_list;
526
526
  recycler->entry_list = tmp->next;
527
527
  return tmp;
528
528
  }
529
529
  if (!recycler->pool_list || recycler->pool_list->unused == 0) {
530
- size_t size = PCC_POOL_MIN_SIZE;
530
+ size_t size = PACKCR_POOL_MIN_SIZE;
531
531
  if (recycler->pool_list) {
532
532
  size = recycler->pool_list->allocated << 1;
533
533
  if (size == 0) size = recycler->pool_list->allocated;
534
534
  }
535
535
  {
536
- pcc_memory_pool_t *const pool = (pcc_memory_pool_t *)PCC_MALLOC(
537
- auxil, sizeof(pcc_memory_pool_t) + recycler->element_size * size
536
+ packcr_memory_pool_t *const pool = (packcr_memory_pool_t *)PACKCR_MALLOC(
537
+ auxil, sizeof(packcr_memory_pool_t) + recycler->element_size * size
538
538
  );
539
539
  pool->allocated = size;
540
540
  pool->unused = size;
@@ -543,136 +543,136 @@ static void *pcc_memory_recycler__supply(pcc_auxil_t auxil, pcc_memory_recycler_
543
543
  }
544
544
  }
545
545
  recycler->pool_list->unused--;
546
- return (char *)recycler->pool_list + sizeof(pcc_memory_pool_t) + recycler->element_size * recycler->pool_list->unused;
546
+ return (char *)recycler->pool_list + sizeof(packcr_memory_pool_t) + recycler->element_size * recycler->pool_list->unused;
547
547
  }
548
548
 
549
- static void pcc_memory_recycler__recycle(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler, void *ptr) {
550
- pcc_memory_entry_t *const tmp = (pcc_memory_entry_t *)ptr;
549
+ static void packcr_memory_recycler__recycle(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler, void *ptr) {
550
+ packcr_memory_entry_t *const tmp = (packcr_memory_entry_t *)ptr;
551
551
  tmp->next = recycler->entry_list;
552
552
  recycler->entry_list = tmp;
553
553
  }
554
554
 
555
- static void pcc_memory_recycler__term(pcc_auxil_t auxil, pcc_memory_recycler_t *recycler) {
555
+ static void packcr_memory_recycler__term(packcr_auxil_t auxil, packcr_memory_recycler_t *recycler) {
556
556
  while (recycler->pool_list) {
557
- pcc_memory_pool_t *const tmp = recycler->pool_list;
557
+ packcr_memory_pool_t *const tmp = recycler->pool_list;
558
558
  recycler->pool_list = tmp->next;
559
- PCC_FREE(auxil, tmp);
559
+ PACKCR_FREE(auxil, tmp);
560
560
  }
561
561
  }
562
562
 
563
563
  MARK_FUNC_AS_USED
564
- static pcc_thunk_chunk_t *pcc_thunk_chunk__create(pcc_context_t *ctx) {
565
- pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)pcc_memory_recycler__supply(ctx->auxil, &ctx->thunk_chunk_recycler);
566
- pcc_value_table__init(ctx->auxil, &chunk->values);
567
- pcc_capture_table__init(ctx->auxil, &chunk->capts);
568
- pcc_thunk_array__init(ctx->auxil, &chunk->thunks);
564
+ static packcr_thunk_chunk_t *packcr_thunk_chunk__create(packcr_context_t *ctx) {
565
+ packcr_thunk_chunk_t *const chunk = (packcr_thunk_chunk_t *)packcr_memory_recycler__supply(ctx->auxil, &ctx->thunk_chunk_recycler);
566
+ packcr_value_table__init(ctx->auxil, &chunk->values);
567
+ packcr_capture_table__init(ctx->auxil, &chunk->capts);
568
+ packcr_thunk_array__init(ctx->auxil, &chunk->thunks);
569
569
  chunk->pos = 0;
570
570
  return chunk;
571
571
  }
572
572
 
573
- static void pcc_thunk_chunk__destroy(pcc_context_t *ctx, pcc_thunk_chunk_t *chunk) {
573
+ static void packcr_thunk_chunk__destroy(packcr_context_t *ctx, packcr_thunk_chunk_t *chunk) {
574
574
  if (chunk == NULL) return;
575
- pcc_thunk_array__term(ctx->auxil, &chunk->thunks);
576
- pcc_capture_table__term(ctx->auxil, &chunk->capts);
577
- pcc_value_table__term(ctx->auxil, &chunk->values);
578
- pcc_memory_recycler__recycle(ctx->auxil, &ctx->thunk_chunk_recycler, chunk);
575
+ packcr_thunk_array__term(ctx->auxil, &chunk->thunks);
576
+ packcr_capture_table__term(ctx->auxil, &chunk->capts);
577
+ packcr_value_table__term(ctx->auxil, &chunk->values);
578
+ packcr_memory_recycler__recycle(ctx->auxil, &ctx->thunk_chunk_recycler, chunk);
579
579
  }
580
580
 
581
- static void pcc_rule_set__init(pcc_auxil_t auxil, pcc_rule_set_t *set) {
581
+ static void packcr_rule_set__init(packcr_auxil_t auxil, packcr_rule_set_t *set) {
582
582
  set->len = 0;
583
583
  set->max = 0;
584
584
  set->buf = NULL;
585
585
  }
586
586
 
587
- static size_t pcc_rule_set__index(pcc_auxil_t auxil, const pcc_rule_set_t *set, pcc_rule_t rule) {
587
+ static size_t packcr_rule_set__index(packcr_auxil_t auxil, const packcr_rule_set_t *set, packcr_rule_t rule) {
588
588
  size_t i;
589
589
  for (i = 0; i < set->len; i++) {
590
590
  if (set->buf[i] == rule) return i;
591
591
  }
592
- return PCC_VOID_VALUE;
592
+ return PACKCR_VOID_VALUE;
593
593
  }
594
594
 
595
- static pcc_bool_t pcc_rule_set__add(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
596
- const size_t i = pcc_rule_set__index(auxil, set, rule);
597
- if (i != PCC_VOID_VALUE) return PCC_FALSE;
595
+ static packcr_bool_t packcr_rule_set__add(packcr_auxil_t auxil, packcr_rule_set_t *set, packcr_rule_t rule) {
596
+ const size_t i = packcr_rule_set__index(auxil, set, rule);
597
+ if (i != PACKCR_VOID_VALUE) return PACKCR_FALSE;
598
598
  if (set->max <= set->len) {
599
599
  const size_t n = set->len + 1;
600
600
  size_t m = set->max;
601
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
601
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
602
602
  while (m < n && m != 0) m <<= 1;
603
603
  if (m == 0) m = n;
604
- set->buf = (pcc_rule_t *)PCC_REALLOC(auxil, set->buf, sizeof(pcc_rule_t) * m);
604
+ set->buf = (packcr_rule_t *)PACKCR_REALLOC(auxil, set->buf, sizeof(packcr_rule_t) * m);
605
605
  set->max = m;
606
606
  }
607
607
  set->buf[set->len++] = rule;
608
- return PCC_TRUE;
608
+ return PACKCR_TRUE;
609
609
  }
610
610
 
611
- static void pcc_rule_set__term(pcc_auxil_t auxil, pcc_rule_set_t *set) {
612
- PCC_FREE(auxil, set->buf);
611
+ static void packcr_rule_set__term(packcr_auxil_t auxil, packcr_rule_set_t *set) {
612
+ PACKCR_FREE(auxil, set->buf);
613
613
  }
614
614
 
615
- static pcc_lr_memo_t *pcc_lr_memo__create(pcc_context_t *ctx, size_t offset<% if @location %>, pcc_location_t offset_loc<% end %>) {
616
- pcc_lr_memo_t *memo = (pcc_lr_memo_t *)pcc_memory_recycler__supply(ctx->auxil, &ctx->lr_memo_recycler);
615
+ static packcr_lr_memo_t *packcr_lr_memo__create(packcr_context_t *ctx, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>) {
616
+ packcr_lr_memo_t *memo = (packcr_lr_memo_t *)packcr_memory_recycler__supply(ctx->auxil, &ctx->lr_memo_recycler);
617
617
  memo->offset = offset;
618
618
  <%- if @location -%>
619
619
  memo->offset_loc = offset_loc;
620
620
  <%- end -%>
621
621
  memo->chunk = NULL;
622
- memo->fail = PCC_TRUE;
623
- memo->grow = PCC_FALSE;
622
+ memo->fail = PACKCR_TRUE;
623
+ memo->grow = PACKCR_FALSE;
624
624
  memo->hold = NULL;
625
625
  return memo;
626
626
  }
627
627
 
628
- static void pcc_lr_memo__set_chunk(pcc_context_t *ctx, pcc_lr_memo_t *memo, pcc_thunk_chunk_t *chunk) {
628
+ static void packcr_lr_memo__set_chunk(packcr_context_t *ctx, packcr_lr_memo_t *memo, packcr_thunk_chunk_t *chunk) {
629
629
  if (memo->chunk) {
630
- pcc_lr_memo_t *const a = pcc_lr_memo__create(ctx, memo->offset<% if @location %>, memo->offset_loc<% end %>);
631
- a->chunk = memo->chunk;
632
- a->hold = memo->hold;
633
- memo->hold = a;
630
+ packcr_lr_memo_t *const new_hold_memo = packcr_lr_memo__create(ctx, memo->offset<% if @location %>, memo->offset_loc<% end %>);
631
+ new_hold_memo->chunk = memo->chunk;
632
+ new_hold_memo->hold = memo->hold;
633
+ memo->hold = new_hold_memo;
634
634
  }
635
635
  memo->chunk = chunk;
636
- memo->fail = PCC_FALSE;
636
+ memo->fail = PACKCR_FALSE;
637
637
  }
638
638
 
639
- static void pcc_lr_memo__destroy(pcc_context_t *ctx, pcc_lr_memo_t *memo) {
639
+ static void packcr_lr_memo__destroy(packcr_context_t *ctx, packcr_lr_memo_t *memo) {
640
640
  while (memo != NULL) {
641
- pcc_lr_memo_t *const a = memo->hold;
642
- pcc_thunk_chunk__destroy(ctx, memo->chunk);
643
- pcc_memory_recycler__recycle(ctx->auxil, &ctx->lr_memo_recycler, memo);
644
- memo = a;
641
+ packcr_lr_memo_t *const hold_memo = memo->hold;
642
+ packcr_thunk_chunk__destroy(ctx, memo->chunk);
643
+ packcr_memory_recycler__recycle(ctx->auxil, &ctx->lr_memo_recycler, memo);
644
+ memo = hold_memo;
645
645
  }
646
646
  }
647
647
 
648
- static void pcc_lr_memo_map__init(pcc_auxil_t auxil, pcc_lr_memo_map_t *map) {
648
+ static void packcr_lr_memo_map__init(packcr_auxil_t auxil, packcr_lr_memo_map_t *map) {
649
649
  map->len = 0;
650
650
  map->max = 0;
651
651
  map->buf = NULL;
652
652
  }
653
653
 
654
- static size_t pcc_lr_memo_map__index(pcc_context_t *ctx, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
654
+ static size_t packcr_lr_memo_map__index(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule) {
655
655
  size_t i;
656
656
  for (i = 0; i < map->len; i++) {
657
657
  if (map->buf[i].rule == rule) return i;
658
658
  }
659
- return PCC_VOID_VALUE;
659
+ return PACKCR_VOID_VALUE;
660
660
  }
661
661
 
662
- static void pcc_lr_memo_map__put(pcc_context_t *ctx, pcc_lr_memo_map_t *map, pcc_rule_t rule, pcc_lr_memo_t *memo) {
663
- const size_t i = pcc_lr_memo_map__index(ctx, map, rule);
664
- if (i != PCC_VOID_VALUE) {
665
- pcc_lr_memo__destroy(ctx, map->buf[i].memo);
662
+ static void packcr_lr_memo_map__put(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule, packcr_lr_memo_t *memo) {
663
+ const size_t i = packcr_lr_memo_map__index(ctx, map, rule);
664
+ if (i != PACKCR_VOID_VALUE) {
665
+ packcr_lr_memo__destroy(ctx, map->buf[i].memo);
666
666
  map->buf[i].memo = memo;
667
667
  }
668
668
  else {
669
669
  if (map->max <= map->len) {
670
670
  const size_t n = map->len + 1;
671
671
  size_t m = map->max;
672
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
672
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
673
673
  while (m < n && m != 0) m <<= 1;
674
674
  if (m == 0) m = n;
675
- map->buf = (pcc_lr_memo_map_entry_t *)PCC_REALLOC(ctx->auxil, map->buf, sizeof(pcc_lr_memo_map_entry_t) * m);
675
+ map->buf = (packcr_lr_memo_map_entry_t *)PACKCR_REALLOC(ctx->auxil, map->buf, sizeof(packcr_lr_memo_map_entry_t) * m);
676
676
  map->max = m;
677
677
  }
678
678
  map->buf[map->len].rule = rule;
@@ -681,156 +681,156 @@ static void pcc_lr_memo_map__put(pcc_context_t *ctx, pcc_lr_memo_map_t *map, pcc
681
681
  }
682
682
  }
683
683
 
684
- static pcc_lr_memo_t *pcc_lr_memo_map__get(pcc_context_t *ctx, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
685
- const size_t i = pcc_lr_memo_map__index(ctx, map, rule);
686
- return (i != PCC_VOID_VALUE) ? map->buf[i].memo : NULL;
684
+ static packcr_lr_memo_t *packcr_lr_memo_map__get(packcr_context_t *ctx, packcr_lr_memo_map_t *map, packcr_rule_t rule) {
685
+ const size_t i = packcr_lr_memo_map__index(ctx, map, rule);
686
+ return (i != PACKCR_VOID_VALUE) ? map->buf[i].memo : NULL;
687
687
  }
688
688
 
689
- static void pcc_lr_memo_map__term(pcc_context_t *ctx, pcc_lr_memo_map_t *map) {
689
+ static void packcr_lr_memo_map__term(packcr_context_t *ctx, packcr_lr_memo_map_t *map) {
690
690
  while (map->len > 0) {
691
691
  map->len--;
692
- pcc_lr_memo__destroy(ctx, map->buf[map->len].memo);
692
+ packcr_lr_memo__destroy(ctx, map->buf[map->len].memo);
693
693
  }
694
- PCC_FREE(ctx->auxil, map->buf);
694
+ PACKCR_FREE(ctx->auxil, map->buf);
695
695
  }
696
696
 
697
- static pcc_lr_memo_map_t *pcc_lr_memo_map__create(pcc_context_t *ctx) {
698
- pcc_lr_memo_map_t *const memo = (pcc_lr_memo_map_t *)PCC_MALLOC(ctx->auxil, sizeof(pcc_lr_memo_map_t));
699
- pcc_lr_memo_map__init(ctx->auxil, memo);
697
+ static packcr_lr_memo_map_t *packcr_lr_memo_map__create(packcr_context_t *ctx) {
698
+ packcr_lr_memo_map_t *const memo = (packcr_lr_memo_map_t *)PACKCR_MALLOC(ctx->auxil, sizeof(packcr_lr_memo_map_t));
699
+ packcr_lr_memo_map__init(ctx->auxil, memo);
700
700
  return memo;
701
701
  }
702
702
 
703
- static void pcc_lr_memo_map__destroy(pcc_context_t *ctx, pcc_lr_memo_map_t *memo) {
703
+ static void packcr_lr_memo_map__destroy(packcr_context_t *ctx, packcr_lr_memo_map_t *memo) {
704
704
  if (memo == NULL) return;
705
- pcc_lr_memo_map__term(ctx, memo);
706
- PCC_FREE(ctx->auxil, memo);
705
+ packcr_lr_memo_map__term(ctx, memo);
706
+ PACKCR_FREE(ctx->auxil, memo);
707
707
  }
708
708
 
709
- static void pcc_lr_table__init(pcc_auxil_t auxil, pcc_lr_table_t *table) {
709
+ static void packcr_lr_table__init(packcr_auxil_t auxil, packcr_lr_table_t *table) {
710
710
  table->ofs = 0;
711
711
  table->len = 0;
712
712
  table->max = 0;
713
713
  table->buf = NULL;
714
714
  }
715
715
 
716
- static void pcc_lr_table__resize(pcc_context_t *ctx, pcc_lr_table_t *table, size_t len) {
716
+ static void packcr_lr_table__resize(packcr_context_t *ctx, packcr_lr_table_t *table, size_t len) {
717
717
  size_t i;
718
- for (i = len; i < table->len; i++) pcc_lr_memo_map__destroy(ctx, table->buf[i]);
718
+ for (i = len; i < table->len; i++) packcr_lr_memo_map__destroy(ctx, table->buf[i]);
719
719
  if (table->max < len) {
720
720
  size_t m = table->max;
721
- if (m == 0) m = PCC_ARRAY_MIN_SIZE;
721
+ if (m == 0) m = PACKCR_ARRAY_MIN_SIZE;
722
722
  while (m < len && m != 0) m <<= 1;
723
723
  if (m == 0) m = len;
724
- table->buf = (pcc_lr_memo_map_t **)PCC_REALLOC(ctx->auxil, table->buf, sizeof(pcc_lr_memo_map_t *) * m);
724
+ table->buf = (packcr_lr_memo_map_t **)PACKCR_REALLOC(ctx->auxil, table->buf, sizeof(packcr_lr_memo_map_t *) * m);
725
725
  table->max = m;
726
726
  }
727
727
  for (i = table->len; i < len; i++) table->buf[i] = NULL;
728
728
  table->len = len;
729
729
  }
730
730
 
731
- static void pcc_lr_table__set_memo(pcc_context_t *ctx, pcc_lr_table_t *table, size_t index, pcc_rule_t rule, pcc_lr_memo_t *memo) {
731
+ static void packcr_lr_table__set_memo(packcr_context_t *ctx, packcr_lr_table_t *table, size_t index, packcr_rule_t rule, packcr_lr_memo_t *memo) {
732
732
  index += table->ofs;
733
- if (index >= table->len) pcc_lr_table__resize(ctx, table, index + 1);
734
- if (table->buf[index] == NULL) table->buf[index] = pcc_lr_memo_map__create(ctx);
735
- pcc_lr_memo_map__put(ctx, table->buf[index], rule, memo);
733
+ if (index >= table->len) packcr_lr_table__resize(ctx, table, index + 1);
734
+ if (table->buf[index] == NULL) table->buf[index] = packcr_lr_memo_map__create(ctx);
735
+ packcr_lr_memo_map__put(ctx, table->buf[index], rule, memo);
736
736
  }
737
737
 
738
- static pcc_lr_memo_t *pcc_lr_table__get_memo(pcc_context_t *ctx, pcc_lr_table_t *table, size_t index, pcc_rule_t rule) {
738
+ static packcr_lr_memo_t *packcr_lr_table__get_memo(packcr_context_t *ctx, packcr_lr_table_t *table, size_t index, packcr_rule_t rule) {
739
739
  index += table->ofs;
740
740
  if (index >= table->len || table->buf[index] == NULL) return NULL;
741
- return pcc_lr_memo_map__get(ctx, table->buf[index], rule);
741
+ return packcr_lr_memo_map__get(ctx, table->buf[index], rule);
742
742
  }
743
743
 
744
- static void pcc_lr_table__shift(pcc_context_t *ctx, pcc_lr_table_t *table, size_t count) {
744
+ static void packcr_lr_table__shift(packcr_context_t *ctx, packcr_lr_table_t *table, size_t count) {
745
745
  size_t i;
746
746
  if (count > table->len - table->ofs) count = table->len - table->ofs;
747
- for (i = 0; i < count; i++) pcc_lr_memo_map__destroy(ctx, table->buf[table->ofs++]);
747
+ for (i = 0; i < count; i++) packcr_lr_memo_map__destroy(ctx, table->buf[table->ofs++]);
748
748
  if (table->ofs > (table->max >> 1)) {
749
- memmove(table->buf, table->buf + table->ofs, sizeof(pcc_lr_memo_map_t *) * (table->len - table->ofs));
749
+ memmove(table->buf, table->buf + table->ofs, sizeof(packcr_lr_memo_map_t *) * (table->len - table->ofs));
750
750
  table->len -= table->ofs;
751
751
  table->ofs = 0;
752
752
  }
753
753
  }
754
754
 
755
- static void pcc_lr_table__term(pcc_context_t *ctx, pcc_lr_table_t *table) {
755
+ static void packcr_lr_table__term(packcr_context_t *ctx, packcr_lr_table_t *table) {
756
756
  while (table->len > table->ofs) {
757
757
  table->len--;
758
- pcc_lr_memo_map__destroy(ctx, table->buf[table->len]);
758
+ packcr_lr_memo_map__destroy(ctx, table->buf[table->len]);
759
759
  }
760
- PCC_FREE(ctx->auxil, table->buf);
760
+ PACKCR_FREE(ctx->auxil, table->buf);
761
761
  }
762
762
 
763
- static pcc_context_t *pcc_context__create(pcc_auxil_t auxil) {
764
- pcc_context_t *const ctx = (pcc_context_t *)PCC_MALLOC(auxil, sizeof(pcc_context_t));
763
+ static packcr_context_t *packcr_context__create(packcr_auxil_t auxil) {
764
+ packcr_context_t *const ctx = (packcr_context_t *)PACKCR_MALLOC(auxil, sizeof(packcr_context_t));
765
765
  ctx->buffer_start_position = 0;
766
766
  ctx->position_offset = 0;
767
767
  <%- if @location -%>
768
- pcc_location_init(&ctx->buffer_start_position_loc);
769
- pcc_location_init(&ctx->position_offset_loc);
768
+ packcr_location_init(&ctx->buffer_start_position_loc);
769
+ packcr_location_init(&ctx->position_offset_loc);
770
770
  <%- end -%>
771
771
  ctx->level = 0;
772
- pcc_char_array__init(auxil, &ctx->buffer);
773
- pcc_lr_table__init(auxil, &ctx->lrtable);
774
- pcc_thunk_array__init(auxil, &ctx->thunks);
775
- pcc_memory_recycler__init(auxil, &ctx->thunk_chunk_recycler, sizeof(pcc_thunk_chunk_t));
776
- pcc_memory_recycler__init(auxil, &ctx->lr_memo_recycler, sizeof(pcc_lr_memo_t));
772
+ packcr_char_array__init(auxil, &ctx->buffer);
773
+ packcr_lr_table__init(auxil, &ctx->lrtable);
774
+ packcr_thunk_array__init(auxil, &ctx->thunks);
775
+ packcr_memory_recycler__init(auxil, &ctx->thunk_chunk_recycler, sizeof(packcr_thunk_chunk_t));
776
+ packcr_memory_recycler__init(auxil, &ctx->lr_memo_recycler, sizeof(packcr_lr_memo_t));
777
777
  ctx->auxil = auxil;
778
778
  return ctx;
779
779
  }
780
780
 
781
- static void pcc_context__destroy(pcc_context_t *ctx) {
781
+ static void packcr_context__destroy(packcr_context_t *ctx) {
782
782
  if (ctx == NULL) return;
783
- pcc_thunk_array__term(ctx->auxil, &ctx->thunks);
784
- pcc_lr_table__term(ctx, &ctx->lrtable);
785
- pcc_char_array__term(ctx->auxil, &ctx->buffer);
786
- pcc_memory_recycler__term(ctx->auxil, &ctx->thunk_chunk_recycler);
787
- pcc_memory_recycler__term(ctx->auxil, &ctx->lr_memo_recycler);
788
- PCC_FREE(ctx->auxil, ctx);
783
+ packcr_thunk_array__term(ctx->auxil, &ctx->thunks);
784
+ packcr_lr_table__term(ctx, &ctx->lrtable);
785
+ packcr_char_array__term(ctx->auxil, &ctx->buffer);
786
+ packcr_memory_recycler__term(ctx->auxil, &ctx->thunk_chunk_recycler);
787
+ packcr_memory_recycler__term(ctx->auxil, &ctx->lr_memo_recycler);
788
+ PACKCR_FREE(ctx->auxil, ctx);
789
789
  }
790
790
 
791
- static size_t pcc_refill_buffer(pcc_context_t *ctx, size_t num) {
791
+ static size_t packcr_refill_buffer(packcr_context_t *ctx, size_t num) {
792
792
  if (ctx->buffer.len >= ctx->position_offset + num) return ctx->buffer.len - ctx->position_offset;
793
793
  while (ctx->buffer.len < ctx->position_offset + num) {
794
- const int c = PCC_GETCHAR(ctx->auxil);
794
+ const int c = PACKCR_GETCHAR(ctx->auxil);
795
795
  if (c < 0) break;
796
- pcc_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
796
+ packcr_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
797
797
  }
798
798
  return ctx->buffer.len - ctx->position_offset;
799
799
  }
800
800
 
801
801
  MARK_FUNC_AS_USED
802
- static void pcc_commit_buffer(pcc_context_t *ctx) {
802
+ static void packcr_commit_buffer(packcr_context_t *ctx) {
803
803
  memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->position_offset, ctx->buffer.len - ctx->position_offset);
804
804
  ctx->buffer.len -= ctx->position_offset;
805
805
  ctx->buffer_start_position += ctx->position_offset;
806
- pcc_lr_table__shift(ctx, &ctx->lrtable, ctx->position_offset);
806
+ packcr_lr_table__shift(ctx, &ctx->lrtable, ctx->position_offset);
807
807
  ctx->position_offset = 0;
808
808
  <%- if @location -%>
809
- ctx->buffer_start_position_loc = pcc_location_add(ctx->buffer_start_position_loc, ctx->position_offset_loc);
810
- pcc_location_init(&ctx->position_offset_loc);
809
+ ctx->buffer_start_position_loc = packcr_location_add(ctx->buffer_start_position_loc, ctx->position_offset_loc);
810
+ packcr_location_init(&ctx->position_offset_loc);
811
811
  <%- end -%>
812
812
  }
813
813
 
814
814
  MARK_FUNC_AS_USED
815
- static const char *pcc_get_capture_string(pcc_context_t *ctx, const pcc_capture_t *capt) {
815
+ static const char *packcr_get_capture_string(packcr_context_t *ctx, const packcr_capture_t *capt) {
816
816
  if (capt->string == NULL)
817
- ((pcc_capture_t *)capt)->string =
818
- pcc_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
817
+ ((packcr_capture_t *)capt)->string =
818
+ packcr_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
819
819
  return capt->string;
820
820
  }
821
821
 
822
822
  <% if @utf8 -%>
823
- static size_t pcc_get_char_as_utf32(pcc_context_t *ctx, int *out) { /* with checking UTF-8 validity */
823
+ static size_t packcr_get_char_as_utf32(packcr_context_t *ctx, int *out) { /* with checking UTF-8 validity */
824
824
  int c, u;
825
825
  size_t n;
826
- if (pcc_refill_buffer(ctx, 1) < 1) return 0;
826
+ if (packcr_refill_buffer(ctx, 1) < 1) return 0;
827
827
  c = (int)(unsigned char)ctx->buffer.buf[ctx->position_offset];
828
828
  n = (c < 0x80) ? 1 :
829
829
  ((c & 0xe0) == 0xc0) ? 2 :
830
830
  ((c & 0xf0) == 0xe0) ? 3 :
831
831
  ((c & 0xf8) == 0xf0) ? 4 : 0;
832
832
  if (n < 1) return 0;
833
- if (pcc_refill_buffer(ctx, n) < n) return 0;
833
+ if (packcr_refill_buffer(ctx, n) < n) return 0;
834
834
  switch (n) {
835
835
  case 1:
836
836
  u = c;
@@ -873,28 +873,28 @@ static size_t pcc_get_char_as_utf32(pcc_context_t *ctx, int *out) { /* with chec
873
873
  }
874
874
 
875
875
  <% end -%>
876
- static void pcc_grow_lr(pcc_context_t *ctx, pcc_rule_t rule, size_t offset<% if @location %>, pcc_location_t offset_loc<% end %>) {
876
+ static void packcr_grow_lr(packcr_context_t *ctx, packcr_rule_t rule, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>) {
877
877
  while(1) {
878
878
  const size_t old_offset = ctx->position_offset;
879
- pcc_thunk_chunk_t *chunk;
880
- pcc_lr_memo_t *memo;
881
- pcc_rule_set_t limits;
879
+ packcr_thunk_chunk_t *chunk;
880
+ packcr_lr_memo_t *memo;
881
+ packcr_rule_set_t limits;
882
882
  ctx->position_offset = offset;
883
883
  <%- if @location -%>
884
884
  ctx->position_offset_loc = offset_loc;
885
885
  <%- end -%>
886
- pcc_rule_set__init(ctx->auxil, &limits);
887
- pcc_rule_set__add(ctx->auxil, &limits, rule);
886
+ packcr_rule_set__init(ctx->auxil, &limits);
887
+ packcr_rule_set__add(ctx->auxil, &limits, rule);
888
888
  chunk = rule(ctx, offset<% if @location %>, offset_loc<% end %>, &limits);
889
- pcc_rule_set__term(ctx->auxil, &limits);
889
+ packcr_rule_set__term(ctx->auxil, &limits);
890
890
  if (!chunk)
891
891
  break;
892
892
  if (ctx->position_offset <= old_offset) {
893
- pcc_thunk_chunk__destroy(ctx, chunk);
893
+ packcr_thunk_chunk__destroy(ctx, chunk);
894
894
  break;
895
895
  }
896
- memo = pcc_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
897
- pcc_lr_memo__set_chunk(ctx, memo, chunk);
896
+ memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
897
+ packcr_lr_memo__set_chunk(ctx, memo, chunk);
898
898
  memo->offset = ctx->position_offset;
899
899
  <%- if @location -%>
900
900
  memo->offset_loc = ctx->position_offset_loc;
@@ -903,76 +903,90 @@ static void pcc_grow_lr(pcc_context_t *ctx, pcc_rule_t rule, size_t offset<% if
903
903
  }
904
904
 
905
905
  MARK_FUNC_AS_USED
906
- static pcc_thunk_chunk_t *pcc_get_rule_thunk_chunk(pcc_context_t *ctx, pcc_rule_t rule) {
907
- pcc_thunk_chunk_t *c = NULL;
906
+ static packcr_thunk_chunk_t *packcr_get_rule_thunk_chunk(packcr_context_t *ctx, packcr_rule_t rule) {
907
+ packcr_thunk_chunk_t *c = NULL;
908
908
  size_t offset = ctx->position_offset;
909
909
  <%- if @location -%>
910
- pcc_location_t offset_loc = ctx->position_offset_loc;
910
+ packcr_location_t offset_loc = ctx->position_offset_loc;
911
911
  <%- end -%>
912
- pcc_lr_memo_t *a = pcc_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
912
+ packcr_lr_memo_t *memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
913
913
 
914
- if (a == NULL) {
915
- a = pcc_lr_memo__create(ctx, offset<% if @location %>, offset_loc<% end %>);
916
- pcc_lr_table__set_memo(ctx, &ctx->lrtable, offset, rule, a);
914
+ if (memo == NULL) {
915
+ memo = packcr_lr_memo__create(ctx, offset<% if @location %>, offset_loc<% end %>);
916
+ packcr_lr_table__set_memo(ctx, &ctx->lrtable, offset, rule, memo);
917
917
  c = rule(ctx, offset<% if @location %>, offset_loc<% end %>, NULL);
918
- pcc_lr_memo__set_chunk(ctx, a, c);
919
- a->offset = ctx->position_offset;
918
+ packcr_lr_memo__set_chunk(ctx, memo, c);
919
+ memo->offset = ctx->position_offset;
920
+ <%- if @location -%>
921
+ memo->offset_loc = ctx->position_offset_loc;
922
+ <%- end -%>
923
+ if (memo->grow) {
924
+ packcr_grow_lr(ctx, rule, offset<% if @location %>, offset_loc<% end %>);
925
+ memo->grow = PACKCR_FALSE;
926
+ ctx->position_offset = memo->offset;
920
927
  <%- if @location -%>
921
- a->offset_loc = ctx->position_offset_loc;
928
+ ctx->position_offset_loc = memo->offset_loc;
922
929
  <%- end -%>
923
- if (a->grow) {
924
- pcc_grow_lr(ctx, rule, offset<% if @location %>, offset_loc<% end %>);
925
- a->grow = PCC_FALSE;
926
- ctx->position_offset = a->offset;
927
- return a->chunk;
930
+ return memo->chunk;
928
931
  }
929
932
  return c;
930
- } else if (a->fail) {
931
- pcc_lr_memo__set_chunk(ctx, a, NULL);
932
- a->grow = PCC_TRUE;
933
+ } else if (memo->fail) {
934
+ packcr_lr_memo__set_chunk(ctx, memo, NULL);
935
+ memo->grow = PACKCR_TRUE;
933
936
  return NULL;
934
937
  }
935
- ctx->position_offset = a->offset;
936
- return a->chunk;
938
+ ctx->position_offset = memo->offset;
939
+ <%- if @location -%>
940
+ ctx->position_offset_loc = memo->offset_loc;
941
+ <%- end -%>
942
+ return memo->chunk;
937
943
  }
938
944
 
939
945
  MARK_FUNC_AS_USED
940
- static pcc_bool_t pcc_apply_rule(pcc_context_t *ctx, pcc_rule_t rule, pcc_thunk_array_t *thunks, pcc_value_t *value, size_t offset<% if @location %>, pcc_location_t offset_loc<% end %>, pcc_rule_set_t *limits) {
941
- static pcc_value_t null;
942
- pcc_thunk_chunk_t *c;
946
+ static packcr_bool_t packcr_apply_rule(packcr_context_t *ctx, packcr_rule_t rule, packcr_thunk_array_t *thunks, packcr_value_t *value, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>, packcr_rule_set_t *limits) {
947
+ static packcr_value_t null;
948
+ packcr_thunk_chunk_t *c;
943
949
  if (limits != NULL) {
944
- pcc_lr_memo_t *a;
945
- pcc_rule_set__add(ctx->auxil, limits, rule);
950
+ packcr_lr_memo_t *memo;
951
+ packcr_rule_set__add(ctx->auxil, limits, rule);
946
952
  c = rule(ctx, offset<% if @location %>, offset_loc<% end %>, limits);
947
- a = pcc_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
948
- if (a == NULL || ctx->position_offset <= a->offset) {
949
- c = a->chunk;
950
- ctx->position_offset = a->offset;
953
+ memo = packcr_lr_table__get_memo(ctx, &ctx->lrtable, offset, rule);
954
+ if (memo == NULL || ctx->position_offset <= memo->offset) {
955
+ if (memo) {
956
+ c = memo->chunk;
957
+ ctx->position_offset = memo->offset;
958
+ <%- if @location -%>
959
+ ctx->position_offset_loc = memo->offset_loc;
960
+ <%- end -%>
961
+ }
951
962
  } else {
952
- pcc_lr_memo__set_chunk(ctx, a, c);
953
- a->offset = ctx->position_offset;
963
+ packcr_lr_memo__set_chunk(ctx, memo, c);
964
+ memo->offset = ctx->position_offset;
965
+ <%- if @location -%>
966
+ memo->offset_loc = ctx->position_offset_loc;
967
+ <%- end -%>
954
968
  }
955
969
  } else {
956
- c = pcc_get_rule_thunk_chunk(ctx, rule);
970
+ c = packcr_get_rule_thunk_chunk(ctx, rule);
957
971
  }
958
- if (c == NULL) return PCC_FALSE;
972
+ if (c == NULL) return PACKCR_FALSE;
959
973
  if (value == NULL) value = &null;
960
- memset(value, 0, sizeof(pcc_value_t)); /* in case */
961
- pcc_thunk_array__add(ctx->auxil, thunks, pcc_thunk__create_node(ctx->auxil, &c->thunks, value));
962
- return PCC_TRUE;
974
+ memset(value, 0, sizeof(packcr_value_t)); /* in case */
975
+ packcr_thunk_array__add(ctx->auxil, thunks, packcr_thunk__create_node(ctx->auxil, &c->thunks, value));
976
+ return PACKCR_TRUE;
963
977
  }
964
978
 
965
979
  MARK_FUNC_AS_USED
966
- static void pcc_do_action(pcc_context_t *ctx, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
980
+ static void packcr_do_action(packcr_context_t *ctx, const packcr_thunk_array_t *thunks, packcr_value_t *value) {
967
981
  size_t i;
968
982
  for (i = 0; i < thunks->len; i++) {
969
- pcc_thunk_t *const thunk = thunks->buf[i];
983
+ packcr_thunk_t *const thunk = thunks->buf[i];
970
984
  switch (thunk->type) {
971
- case PCC_THUNK_LEAF:
985
+ case PACKCR_THUNK_LEAF:
972
986
  thunk->data.leaf.action(ctx, thunk, value);
973
987
  break;
974
- case PCC_THUNK_NODE:
975
- pcc_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
988
+ case PACKCR_THUNK_NODE:
989
+ packcr_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
976
990
  break;
977
991
  default: /* unknown */
978
992
  break;
@@ -982,32 +996,32 @@ static void pcc_do_action(pcc_context_t *ctx, const pcc_thunk_array_t *thunks, p
982
996
 
983
997
  <%- @root.rules.each do |rule| -%>
984
998
  <%- rule.codes.each do |code| -%>
985
- static void pcc_action_<%= rule.name %>_<%= code.index %>(<%= prefix %>_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {
986
- #define auxil (__pcc_ctx->auxil)
987
- #define __ (*__pcc_out)
999
+ static void packcr_action_<%= rule.name %>_<%= code.index %>(<%= prefix %>_context_t *__packcr_ctx, packcr_thunk_t *__packcr_in, packcr_value_t *__packcr_out) {
1000
+ #define auxil (__packcr_ctx->auxil)
1001
+ #define __ (*__packcr_out)
988
1002
  <%- code.vars.each do |ref| -%>
989
- #define <%= ref.var %> (*__pcc_in->data.leaf.values.buf[<%= ref.index %>])
1003
+ #define <%= ref.var %> (*__packcr_in->data.leaf.values.buf[<%= ref.index %>])
990
1004
  <% end -%>
991
- #define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)
992
- #define _0s ((const size_t)(__pcc_ctx->buffer_start_position + __pcc_in->data.leaf.capt0.range.start))
993
- #define _0e ((const size_t)(__pcc_ctx->buffer_start_position + __pcc_in->data.leaf.capt0.range.end))
1005
+ #define _0 packcr_get_capture_string(__packcr_ctx, &__packcr_in->data.leaf.capt0)
1006
+ #define _0s ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capt0.range.start))
1007
+ #define _0e ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capt0.range.end))
994
1008
  <%- if @location -%>
995
- #define _0sl ((const pcc_location_t)(pcc_location_add(__pcc_ctx->buffer_start_position_loc, __pcc_in->data.leaf.capt0.range.start_loc)))
996
- #define _0el ((const pcc_location_t)(pcc_location_add(__pcc_ctx->buffer_start_position_loc, __pcc_in->data.leaf.capt0.range.end_loc)))
1009
+ #define _0sl ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capt0.range.start_loc)))
1010
+ #define _0el ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capt0.range.end_loc)))
997
1011
  <%- end -%>
998
1012
  <%- if @capture_in_code -%>
999
- #define _0c __pcc_in->data.leaf.capt0
1013
+ #define _0c __packcr_in->data.leaf.capt0
1000
1014
  <%- end -%>
1001
1015
  <% code.capts.each do |capture| -%>
1002
- #define _<%= capture.index + 1 %> pcc_get_capture_string(__pcc_ctx, __pcc_in->data.leaf.capts.buf[<%= capture.index %>])
1003
- #define _<%= capture.index + 1 %>s ((const size_t)(__pcc_ctx->buffer_start_position + __pcc_in->data.leaf.capts.buf[<%= capture.index %>]->range.start))
1004
- #define _<%= capture.index + 1 %>e ((const size_t)(__pcc_ctx->buffer_start_position + __pcc_in->data.leaf.capts.buf[<%= capture.index %>]->range.end))
1016
+ #define _<%= capture.index + 1 %> packcr_get_capture_string(__packcr_ctx, __packcr_in->data.leaf.capts.buf[<%= capture.index %>])
1017
+ #define _<%= capture.index + 1 %>s ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.start))
1018
+ #define _<%= capture.index + 1 %>e ((const size_t)(__packcr_ctx->buffer_start_position + __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.end))
1005
1019
  <%- if @location -%>
1006
- #define _<%= capture.index + 1 %>sl ((const pcc_location_t)(pcc_location_add(__pcc_ctx->buffer_start_position_loc, __pcc_in->data.leaf.capts.buf[<%= capture.index %>]->range.start_loc)))
1007
- #define _<%= capture.index + 1 %>el ((const pcc_location_t)(pcc_location_add(__pcc_ctx->buffer_start_position_loc, __pcc_in->data.leaf.capts.buf[<%= capture.index %>]->range.end_loc)))
1020
+ #define _<%= capture.index + 1 %>sl ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.start_loc)))
1021
+ #define _<%= capture.index + 1 %>el ((const packcr_location_t)(packcr_location_add(__packcr_ctx->buffer_start_position_loc, __packcr_in->data.leaf.capts.buf[<%= capture.index %>]->range.end_loc)))
1008
1022
  <%- end -%>
1009
1023
  <%- if @capture_in_code -%>
1010
- #define _<%= capture.index + 1 %>c (*__pcc_in->data.leaf.capts.buf[<%= capture.index %>])
1024
+ #define _<%= capture.index + 1 %>c (*__packcr_in->data.leaf.capts.buf[<%= capture.index %>])
1011
1025
  <%- end -%>
1012
1026
  <%- end -%>
1013
1027
  <%= stream.get_code_block(code.code, 4, @iname) -%>
@@ -1033,7 +1047,7 @@ static void pcc_action_<%= rule.name %>_<%= code.index %>(<%= prefix %>_context_
1033
1047
  <%- end -%>
1034
1048
  <%- end -%>
1035
1049
  <%- @root.rules.each do |rule| -%>
1036
- static pcc_thunk_chunk_t *pcc_evaluate_rule_<%= rule.name %>(pcc_context_t *ctx, size_t offset<% if @location %>, pcc_location_t offset_loc<% end %>, pcc_rule_set_t *limits);
1050
+ static packcr_thunk_chunk_t *packcr_evaluate_rule_<%= rule.name %>(packcr_context_t *ctx, size_t offset<% if @location %>, packcr_location_t offset_loc<% end %>, packcr_rule_set_t *limits);
1037
1051
  <%- end -%>
1038
1052
 
1039
1053
  <%- @root.rules.each do |rule| -%>
@@ -1042,24 +1056,24 @@ static pcc_thunk_chunk_t *pcc_evaluate_rule_<%= rule.name %>(pcc_context_t *ctx,
1042
1056
 
1043
1057
  <%- end -%>
1044
1058
  <%= prefix %>_context_t *<%= prefix %>_create(<%= auxil_def %>auxil) {
1045
- return pcc_context__create(auxil);
1059
+ return packcr_context__create(auxil);
1046
1060
  }
1047
1061
 
1048
1062
  int <%= prefix %>_parse(<%= prefix %>_context_t *ctx, <%= value_def %>*ret) {
1049
1063
  size_t pos = ctx->buffer_start_position;
1050
1064
  <%- if !@root.rules.empty? -%>
1051
- if (pcc_apply_rule(ctx, pcc_evaluate_rule_<%= @root.rules[0].name %>, &ctx->thunks, ret, ctx->position_offset<% if @location %>, ctx->position_offset_loc<% end %>, NULL))
1052
- pcc_do_action(ctx, &ctx->thunks, ret);
1065
+ if (packcr_apply_rule(ctx, packcr_evaluate_rule_<%= @root.rules[0].name %>, &ctx->thunks, ret, ctx->position_offset<% if @location %>, ctx->position_offset_loc<% end %>, NULL))
1066
+ packcr_do_action(ctx, &ctx->thunks, ret);
1053
1067
  else
1054
- PCC_ERROR(ctx->auxil);
1055
- pcc_commit_buffer(ctx);
1068
+ PACKCR_ERROR(ctx->auxil);
1069
+ packcr_commit_buffer(ctx);
1056
1070
  <%- end -%>
1057
- pcc_thunk_array__revert(ctx->auxil, &ctx->thunks, 0);
1058
- return pos != ctx->buffer_start_position && pcc_refill_buffer(ctx, 1) >= 1;
1071
+ packcr_thunk_array__revert(ctx->auxil, &ctx->thunks, 0);
1072
+ return pos != ctx->buffer_start_position && packcr_refill_buffer(ctx, 1) >= 1;
1059
1073
  }
1060
1074
 
1061
1075
  void <%= prefix %>_destroy(<%= prefix %>_context_t *ctx) {
1062
- pcc_context__destroy(ctx);
1076
+ packcr_context__destroy(ctx);
1063
1077
  }
1064
1078
  <%- if !code(:lsource).empty? -%>
1065
1079