teptris 0.3.26.0-arm-linux → 0.3.28.0-arm-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 +4 -4
- data/ext/teptris_ext/engine/README.md +1 -1
- data/ext/teptris_ext/engine/src/include/teptris/version.h +2 -2
- data/ext/teptris_ext/engine/src/teptris/emit/writer.c +69 -62
- data/ext/teptris_ext/engine/src/teptris/parse/datetime.c +108 -51
- data/ext/teptris_ext/engine/src/teptris/parse/parse.h +6 -0
- data/ext/teptris_ext/engine/src/teptris/schema/json_read.c +22 -4
- data/lib/teptris/3.3/teptris_ext.so +0 -0
- data/lib/teptris/3.4/teptris_ext.so +0 -0
- data/lib/teptris/4.0/teptris_ext.so +0 -0
- data/lib/teptris/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4da0b87574ca223341500908f7c9bc61f28c6a4138f5ae5448c81e1068a313b8
|
|
4
|
+
data.tar.gz: a8bf97a370f89bc2c975c114b3c146509b02de2912f8d4548a0e392489dce9b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d8be1e4d34c9cef41142caee4895b80282a8f226e92098b0b96f066b098e59f197ff62e05ea748edcbb3ce40cb0dfb61d4a600374fbea5c8750479414c7338ae
|
|
7
|
+
data.tar.gz: ac59132b12d2d67bad050fcdd26fdea684e8b4c7c10d883f63f78d3c1fa538d17c4eaf2e077d0e8b4acf500955879ba0fc8027ec5065008ea9f4d50ac47a2061
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
* 0x05 FALSE
|
|
21
21
|
* 0x06 TRUE
|
|
22
22
|
* 0x07 DATETIME u8 kind(4..7) <25 B, same layout as flatten>
|
|
23
|
+
* 0x0F DATETIME-TEXT u32 len <bytes> - an RFC 3339 literal carried
|
|
24
|
+
* as raw text (the JS dump's datetime shape); the
|
|
25
|
+
* engine parses it with teptris_datetime_from_str at
|
|
26
|
+
* decode (non-datetime text = ERR_ARG). Emits the
|
|
27
|
+
* same canonical bytes as the structured op - the
|
|
28
|
+
* host never parses datetimes.
|
|
23
29
|
* 0x08 BEGIN-TABLE section header ([k] / [a.b])
|
|
24
30
|
* 0x09 BEGIN-ARRAY inline array as a value
|
|
25
31
|
* 0x0A BEGIN-AOT array-of-tables ([[k]], elements via BEGIN-TABLE)
|
|
@@ -36,6 +42,7 @@
|
|
|
36
42
|
#include <string.h>
|
|
37
43
|
|
|
38
44
|
#include "emit_shared.h"
|
|
45
|
+
#include "teptris/parse/parse.h"
|
|
39
46
|
#include "teptris/teptris.h"
|
|
40
47
|
|
|
41
48
|
enum {
|
|
@@ -53,7 +60,8 @@ enum {
|
|
|
53
60
|
W_BEGIN_INLINE_TABLE = 0x0B,
|
|
54
61
|
W_CLOSE = 0x0C,
|
|
55
62
|
W_EMPTY_TABLE = 0x0D,
|
|
56
|
-
W_EMPTY_ARRAY = 0x0E
|
|
63
|
+
W_EMPTY_ARRAY = 0x0E,
|
|
64
|
+
W_DATETIME_TEXT = 0x0F
|
|
57
65
|
};
|
|
58
66
|
|
|
59
67
|
enum {
|
|
@@ -63,19 +71,27 @@ enum {
|
|
|
63
71
|
F_ITAB /* inline table */
|
|
64
72
|
};
|
|
65
73
|
|
|
74
|
+
/* keys ride inline: the op grammar caps a key at 255 bytes, so no
|
|
75
|
+
* key ever needs the heap — the per-key malloc/free pair profiled at
|
|
76
|
+
* ~27% of the writer's flat-dump hot path (2026-11-11) */
|
|
77
|
+
#define W_KEY_INLINE 256
|
|
78
|
+
|
|
66
79
|
typedef struct wframe {
|
|
67
80
|
struct wframe *down;
|
|
68
81
|
int kind;
|
|
69
|
-
char *key;
|
|
82
|
+
char *key; /* TBL section component; AOT key; else NULL
|
|
83
|
+
(always points INTO key_buf when set) */
|
|
70
84
|
size_t key_len;
|
|
71
|
-
|
|
72
|
-
int
|
|
85
|
+
char key_buf[W_KEY_INLINE];
|
|
86
|
+
int first; /* inline separator state */
|
|
87
|
+
int saw_subtable; /* TBL: a nested section was opened under us */
|
|
73
88
|
} wframe;
|
|
74
89
|
|
|
75
90
|
struct teptris_writer {
|
|
76
91
|
ebuf out;
|
|
77
|
-
char *key; /* pending key */
|
|
92
|
+
char *key; /* pending key (points INTO key_buf when set) */
|
|
78
93
|
size_t key_len;
|
|
94
|
+
char key_buf[W_KEY_INLINE];
|
|
79
95
|
wframe *top;
|
|
80
96
|
int finished;
|
|
81
97
|
teptris_status st;
|
|
@@ -104,67 +120,33 @@ void teptris_writer_free(teptris_writer *w)
|
|
|
104
120
|
while (w->top != NULL) {
|
|
105
121
|
wframe *f = w->top;
|
|
106
122
|
w->top = f->down;
|
|
107
|
-
free(f->key);
|
|
108
123
|
free(f);
|
|
109
124
|
}
|
|
110
|
-
free(w->key);
|
|
111
125
|
free(w->out.p);
|
|
112
126
|
free(w);
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
static void w_take_key(teptris_writer *w, const char *k, size_t klen)
|
|
116
130
|
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
w->st = TEPTRIS_ERR_ALLOC;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
memcpy(w->key, k, klen);
|
|
127
|
-
w->key_len = klen;
|
|
128
|
-
} else {
|
|
129
|
-
/* an empty key stays PENDING: NULL means "no key", and the
|
|
130
|
-
* keyed-prefix checks treat NULL as absent. The parse side
|
|
131
|
-
* accepts '' = 1, so the writer must emit it ('' via emit_key) */
|
|
132
|
-
w->key = malloc(1);
|
|
133
|
-
if (w->key == NULL) {
|
|
134
|
-
w->key_len = 0;
|
|
135
|
-
w->st = TEPTRIS_ERR_ALLOC;
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
w->key[0] = '\0';
|
|
139
|
-
w->key_len = 0;
|
|
131
|
+
/* NULL means "no key"; the empty key stays PENDING as a present
|
|
132
|
+
* but zero-length buffer (the parse side accepts '' = 1, so the
|
|
133
|
+
* writer must emit it via emit_key) */
|
|
134
|
+
if (klen >= W_KEY_INLINE) {
|
|
135
|
+
w->st = TEPTRIS_ERR_ARG; /* the grammar caps keys at 255 */
|
|
136
|
+
return;
|
|
140
137
|
}
|
|
138
|
+
memcpy(w->key_buf, k, klen);
|
|
139
|
+
w->key_buf[klen] = '\0';
|
|
140
|
+
w->key = w->key_buf;
|
|
141
|
+
w->key_len = klen;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
static void w_clear_key(teptris_writer *w)
|
|
144
145
|
{
|
|
145
|
-
free(w->key);
|
|
146
146
|
w->key = NULL;
|
|
147
147
|
w->key_len = 0;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/* push with an OWNED key (transfers the malloc from the caller) */
|
|
151
|
-
static wframe *w_push_steal(teptris_writer *w, int kind, char *k,
|
|
152
|
-
size_t klen)
|
|
153
|
-
{
|
|
154
|
-
wframe *f = calloc(1, sizeof(*f));
|
|
155
|
-
if (f == NULL) {
|
|
156
|
-
free(k);
|
|
157
|
-
w->st = TEPTRIS_ERR_ALLOC;
|
|
158
|
-
return NULL;
|
|
159
|
-
}
|
|
160
|
-
f->down = w->top;
|
|
161
|
-
f->kind = kind;
|
|
162
|
-
f->key = k;
|
|
163
|
-
f->key_len = klen;
|
|
164
|
-
w->top = f;
|
|
165
|
-
return f;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
150
|
static wframe *w_push(teptris_writer *w, int kind, const char *k,
|
|
169
151
|
size_t klen)
|
|
170
152
|
{
|
|
@@ -175,14 +157,10 @@ static wframe *w_push(teptris_writer *w, int kind, const char *k,
|
|
|
175
157
|
}
|
|
176
158
|
f->down = w->top;
|
|
177
159
|
f->kind = kind;
|
|
178
|
-
if (
|
|
179
|
-
f->
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
w->st = TEPTRIS_ERR_ALLOC;
|
|
183
|
-
return NULL;
|
|
184
|
-
}
|
|
185
|
-
memcpy(f->key, k, klen);
|
|
160
|
+
if (k != NULL) {
|
|
161
|
+
memcpy(f->key_buf, k, klen);
|
|
162
|
+
f->key_buf[klen] = '\0';
|
|
163
|
+
f->key = f->key_buf;
|
|
186
164
|
f->key_len = klen;
|
|
187
165
|
}
|
|
188
166
|
w->top = f;
|
|
@@ -409,6 +387,36 @@ teptris_status teptris_writer_feed(teptris_writer *w, const uint8_t *ops,
|
|
|
409
387
|
w_end_line(w);
|
|
410
388
|
break;
|
|
411
389
|
}
|
|
390
|
+
case W_DATETIME_TEXT: {
|
|
391
|
+
if (i + 4 > len) {
|
|
392
|
+
w->st = TEPTRIS_ERR_ARG;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
uint32_t tlen = (uint32_t)ops[i] |
|
|
396
|
+
((uint32_t)ops[i + 1] << 8) |
|
|
397
|
+
((uint32_t)ops[i + 2] << 16) |
|
|
398
|
+
((uint32_t)ops[i + 3] << 24);
|
|
399
|
+
i += 4;
|
|
400
|
+
if (i + tlen > len) {
|
|
401
|
+
w->st = TEPTRIS_ERR_ARG;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
teptris_datetime dt;
|
|
405
|
+
teptris_kind dk;
|
|
406
|
+
if (teptris_datetime_from_str((const char *)ops + i, tlen, &dt,
|
|
407
|
+
&dk) != TEPTRIS_OK) {
|
|
408
|
+
w->st = TEPTRIS_ERR_ARG;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
i += tlen;
|
|
412
|
+
w_keyed_prefix(w);
|
|
413
|
+
if (w->st != TEPTRIS_OK) {
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
emit_dt(&w->out, &dt, dk);
|
|
417
|
+
w_end_line(w);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
412
420
|
case W_BEGIN_TABLE: {
|
|
413
421
|
wframe *t = w->top;
|
|
414
422
|
if (t != NULL && (t->kind == F_ARRAY || t->kind == F_ITAB)) {
|
|
@@ -438,11 +446,11 @@ teptris_status teptris_writer_feed(teptris_writer *w, const uint8_t *ops,
|
|
|
438
446
|
eb_c(&w->out, '[');
|
|
439
447
|
w_path(w, 1);
|
|
440
448
|
eb_put(&w->out, "]\n", 2);
|
|
441
|
-
char *k = w->key;
|
|
449
|
+
const char *k = w->key;
|
|
442
450
|
size_t klen = w->key_len;
|
|
443
451
|
w->key = NULL;
|
|
444
452
|
w->key_len = 0;
|
|
445
|
-
|
|
453
|
+
w_push(w, F_TABLE, k, klen);
|
|
446
454
|
break;
|
|
447
455
|
}
|
|
448
456
|
case W_BEGIN_AOT: {
|
|
@@ -458,11 +466,11 @@ teptris_status teptris_writer_feed(teptris_writer *w, const uint8_t *ops,
|
|
|
458
466
|
if (t != NULL) {
|
|
459
467
|
t->saw_subtable = 1;
|
|
460
468
|
}
|
|
461
|
-
char *k = w->key;
|
|
469
|
+
const char *k = w->key;
|
|
462
470
|
size_t klen = w->key_len;
|
|
463
471
|
w->key = NULL;
|
|
464
472
|
w->key_len = 0;
|
|
465
|
-
|
|
473
|
+
w_push(w, F_AOT, k, klen);
|
|
466
474
|
break;
|
|
467
475
|
}
|
|
468
476
|
case W_BEGIN_ARRAY: {
|
|
@@ -529,7 +537,6 @@ teptris_status teptris_writer_feed(teptris_writer *w, const uint8_t *ops,
|
|
|
529
537
|
}
|
|
530
538
|
int kind = f->kind;
|
|
531
539
|
w->top = f->down;
|
|
532
|
-
free(f->key);
|
|
533
540
|
free(f);
|
|
534
541
|
if (kind == F_ARRAY) {
|
|
535
542
|
eb_c(&w->out, ']');
|
|
@@ -68,27 +68,38 @@ static teptris_status finish_node(teptris_parser *ps, teptris_kind kind,
|
|
|
68
68
|
return TEPTRIS_OK;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
/* The datetime grammar core: parse one datetime at p..end into dt.
|
|
72
|
+
* No DOM, no parser state — teptris_parse_datetime wraps this with
|
|
73
|
+
* node creation, and teptris_datetime_from_str uses it to classify a
|
|
74
|
+
* standalone literal (the json-to-toml dump path). Errors come back
|
|
75
|
+
* as ERR_SYNTAX with a message in *err. */
|
|
76
|
+
static teptris_status dt_scan(const char *p, const char *end,
|
|
77
|
+
teptris_datetime *dt, teptris_kind *kind,
|
|
78
|
+
size_t *consumed, const char **err)
|
|
72
79
|
{
|
|
73
|
-
const char *p = ps->p;
|
|
74
|
-
const char *end = ps->end;
|
|
75
80
|
const char *start = p;
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
memset(dt, 0, sizeof(*dt));
|
|
82
|
+
|
|
83
|
+
if (end - p < 5) {
|
|
84
|
+
*err = "datetime too short";
|
|
85
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
86
|
+
}
|
|
78
87
|
|
|
79
|
-
if (p[4] == '-') {
|
|
88
|
+
if (end - p >= 10 && p[4] == '-') {
|
|
80
89
|
int y = num4(p);
|
|
81
90
|
int mo = d2(p + 5);
|
|
82
91
|
int da = d2(p + 8);
|
|
83
92
|
if (mo < 1 || mo > 12) {
|
|
84
|
-
|
|
93
|
+
*err = "invalid month";
|
|
94
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
85
95
|
}
|
|
86
96
|
if (da < 1 || da > days_in_month(y, mo)) {
|
|
87
|
-
|
|
97
|
+
*err = "invalid day";
|
|
98
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
88
99
|
}
|
|
89
|
-
dt
|
|
90
|
-
dt
|
|
91
|
-
dt
|
|
100
|
+
dt->year = (int32_t)y;
|
|
101
|
+
dt->month = (uint8_t)mo;
|
|
102
|
+
dt->day = (uint8_t)da;
|
|
92
103
|
p += 10;
|
|
93
104
|
|
|
94
105
|
bool has_time =
|
|
@@ -96,42 +107,46 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
|
96
107
|
(size_t)(end - p) >= 6 && is_dig(p + 1) && is_dig(p + 2) &&
|
|
97
108
|
p[3] == ':' && is_dig(p + 4) && is_dig(p + 5);
|
|
98
109
|
if (!has_time) {
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
*kind = TEPTRIS_DATE_LOCAL;
|
|
111
|
+
*consumed = (size_t)(p - start);
|
|
112
|
+
return TEPTRIS_OK;
|
|
101
113
|
}
|
|
102
114
|
p++; /* separator */
|
|
103
115
|
|
|
104
116
|
int h = d2(p);
|
|
105
117
|
int mi = d2(p + 3);
|
|
106
118
|
int s = 0; /* TOML 1.1: seconds optional */
|
|
107
|
-
size_t
|
|
119
|
+
size_t sec_consumed = 5;
|
|
108
120
|
if ((size_t)(end - p) >= 6 && p[5] == ':') {
|
|
109
121
|
if ((size_t)(end - p) < 8 || !is_dig(p + 6) || !is_dig(p + 7)) {
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
*err = "invalid second";
|
|
123
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
112
124
|
}
|
|
113
125
|
s = d2(p + 6);
|
|
114
|
-
|
|
126
|
+
sec_consumed = 8;
|
|
115
127
|
}
|
|
116
128
|
if (h > 23) {
|
|
117
|
-
|
|
129
|
+
*err = "invalid hour";
|
|
130
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
118
131
|
}
|
|
119
132
|
if (mi > 59) {
|
|
120
|
-
|
|
133
|
+
*err = "invalid minute";
|
|
134
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
121
135
|
}
|
|
122
136
|
if (s > 60) {
|
|
123
|
-
|
|
137
|
+
*err = "invalid second";
|
|
138
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
124
139
|
}
|
|
125
|
-
dt
|
|
126
|
-
dt
|
|
127
|
-
dt
|
|
128
|
-
p +=
|
|
140
|
+
dt->hour = (uint8_t)h;
|
|
141
|
+
dt->minute = (uint8_t)mi;
|
|
142
|
+
dt->second = (uint8_t)s;
|
|
143
|
+
p += sec_consumed;
|
|
129
144
|
|
|
130
145
|
if (p < end && *p == '.') {
|
|
131
146
|
p++;
|
|
132
147
|
if (p >= end || !is_dig(p)) {
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
*err = "expected fractional digits";
|
|
149
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
135
150
|
}
|
|
136
151
|
uint32_t scale = 100000000u; /* 9 digits */
|
|
137
152
|
uint32_t ns = 0;
|
|
@@ -142,14 +157,15 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
|
142
157
|
}
|
|
143
158
|
p++; /* beyond 9 digits: validated, then truncated */
|
|
144
159
|
}
|
|
145
|
-
dt
|
|
160
|
+
dt->nanosecond = ns;
|
|
146
161
|
}
|
|
147
162
|
|
|
148
163
|
if (p < end && (*p == 'Z' || *p == 'z')) {
|
|
149
|
-
dt
|
|
164
|
+
dt->offset_seconds = 0;
|
|
150
165
|
p++;
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
*kind = TEPTRIS_DATETIME_OFFSET;
|
|
167
|
+
*consumed = (size_t)(p - start);
|
|
168
|
+
return TEPTRIS_OK;
|
|
153
169
|
}
|
|
154
170
|
if (p < end && (*p == '+' || *p == '-') &&
|
|
155
171
|
(size_t)(end - p) >= 6 && is_dig(p + 1) && is_dig(p + 2) &&
|
|
@@ -158,49 +174,55 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
|
158
174
|
int oh = d2(p + 1);
|
|
159
175
|
int om = d2(p + 4);
|
|
160
176
|
if (oh > 23 || om > 59) {
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
*err = "invalid UTC offset";
|
|
178
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
163
179
|
}
|
|
164
|
-
dt
|
|
180
|
+
dt->offset_seconds = sign * (oh * 3600 + om * 60);
|
|
165
181
|
p += 6;
|
|
166
|
-
|
|
167
|
-
|
|
182
|
+
*kind = TEPTRIS_DATETIME_OFFSET;
|
|
183
|
+
*consumed = (size_t)(p - start);
|
|
184
|
+
return TEPTRIS_OK;
|
|
168
185
|
}
|
|
169
|
-
|
|
170
|
-
|
|
186
|
+
*kind = TEPTRIS_DATETIME_LOCAL;
|
|
187
|
+
*consumed = (size_t)(p - start);
|
|
188
|
+
return TEPTRIS_OK;
|
|
171
189
|
}
|
|
172
190
|
|
|
173
191
|
/* time-only; TOML 1.1: seconds optional */
|
|
174
192
|
int h = d2(p);
|
|
175
193
|
int mi = d2(p + 3);
|
|
176
194
|
int s = 0;
|
|
177
|
-
size_t
|
|
195
|
+
size_t sec_consumed = 5;
|
|
178
196
|
if ((size_t)(end - p) >= 8 && p[5] == ':') {
|
|
179
197
|
if (!is_dig(p + 6) || !is_dig(p + 7)) {
|
|
180
|
-
|
|
198
|
+
*err = "invalid second";
|
|
199
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
181
200
|
}
|
|
182
201
|
s = d2(p + 6);
|
|
183
|
-
|
|
202
|
+
sec_consumed = 8;
|
|
184
203
|
}
|
|
185
204
|
if (h > 23) {
|
|
186
|
-
|
|
205
|
+
*err = "invalid hour";
|
|
206
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
187
207
|
}
|
|
188
208
|
if (mi > 59) {
|
|
189
|
-
|
|
209
|
+
*err = "invalid minute";
|
|
210
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
190
211
|
}
|
|
191
212
|
if (s > 60) {
|
|
192
|
-
|
|
213
|
+
*err = "invalid second";
|
|
214
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
193
215
|
}
|
|
194
|
-
dt
|
|
195
|
-
dt
|
|
196
|
-
dt
|
|
197
|
-
p +=
|
|
216
|
+
dt->hour = (uint8_t)h;
|
|
217
|
+
dt->minute = (uint8_t)mi;
|
|
218
|
+
dt->second = (uint8_t)s;
|
|
219
|
+
p += sec_consumed;
|
|
198
220
|
|
|
199
221
|
if (p < end && *p == '.') {
|
|
200
222
|
p++;
|
|
201
223
|
if (p >= end || !is_dig(p)) {
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
*err = "expected fractional digits";
|
|
225
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
204
226
|
}
|
|
205
227
|
uint32_t scale = 100000000u;
|
|
206
228
|
uint32_t ns = 0;
|
|
@@ -211,8 +233,43 @@ teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
|
211
233
|
}
|
|
212
234
|
p++;
|
|
213
235
|
}
|
|
214
|
-
dt
|
|
236
|
+
dt->nanosecond = ns;
|
|
215
237
|
}
|
|
216
238
|
|
|
217
|
-
|
|
239
|
+
*kind = TEPTRIS_TIME_LOCAL;
|
|
240
|
+
*consumed = (size_t)(p - start);
|
|
241
|
+
return TEPTRIS_OK;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out)
|
|
245
|
+
{
|
|
246
|
+
const char *p = ps->p;
|
|
247
|
+
const char *end = ps->end;
|
|
248
|
+
const char *err = NULL;
|
|
249
|
+
teptris_datetime dt;
|
|
250
|
+
teptris_kind kind;
|
|
251
|
+
size_t consumed;
|
|
252
|
+
teptris_status st = dt_scan(p, end, &dt, &kind, &consumed, &err);
|
|
253
|
+
if (st != TEPTRIS_OK) {
|
|
254
|
+
return tep_fail_at(ps, NULL, st, err);
|
|
255
|
+
}
|
|
256
|
+
return finish_node(ps, kind, &dt, consumed, out);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
teptris_status teptris_datetime_from_str(const char *s, size_t len,
|
|
260
|
+
teptris_datetime *dt,
|
|
261
|
+
teptris_kind *kind)
|
|
262
|
+
{
|
|
263
|
+
const char *err = NULL;
|
|
264
|
+
size_t consumed;
|
|
265
|
+
teptris_status st = dt_scan(s, s + len, dt, kind, &consumed, &err);
|
|
266
|
+
if (st != TEPTRIS_OK) {
|
|
267
|
+
return st;
|
|
268
|
+
}
|
|
269
|
+
/* a standalone literal must be the WHOLE string: trailing bytes
|
|
270
|
+
* make it a plain string, not a datetime */
|
|
271
|
+
if (consumed != len) {
|
|
272
|
+
return TEPTRIS_ERR_SYNTAX;
|
|
273
|
+
}
|
|
274
|
+
return TEPTRIS_OK;
|
|
218
275
|
}
|
|
@@ -64,6 +64,12 @@ teptris_status teptris_parse_key_path(teptris_parser *ps,
|
|
|
64
64
|
/* datetime.c */
|
|
65
65
|
bool teptris_datetime_lookahead(const teptris_parser *ps);
|
|
66
66
|
teptris_status teptris_parse_datetime(teptris_parser *ps, teptris_node **out);
|
|
67
|
+
/* classify a standalone literal: fills dt + kind when s..s+len is
|
|
68
|
+
* EXACTLY one datetime (trailing bytes -> ERR_SYNTAX, the caller
|
|
69
|
+
* keeps it a plain string) */
|
|
70
|
+
teptris_status teptris_datetime_from_str(const char *s, size_t len,
|
|
71
|
+
teptris_datetime *dt,
|
|
72
|
+
teptris_kind *kind);
|
|
67
73
|
|
|
68
74
|
/* parser.c: skip space/tab (parser loop) — arrays also allow newlines
|
|
69
75
|
* and comments. Both validate comment contents. */
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
#include <string.h>
|
|
10
10
|
|
|
11
11
|
#include "json_read.h"
|
|
12
|
+
#include "teptris/common/ryu/ryu_parse.h"
|
|
12
13
|
#include "teptris/memory/arena.h"
|
|
13
14
|
|
|
14
|
-
#define JSON_MAX_DEPTH
|
|
15
|
+
#define JSON_MAX_DEPTH 512
|
|
15
16
|
|
|
16
17
|
struct jv {
|
|
17
18
|
jv_kind kind;
|
|
@@ -403,7 +404,6 @@ static jv *jvalue(jctx *c) {
|
|
|
403
404
|
memcpy(tmp, c->src + start, tlen);
|
|
404
405
|
tmp[tlen] = '\0';
|
|
405
406
|
v = teptris_arena_alloc(c->a, sizeof(jv));
|
|
406
|
-
*v = (jv){ .num = strtod(tmp, NULL) };
|
|
407
407
|
if (integral) {
|
|
408
408
|
errno = 0;
|
|
409
409
|
char *end = NULL;
|
|
@@ -412,10 +412,28 @@ static jv *jvalue(jctx *c) {
|
|
|
412
412
|
v->kind = JV_INT;
|
|
413
413
|
v->i = (int64_t)i;
|
|
414
414
|
} else {
|
|
415
|
-
|
|
415
|
+
/* out-of-int64 JSON integer: the float view, parsed
|
|
416
|
+
* with the engine's ryu s2d - libc strtod costs
|
|
417
|
+
* ~1.3us/float in wasm (musl), ryu is the same fast
|
|
418
|
+
* correct parse the TOML number path uses */
|
|
419
|
+
double num = 0;
|
|
420
|
+
if (teptris_ryu_s2d_n(tmp, (int)tlen, &num) !=
|
|
421
|
+
TEPTRIS_RYU_SUCCESS) {
|
|
422
|
+
jfail(c, "invalid number");
|
|
423
|
+
c->depth--;
|
|
424
|
+
return NULL;
|
|
425
|
+
}
|
|
426
|
+
*v = (jv){ .kind = JV_NUM, .num = num };
|
|
416
427
|
}
|
|
417
428
|
} else {
|
|
418
|
-
|
|
429
|
+
double num = 0;
|
|
430
|
+
if (teptris_ryu_s2d_n(tmp, (int)tlen, &num) !=
|
|
431
|
+
TEPTRIS_RYU_SUCCESS) {
|
|
432
|
+
jfail(c, "invalid number");
|
|
433
|
+
c->depth--;
|
|
434
|
+
return NULL;
|
|
435
|
+
}
|
|
436
|
+
*v = (jv){ .kind = JV_NUM, .num = num };
|
|
419
437
|
}
|
|
420
438
|
} else {
|
|
421
439
|
jfail(c, "unexpected character");
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/teptris/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.28.0
|
|
5
5
|
platform: arm-linux
|
|
6
6
|
authors:
|
|
7
7
|
- teptris contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A native C extension over libteptris, a C99 TOML 1.1 parser/emitter.
|
|
14
14
|
API shape mirrors the tomlib gem.
|