teptris 0.3.23.0-powerpc64le-linux → 0.3.25.0-powerpc64le-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32fdcd4af59d32f2e0b6b90e1f4d8df16d2e5b86ab92dc3998e6888dc2c059dd
4
- data.tar.gz: 864d2c81f622a34f0e42eeca7f772c4f532212cd637df81bc2a092232cdd2d54
3
+ metadata.gz: 6711dc8bd2e47ced8a6fdf6478968e7636c448d41d8e1e007ca1646b4c03d8f5
4
+ data.tar.gz: bc52fd02baf456ff267c3ba06febe5aca09182a30c4471d5fda3742b5b6e793b
5
5
  SHA512:
6
- metadata.gz: b0a817984901eede4fd7df994cd7697837a1439811b4e3e3048d6bbab89575999cc117b705886b18a53abdf9e7abaf4fd1e21550e96b3337ee9888ce3aa1b209
7
- data.tar.gz: adee07dc2ffd5bad5d61377b92f33bd7a153d973a4b1e94bb5ac9cb359e94b4ffe739de325d2ab6b130bf3bdba6555ccf1768d697282ac14f08c9647174e7d70
6
+ metadata.gz: b582bc413fd870812a44aeb406f57657772226268c7544b3abfbccdc04f14f0dcc7aceaea1ac9f5a08e30805442de91743375c8e495de2e01579f1deb95af18f
7
+ data.tar.gz: 2615199304f007b3493dafe5484afb7b430dbd91ef3c10d607530d7f5b983267445b8bf32fa4fc1773f68d40b502693718a75c9ad4ac0e34c219f83a5ffbbc0c
@@ -1,4 +1,4 @@
1
- # libteptris 0.3.23 — vendored source
1
+ # libteptris 0.3.25 — vendored source
2
2
 
3
3
  This directory carries the COMPLETE C source of the engine this
4
4
  gem's extension was built from (the packaging doctrine: compiled
@@ -3,7 +3,7 @@
3
3
 
4
4
  #define TEPTRIS_VERSION_MAJOR 0
5
5
  #define TEPTRIS_VERSION_MINOR 3
6
- #define TEPTRIS_VERSION_PATCH 23
7
- #define TEPTRIS_VERSION_STRING "0.3.23"
6
+ #define TEPTRIS_VERSION_PATCH 25
7
+ #define TEPTRIS_VERSION_STRING "0.3.25"
8
8
 
9
9
  #endif /* TEPTRIS_VERSION_H */
@@ -20,6 +20,7 @@
20
20
  #include <string.h>
21
21
 
22
22
  #include "regex.h"
23
+ #include "unicode_props.h"
23
24
 
24
25
  /* ---------------------------------------------------------------- AST -- */
25
26
 
@@ -199,6 +200,94 @@ static void cls_add_cp(pctx *c, ra *cl, uint32_t cp) {
199
200
  cl->n_ranges++;
200
201
  }
201
202
 
203
+ /* ------------------------------------------------- \p{...} properties -- */
204
+
205
+ static void cls_reserve(pctx *c, ra *cl, size_t cap);
206
+
207
+ /* the property named by s[0..n) (decoded code points): binary search
208
+ * over the sorted table */
209
+ static const teptris_uc_prop *uc_find(const uint32_t *s, size_t n) {
210
+ int lo = 0, hi = teptris_n_unicode_props - 1;
211
+ while (lo <= hi) {
212
+ int mid = (lo + hi) / 2;
213
+ const char *name = teptris_unicode_props[mid].name;
214
+ int cmp = 0;
215
+ for (size_t i = 0; i < n; i++) {
216
+ unsigned char c = (unsigned char)name[i];
217
+ if (c == '\0' || (uint32_t)c != s[i]) {
218
+ cmp = (uint32_t)c < s[i] ? -1 : 1;
219
+ break;
220
+ }
221
+ }
222
+ if (cmp == 0 && name[n] == '\0') return &teptris_unicode_props[mid];
223
+ if (cmp == 0) cmp = 1; /* longer table name: s sorts first */
224
+ if (cmp < 0) lo = mid + 1;
225
+ else hi = mid - 1;
226
+ }
227
+ return NULL;
228
+ }
229
+
230
+ /* the complement of sorted ranges over the whole codepoint space (the
231
+ * caller reserved headroom) */
232
+ static void cls_append_complement(pctx *c, ra *cl,
233
+ const teptris_uc_range *rs, int n) {
234
+ (void)c;
235
+ uint32_t expect = 0;
236
+ for (int i = 0; i <= n; i++) {
237
+ uint32_t lo = i < n ? rs[i].lo : 0x110000;
238
+ uint32_t hi = i < n ? rs[i].hi : 0x110000;
239
+ if (lo > expect) {
240
+ cl->ranges[cl->n_ranges].lo = expect;
241
+ cl->ranges[cl->n_ranges].hi = lo - 1;
242
+ cl->n_ranges++;
243
+ }
244
+ if (hi + 1 > expect) expect = hi + 1;
245
+ }
246
+ }
247
+
248
+ /* parse \p{...} / \P{...} / \p{^...} with c->pos after the letter;
249
+ * the ranges (or their complement) append into cl */
250
+ static void prop_escape(pctx *c, ra *cl, bool negate_letter) {
251
+ bool inner_neg = false;
252
+ if (c->pos >= c->n || c->s[c->pos] != '{') {
253
+ pfail(c, "\\p needs a {property} name");
254
+ return;
255
+ }
256
+ c->pos++;
257
+ if (c->pos < c->n && c->s[c->pos] == '^') {
258
+ inner_neg = true;
259
+ c->pos++;
260
+ }
261
+ size_t start = c->pos;
262
+ while (c->pos < c->n && c->s[c->pos] != '}') c->pos++;
263
+ if (c->pos >= c->n) {
264
+ pfail(c, "unterminated \\p{...}");
265
+ return;
266
+ }
267
+ size_t n = c->pos - start;
268
+ c->pos++; /* the closing brace */
269
+ if (n == 0) {
270
+ pfail(c, "empty \\p{} property name");
271
+ return;
272
+ }
273
+ const teptris_uc_prop *p = uc_find(c->s + start, n);
274
+ if (p == NULL) {
275
+ pfail(c, "unknown \\p{...} property name");
276
+ return;
277
+ }
278
+ bool negate = negate_letter != inner_neg;
279
+ cls_reserve(c, cl, negate ? (size_t)2 * p->n + 8 : (size_t)p->n + 8);
280
+ if (negate) {
281
+ cls_append_complement(c, cl, p->ranges, p->n);
282
+ } else {
283
+ for (int i = 0; i < p->n; i++) {
284
+ cl->ranges[cl->n_ranges].lo = p->ranges[i].lo;
285
+ cl->ranges[cl->n_ranges].hi = p->ranges[i].hi;
286
+ cl->n_ranges++;
287
+ }
288
+ }
289
+ }
290
+
202
291
  /* expand a class shorthand (\d \w \s) into its ranges */
203
292
  static void cls_shorthand(pctx *c, ra *cl, uint32_t e) {
204
293
  if (e == 'd' || e == 'D') {
@@ -241,6 +330,10 @@ static long class_escape(pctx *c, ra *cl) {
241
330
  c->pos++;
242
331
  cls_shorthand(c, cl, e);
243
332
  return -1;
333
+ case 'p': case 'P':
334
+ c->pos++;
335
+ prop_escape(c, cl, e == 'P');
336
+ return -1;
244
337
  case 'x': {
245
338
  c->pos++;
246
339
  if (c->pos + 2 > c->n) {
@@ -291,6 +384,34 @@ static long class_escape(pctx *c, ra *cl) {
291
384
  }
292
385
 
293
386
  /* parse the body of a [...]; c->pos sits after '[' */
387
+ /* sort + merge a class's ranges in place (property tables arrive
388
+ * sorted; literals interleave arbitrarily) so matching can binary
389
+ * search and negation sees a canonical form */
390
+ static void cls_sort_merge(pctx *c, ra *cl) {
391
+ (void)c;
392
+ int n = cl->n_ranges;
393
+ for (int i = 1; i < n; i++) {
394
+ ra_range r = cl->ranges[i];
395
+ int j = i - 1;
396
+ while (j >= 0 && (cl->ranges[j].lo > r.lo)) {
397
+ cl->ranges[j + 1] = cl->ranges[j];
398
+ j--;
399
+ }
400
+ cl->ranges[j + 1] = r;
401
+ }
402
+ int w = 0;
403
+ for (int i = 1; i < n; i++) {
404
+ if (cl->ranges[i].lo <= cl->ranges[w].hi + 1) {
405
+ if (cl->ranges[i].hi > cl->ranges[w].hi) {
406
+ cl->ranges[w].hi = cl->ranges[i].hi;
407
+ }
408
+ } else {
409
+ cl->ranges[++w] = cl->ranges[i];
410
+ }
411
+ }
412
+ cl->n_ranges = w + 1;
413
+ }
414
+
294
415
  static ra *rclass(pctx *c) {
295
416
  ra *cl = rn(c, RA_CLASS);
296
417
  if (c->pos < c->n && c->s[c->pos] == '^') {
@@ -303,6 +424,7 @@ static ra *rclass(pctx *c) {
303
424
  while (c->pos < c->n) {
304
425
  if (c->s[c->pos] == ']' && !first) {
305
426
  c->pos++;
427
+ cls_sort_merge(c, cl);
306
428
  return cl;
307
429
  }
308
430
  first = false;
@@ -495,6 +617,13 @@ static ra *ratom(pctx *c) {
495
617
  cls_shorthand(c, cl, e);
496
618
  return cl;
497
619
  }
620
+ if (e == 'p' || e == 'P') {
621
+ c->pos++;
622
+ ra *cl = rn(c, RA_CLASS);
623
+ prop_escape(c, cl, e == 'P');
624
+ if (c->err[0] != '\0') return NULL;
625
+ return cl;
626
+ }
498
627
  if (e == 'b') {
499
628
  c->pos++;
500
629
  return rn(c, RA_WORDB);
@@ -701,12 +830,13 @@ static bool emit_node(nctx *c, ra *r, frag *f) {
701
830
  int s = nstate(c, RS_CHAR);
702
831
  if (s < 0) return false;
703
832
  if (r->ci) {
704
- /* a folded letter matches both cases */
833
+ /* a folded letter matches both cases (stored ascending:
834
+ * cls_match binary-searches) */
705
835
  c->states[s].ranges = teptris_arena_alloc(c->a, 2 * sizeof(ra_range));
706
- c->states[s].ranges[0].lo = r->cp;
707
- c->states[s].ranges[0].hi = r->cp;
708
- c->states[s].ranges[1].lo = fold_cp(r->cp) - 32;
709
- c->states[s].ranges[1].hi = fold_cp(r->cp) - 32;
836
+ c->states[s].ranges[0].lo = fold_cp(r->cp) - 32;
837
+ c->states[s].ranges[0].hi = fold_cp(r->cp) - 32;
838
+ c->states[s].ranges[1].lo = r->cp;
839
+ c->states[s].ranges[1].hi = r->cp;
710
840
  c->states[s].n_ranges = 2;
711
841
  } else {
712
842
  c->states[s].ranges = teptris_arena_alloc(c->a, sizeof(ra_range));
@@ -937,9 +1067,15 @@ struct sch_regex *sch_regex_compile(teptris_arena *a, const char *pattern,
937
1067
 
938
1068
  static bool cls_match(const rstate *st, uint32_t cp) {
939
1069
  if (st->any) return true;
1070
+ int lo = 0, hi = st->n_ranges - 1;
940
1071
  bool in = false;
941
- for (int i = 0; i < st->n_ranges; i++) {
942
- if (cp >= st->ranges[i].lo && cp <= st->ranges[i].hi) {
1072
+ while (lo <= hi) {
1073
+ int mid = (lo + hi) / 2;
1074
+ if (cp < st->ranges[mid].lo) {
1075
+ hi = mid - 1;
1076
+ } else if (cp > st->ranges[mid].hi) {
1077
+ lo = mid + 1;
1078
+ } else {
943
1079
  in = true;
944
1080
  break;
945
1081
  }
@@ -1151,8 +1151,12 @@ sch_node *sch_compile_node(sctx *c, const jv *v) {
1151
1151
  }
1152
1152
  n->dynamic_recursive = recursive;
1153
1153
  } else if (strcmp(k, "contentSchema") == 0) {
1154
- n->content_schema = sch_compile_node(c, val);
1155
- if (n->content_schema == NULL && c->err[0] != '\0') return NULL;
1154
+ if (!c->dialect_declared) {
1155
+ n->content_schema = sch_compile_node(c, val);
1156
+ if (n->content_schema == NULL && c->err[0] != '\0') return NULL;
1157
+ }
1158
+ /* annotation under an explicit dialect (2020-12 content
1159
+ * vocabulary: assertions SHOULD NOT be made) */
1156
1160
  } else if (strcmp(k, "required") == 0 &&
1157
1161
  jv_kind_of(val) == JV_ARRAY) {
1158
1162
  size_t cnt = jv_item_count(val);
@@ -1224,10 +1228,10 @@ sch_node *sch_compile_node(sctx *c, const jv *v) {
1224
1228
  }
1225
1229
  } else if (strcmp(k, "contentEncoding") == 0 &&
1226
1230
  jv_kind_of(val) == JV_STRING) {
1227
- n->content_encoding = jv_str(val);
1231
+ if (!c->dialect_declared) n->content_encoding = jv_str(val);
1228
1232
  } else if (strcmp(k, "contentMediaType") == 0 &&
1229
1233
  jv_kind_of(val) == JV_STRING) {
1230
- n->content_media_type = jv_str(val);
1234
+ if (!c->dialect_declared) n->content_media_type = jv_str(val);
1231
1235
  } else if (strcmp(k, "items") == 0 && jv_kind_of(val) == JV_ARRAY) {
1232
1236
  /* draft-07 tuple form: positional prefixes; the union
1233
1237
  * reads them exactly like prefixItems, with
@@ -1300,7 +1304,11 @@ sch_node *sch_compile_node(sctx *c, const jv *v) {
1300
1304
  if (!count_value(c, val, &n->max_length)) return NULL;
1301
1305
  n->has_max_length = true;
1302
1306
  } else if (strcmp(k, "format") == 0 && jv_kind_of(val) == JV_STRING) {
1303
- n->format = format_kind(jv_str(val));
1307
+ if (!c->dialect_declared) {
1308
+ n->format = format_kind(jv_str(val));
1309
+ }
1310
+ /* an explicit dialect keeps the spec's annotation-only
1311
+ * default: the keyword rides the ignored tail */
1304
1312
  } else if ((strcmp(k, "minimum") == 0 || strcmp(k, "maximum") == 0 ||
1305
1313
  strcmp(k, "exclusiveMinimum") == 0 ||
1306
1314
  strcmp(k, "exclusiveMaximum") == 0) &&
@@ -1511,7 +1519,11 @@ static teptris_status schema_compile_core(const char *json, size_t len,
1511
1519
  c.cur_dir = held;
1512
1520
  }
1513
1521
  /* draft 07 and older make a $ref ignore its siblings; 2019-09+
1514
- * evaluate $ref alongside them. The root's $schema decides. */
1522
+ * evaluate $ref alongside them. The root's $schema decides. A
1523
+ * standard draft dialect switches format/content* to the spec's
1524
+ * annotation-only default; the format-assertion dialect URI opts
1525
+ * back in, and the no-dialect default asserts (the practical
1526
+ * mode every real-world manifest relies on). */
1515
1527
  if (jv_kind_of(root) == JV_OBJECT) {
1516
1528
  jv *sv = jv_member_get(root, "$schema");
1517
1529
  if (sv != NULL && jv_kind_of(sv) == JV_STRING) {
@@ -1520,6 +1532,9 @@ static teptris_status schema_compile_core(const char *json, size_t len,
1520
1532
  strstr(s, "draft-07") != NULL) {
1521
1533
  c.ref_exclusive = true;
1522
1534
  }
1535
+ if (strstr(s, "format-assertion") == NULL) {
1536
+ c.dialect_declared = true;
1537
+ }
1523
1538
  }
1524
1539
  }
1525
1540
 
@@ -226,6 +226,10 @@ typedef struct {
226
226
  /* which standard vocabularies the dialect keeps (8.1.2: a custom
227
227
  * metaschema's $vocabulary decides; absent = all of them) */
228
228
  unsigned vocab_mask;
229
+ /* an explicit root $schema declares the dialect: format and
230
+ * content* then follow the spec's annotation-only default. No
231
+ * $schema means teptris's practical default: assert. */
232
+ bool dialect_declared;
229
233
  /* standard vocabulary gates (the core vocabulary is mandatory and
230
234
  * never gated) */
231
235
  #define TEPTRIS_VOC_APPLICATOR 1u