yerba 0.9.2-arm-linux-gnu → 0.10.0-arm-linux-gnu

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -17
  3. data/exe/arm-linux-gnu/yerba +0 -0
  4. data/ext/yerba/include/yerba.h +56 -34
  5. data/ext/yerba/yerba.c +268 -186
  6. data/lib/yerba/3.2/yerba.so +0 -0
  7. data/lib/yerba/3.3/yerba.so +0 -0
  8. data/lib/yerba/3.4/yerba.so +0 -0
  9. data/lib/yerba/4.0/yerba.so +0 -0
  10. data/lib/yerba/collection.rb +4 -4
  11. data/lib/yerba/document.rb +134 -0
  12. data/lib/yerba/formatting.rb +1 -0
  13. data/lib/yerba/location.rb +8 -1
  14. data/lib/yerba/map.rb +16 -6
  15. data/lib/yerba/node.rb +41 -0
  16. data/lib/yerba/query_result.rb +33 -10
  17. data/lib/yerba/scalar.rb +29 -0
  18. data/lib/yerba/selector.rb +3 -1
  19. data/lib/yerba/sequence.rb +38 -33
  20. data/lib/yerba/version.rb +1 -1
  21. data/rust/Cargo.lock +1 -1
  22. data/rust/Cargo.toml +1 -1
  23. data/rust/src/commands/get.rs +12 -12
  24. data/rust/src/commands/init.rs +8 -8
  25. data/rust/src/commands/insert.rs +4 -18
  26. data/rust/src/commands/location.rs +2 -0
  27. data/rust/src/commands/mod.rs +34 -6
  28. data/rust/src/commands/move_item.rs +1 -1
  29. data/rust/src/commands/move_key.rs +8 -8
  30. data/rust/src/commands/rename.rs +1 -1
  31. data/rust/src/commands/selectors.rs +1 -1
  32. data/rust/src/commands/set.rs +14 -6
  33. data/rust/src/document/condition.rs +25 -25
  34. data/rust/src/document/delete.rs +57 -43
  35. data/rust/src/document/get.rs +91 -82
  36. data/rust/src/document/insert.rs +77 -77
  37. data/rust/src/document/mod.rs +138 -64
  38. data/rust/src/document/nodes.rs +162 -0
  39. data/rust/src/document/schema.rs +8 -8
  40. data/rust/src/document/set.rs +49 -26
  41. data/rust/src/document/sort.rs +54 -54
  42. data/rust/src/document/style.rs +50 -49
  43. data/rust/src/document/unique.rs +5 -5
  44. data/rust/src/error.rs +8 -4
  45. data/rust/src/ffi.rs +218 -106
  46. data/rust/src/json.rs +62 -2
  47. data/rust/src/lib.rs +2 -1
  48. data/rust/src/main.rs +2 -1
  49. data/rust/src/selector.rs +48 -7
  50. data/rust/src/syntax.rs +449 -56
  51. data/rust/src/validation.rs +5 -3
  52. data/rust/src/yerbafile.rs +124 -76
  53. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b49bb4f346300a0924bc402f297040f7e95d185eec8e58d447c006c841ccdf8
4
- data.tar.gz: a66cdd879c698a2de753646009639a7a1175d738c281dea1e5ff7a291d2d40d5
3
+ metadata.gz: 7789ff3de901f30948a18b6cfd0c212338cc61745571c00d831f06b11e6ba20e
4
+ data.tar.gz: 56b6aeb3fa2581196fc1263757938de9e91293e1e0ec41688ceeddf5ecb514b8
5
5
  SHA512:
6
- metadata.gz: c3ce02a7e1f57ee29ab86d3880ba0088510d3026277df6677bb1dd173e9e6bb6b2ed5052a6d32c9a860afbab4a17f508a1c989c894ed50cf64e80b2f02fbb8c1
7
- data.tar.gz: c60175d27fd5e6d87d54ef16d7a6e6c4aa81f85c57edfb4948e9c4bef8894c4e1d740fa0047f6459dd7d8ba8cfd856c3ca7b50cfef9a6a67202ecbae3d8c1c9e
6
+ metadata.gz: 260346f5d5148442585ec2b000a83c12c807213d0d1a34b3e607ff881f3a8514820cfa895a3591bc042590ac50553f5236af132a7bb32ae34ba817cb96f6f04f
7
+ data.tar.gz: 0f3658ebc475a23e90af6b70682dee1502994c6fcb9fc48fd266d7dfbb164b975af6e5ed8da07dc68c9c0d54b077af483700bd55f8b43848875260ba84f867b4
data/README.md CHANGED
@@ -47,7 +47,7 @@ Use `yerba` as a library in your Rust project:
47
47
 
48
48
  ```toml
49
49
  [dependencies]
50
- yerba = "0.9"
50
+ yerba = "0.10"
51
51
  ```
52
52
 
53
53
  ```rust
@@ -93,9 +93,10 @@ Selectors let you address any node in a YAML document:
93
93
  | Pattern | Meaning | Example |
94
94
  |-------------------|---------------------|----------------------------|
95
95
  | `key` | A single key | `"database.host"` |
96
- | `key.nested` | Nested key path | `"database.settings.pool"` |
96
+ | `key.nested` | Nested keys | `"database.settings.pool"` |
97
97
  | `[]` | All items in array | `"[].title"` |
98
98
  | `[N]` | Item at index | `"[0].title"` |
99
+ | `[-N]` | Item from the end | `"[-1].title"` |
99
100
  | `*` | All values in a map | `"database.*"` |
100
101
  | `[].key[].nested` | Nested array access | `"[].speakers[].name"` |
101
102
 
@@ -149,14 +150,14 @@ yerba get videos.yml "[]" --condition ".speakers contains Matz" --raw
149
150
 
150
151
  ### `set`
151
152
 
152
- Update an existing value at a path. The original quote style is preserved automatically, if a value was double-quoted before, it stays double-quoted after the edit.
153
+ Update an existing value at a selector. The original quote style is preserved automatically, if a value was double-quoted before, it stays double-quoted after the edit.
153
154
 
154
155
  ```bash
155
156
  yerba set config.yml "database.host" "0.0.0.0"
156
157
  yerba set videos.yml "[0].title" "New Title"
157
158
  ```
158
159
 
159
- Use `--if-exists` to only set the value when the path already exists, or `--if-missing` to only set it when the path does not exist:
160
+ Use `--if-exists` to only set the value when the selector already exists, or `--if-missing` to only set it when the selector does not exist:
160
161
 
161
162
  ```bash
162
163
  yerba set config.yml "database.host" "0.0.0.0" --if-exists
@@ -189,7 +190,7 @@ Use `--all` to update all nodes matching a wildcard selector:
189
190
  yerba set videos.yml "[].description" "" --all
190
191
  ```
191
192
 
192
- Values are written in the quote style already at the path, which keeps string edits tidy. A value is quoted anyway when writing it plain would not read back as the string you passed, so `yes` becomes `"yes"` and `12345` becomes `"12345"` — whatever the field held before. Use `--plain` to write a YAML literal instead:
193
+ Values are written in the quote style already at the selector, which keeps string edits tidy. A value is quoted anyway when writing it plain would not read back as the string you passed, so `yes` becomes `"yes"` and `12345` becomes `"12345"` — whatever the field held before. Use `--plain` to write a YAML literal instead:
193
194
 
194
195
  ```bash
195
196
  yerba set config.yml "database.replica" null --plain
@@ -469,10 +470,14 @@ Output:
469
470
  "end_line": 2,
470
471
  "end_column": 19,
471
472
  "start_offset": 22,
472
- "end_offset": 32
473
+ "end_offset": 32,
474
+ "start_character_column": 9,
475
+ "end_character_column": 19
473
476
  }
474
477
  ```
475
478
 
479
+ Lines are 1-based and columns are 0-based, like Prism. `start_column` and `end_column` count bytes, `start_character_column` and `end_character_column` count characters, and offsets are byte offsets into the file.
480
+
476
481
  ### `schema`
477
482
 
478
483
  Validate YAML files against a JSON schema:
@@ -482,7 +487,7 @@ yerba schema data/speakers.yml --schema lib/schemas/speaker_schema.json
482
487
  yerba schema "data/**/videos.yml" --schema lib/schemas/video_schema.json
483
488
  ```
484
489
 
485
- Use `--path` to scope validation to a specific selector (e.g. validate each item in an array):
490
+ Use `--selector` to scope validation to a specific selector (e.g. validate each item in an array):
486
491
 
487
492
  ```bash
488
493
  yerba schema data/speakers.yml --schema speaker_schema.json --selector "[]"
@@ -579,11 +584,11 @@ rules:
579
584
  - files: "data/**/videos.yml"
580
585
  pipeline:
581
586
  - quote_style:
582
- path: "[].speakers"
587
+ selector: "[].speakers"
583
588
  value_style: plain
584
589
 
585
590
  - sort_keys:
586
- path: "[]"
591
+ selector: "[]"
587
592
  order:
588
593
  - id
589
594
  - title
@@ -592,7 +597,7 @@ rules:
592
597
  - files: "data/speakers.yml"
593
598
  pipeline:
594
599
  - sort_keys:
595
- path: "[]"
600
+ selector: "[]"
596
601
  order:
597
602
  - name
598
603
  - slug
@@ -602,13 +607,15 @@ rules:
602
607
  by: name
603
608
  ```
604
609
 
610
+ Rules and steps take a `selector` to scope them. `path` is still accepted as the older name for it.
611
+
605
612
  Available pipeline steps:
606
613
 
607
- - `quote_style` Enforce quote style on keys and/or values, optionally scoped by path
614
+ - `quote_style` Enforce quote style on keys and/or values, optionally scoped by selector
608
615
  - `collection_style` Enforce flow or block style on collections
609
616
  - `sequence_indent` Enforce compact or indented sequence style
610
617
  - `sort_keys` Reorder keys to match a predefined list
611
- - `sort` Sort sequence items by field(s)
618
+ - `sort` Sort sequence items by field(s), `by: ".date,.start_time"` or `by: ".date .start_time"` for tie-breakers
612
619
  - `blank_lines` Enforce blank lines between sequence entries, optionally limited to named map keys with `before` and to non-empty values with `skip_empty`
613
620
  - `set` Set a value (supports conditions, and `plain: true` for YAML literals)
614
621
  - `insert` Insert a new key or sequence item (`plain: true` for YAML literals and fragments)
@@ -617,8 +624,8 @@ Available pipeline steps:
617
624
  - `remove` Remove an item from a sequence
618
625
  - `directives` Add or remove the document start marker (`---`), with optional `max` validation
619
626
  - `unique` Find or remove duplicate items in a sequence
620
- - `schema` Validate against a JSON schema (with optional `path` for scoping)
621
- - `escapes` Spell escaped characters literally where the quote style can carry them (with optional `path` for scoping)
627
+ - `schema` Validate against a JSON schema (with optional `selector` for scoping)
628
+ - `escapes` Spell escaped characters literally where the quote style can carry them (with optional `selector` for scoping)
622
629
  - `final_newline` Enforce exact number of trailing newlines (`count: 1` by default, strips extras)
623
630
 
624
631
  This makes it easy to enforce project-wide YAML conventions in CI:
@@ -747,7 +754,7 @@ document["database"]["host"].value # => "localhost"
747
754
  document["database.host"].value # => "localhost" (same thing)
748
755
  ```
749
756
 
750
- The returned object type depends on what's at the path:
757
+ The returned object type depends on what's at the selector:
751
758
 
752
759
  ```ruby
753
760
  document["database"] # => Yerba::Map
@@ -900,9 +907,14 @@ document.sort(by: :name, order: ["Charlie", "Bob", "Alice"])
900
907
  document.sort("tags")
901
908
  document.sort("tags", order: :desc)
902
909
  document.sort("tags", order: ["rust", "ruby", "go"])
910
+ document.sort("tags", order: "rust,ruby,go")
911
+ document.sort(by: [:date, :start_time])
912
+ document.sort(by: ".date .start_time")
903
913
  ```
904
914
 
905
- The `by:` option accepts symbols, strings, or dot-prefixed strings (`:name`, `"name"`, `".name"`).
915
+ The `by:` option accepts symbols, strings, or dot-prefixed strings (`:name`, `"name"`, `".name"`). Several fields, separated by commas or spaces or given as an Array, sort by the first and break ties with the next.
916
+
917
+ The `order:` option is `:asc`, `:desc`, or an explicit order of values as an Array or comma-separated String.
906
918
 
907
919
  ### Querying
908
920
 
@@ -1038,8 +1050,12 @@ loc.end_line # => 2
1038
1050
  loc.end_column # => 19
1039
1051
  loc.start_offset # => 22
1040
1052
  loc.end_offset # => 32
1053
+ loc.start_character_column # => 9
1054
+ loc.end_character_column # => 19
1041
1055
  ```
1042
1056
 
1057
+ Lines are 1-based and columns are 0-based, matching `Prism::Location`. `start_column` and `end_column` count bytes, `start_character_column` and `end_character_column` count characters, so they differ on lines with non-ASCII text before the value.
1058
+
1043
1059
  You can also get a location by selector string:
1044
1060
 
1045
1061
  ```ruby
@@ -1167,7 +1183,7 @@ scalars.first.document.save!
1167
1183
 
1168
1184
  ### Parsing Selectors
1169
1185
 
1170
- `Yerba::Selector` splits a selector into its segments, using the same parser as the rest of Yerba. Keys are Strings, indexes Integers, `[]` is `:all_items` and `*` is `:all_keys`:
1186
+ `Yerba::Selector` splits a selector into its segments, using the same parser as the rest of Yerba. Keys are Strings, indexes Integers (negative from the end), `[]` is `:all_items` and `*` is `:all_keys`:
1171
1187
 
1172
1188
  ```ruby
1173
1189
  selector = Yerba::Selector.parse("[3].talks[1]")
@@ -1178,6 +1194,7 @@ selector.join("speakers", 0).to_s # => "[3].talks[1].speakers[0]"
1178
1194
 
1179
1195
  Yerba::Selector.parse("[].speakers[]").segments # => [:all_items, "speakers", :all_items]
1180
1196
  Yerba::Selector.parse(".title").relative? # => true
1197
+ Yerba::Selector.parse("tags[-1]").segments # => ["tags", -1]
1181
1198
 
1182
1199
  Yerba::Selector.build([3, "talks", 1]).to_s # => "[3].talks[1]"
1183
1200
  ```
Binary file
@@ -46,6 +46,8 @@ typedef struct YerbaLocation {
46
46
  uintptr_t start_column;
47
47
  uintptr_t end_line;
48
48
  uintptr_t end_column;
49
+ uintptr_t start_character_column;
50
+ uintptr_t end_character_column;
49
51
  } YerbaLocation;
50
52
 
51
53
  typedef struct YerbaGetResult {
@@ -64,6 +66,22 @@ typedef struct YerbaResult {
64
66
  char *error;
65
67
  } YerbaResult;
66
68
 
69
+ typedef struct YerbaNodeRecord {
70
+ intptr_t parent;
71
+ enum NodeType node_type;
72
+ char *selector;
73
+ char *key_name;
74
+ struct YerbaTypedValue value;
75
+ bool has_value;
76
+ struct YerbaLocation location;
77
+ struct YerbaLocation key_location;
78
+ } YerbaNodeRecord;
79
+
80
+ typedef struct YerbaNodeList {
81
+ struct YerbaNodeRecord *records;
82
+ uintptr_t length;
83
+ } YerbaNodeList;
84
+
67
85
  struct YerbaParseResult yerba_document_parse_file(const char *path);
68
86
 
69
87
  struct YerbaParseResult yerba_document_parse(const char *content);
@@ -72,33 +90,33 @@ uint64_t yerba_document_generation(const struct Document *document);
72
90
 
73
91
  void yerba_document_free(struct Document *document);
74
92
 
75
- struct YerbaGetResult yerba_document_get(const struct Document *document, const char *path);
93
+ struct YerbaGetResult yerba_document_get(const struct Document *document, const char *selector);
76
94
 
77
95
  /**
78
96
  * Caller must free with yerba_string_free.
79
97
  */
80
- char *yerba_document_source(const struct Document *document, const char *path);
98
+ char *yerba_document_source(const struct Document *document, const char *selector);
81
99
 
82
100
  /**
83
101
  * Caller must free with yerba_string_free.
84
102
  */
85
- char *yerba_document_get_value(const struct Document *document, const char *path);
103
+ char *yerba_document_get_value(const struct Document *document, const char *selector);
86
104
 
87
105
  /**
88
106
  * Caller must free with yerba_string_free.
89
107
  */
90
108
  char *yerba_document_selectors(const struct Document *document);
91
109
 
92
- char *yerba_document_resolve_selectors(const struct Document *document, const char *path);
110
+ char *yerba_document_resolve_selectors(const struct Document *document, const char *selector);
93
111
 
94
- bool yerba_selector_has_wildcard(const char *path);
112
+ bool yerba_selector_has_wildcard(const char *selector);
95
113
 
96
114
  /**
97
115
  * Parses a selector into JSON: `{"relative": bool, "segments": [...]}`.
98
116
  *
99
- * Keys are encoded as strings, indexes as integers, `[]` as `{"all": "items"}` and `*` as `{"all": "keys"}`.
117
+ * Keys are encoded as strings, indexes as integers (negative from the end), `[]` as `{"all": "items"}` and `*` as `{"all": "keys"}`.
100
118
  */
101
- char *yerba_selector_parse(const char *path);
119
+ char *yerba_selector_parse(const char *selector);
102
120
 
103
121
  /**
104
122
  * Builds a selector string from a JSON array of segments, encoded like `yerba_selector_parse` returns them.
@@ -106,43 +124,43 @@ char *yerba_selector_parse(const char *path);
106
124
  char *yerba_selector_build(const char *segments_json,
107
125
  bool relative);
108
126
 
109
- char *yerba_document_keys(const struct Document *document, const char *path);
127
+ char *yerba_document_keys(const struct Document *document, const char *selector);
110
128
 
111
- char *yerba_document_get_quote_style(const struct Document *document, const char *path);
129
+ char *yerba_document_get_quote_style(const struct Document *document, const char *selector);
112
130
 
113
131
  struct YerbaResult yerba_document_set_quote_style(struct Document *document,
114
- const char *path,
132
+ const char *selector,
115
133
  const char *style);
116
134
 
117
- char *yerba_document_get_collection_style(const struct Document *document, const char *path);
135
+ char *yerba_document_get_collection_style(const struct Document *document, const char *selector);
118
136
 
119
137
  struct YerbaResult yerba_document_set_collection_style(struct Document *document,
120
- const char *path,
138
+ const char *selector,
121
139
  const char *style);
122
140
 
123
- char *yerba_document_get_sequence_indent(const struct Document *document, const char *path);
141
+ char *yerba_document_get_sequence_indent(const struct Document *document, const char *selector);
124
142
 
125
143
  struct YerbaResult yerba_document_set_sequence_indent(struct Document *document,
126
- const char *path,
144
+ const char *selector,
127
145
  const char *style);
128
146
 
129
147
  char *yerba_validate_condition(const char *condition, bool item_context);
130
148
 
131
149
  bool yerba_document_evaluate_condition(const struct Document *document,
132
- const char *parent_path,
150
+ const char *parent_selector,
133
151
  const char *condition);
134
152
 
135
- bool yerba_document_exists(const struct Document *document, const char *path);
153
+ bool yerba_document_exists(const struct Document *document, const char *selector);
136
154
 
137
- bool yerba_document_valid_selector(const struct Document *document, const char *path);
155
+ bool yerba_document_valid_selector(const struct Document *document, const char *selector);
138
156
 
139
157
  char *yerba_document_find(const struct Document *document,
140
- const char *path,
158
+ const char *selector,
141
159
  const char *condition,
142
160
  const char *select);
143
161
 
144
162
  struct YerbaResult yerba_document_set(struct Document *document,
145
- const char *path,
163
+ const char *selector,
146
164
  const char *value,
147
165
  uintptr_t value_length,
148
166
  enum YerbaValueType value_type,
@@ -150,7 +168,7 @@ struct YerbaResult yerba_document_set(struct Document *document,
150
168
  bool all);
151
169
 
152
170
  struct YerbaResult yerba_document_insert(struct Document *document,
153
- const char *path,
171
+ const char *selector,
154
172
  const char *value,
155
173
  uintptr_t value_length,
156
174
  enum YerbaValueType value_type,
@@ -161,28 +179,28 @@ struct YerbaResult yerba_document_insert(struct Document *document,
161
179
  int64_t at);
162
180
 
163
181
  struct YerbaResult yerba_document_insert_object(struct Document *document,
164
- const char *path,
182
+ const char *selector,
165
183
  const char *json,
166
184
  const char *before,
167
185
  const char *after,
168
186
  int64_t at);
169
187
 
170
- struct YerbaResult yerba_document_delete(struct Document *document, const char *path);
188
+ struct YerbaResult yerba_document_delete(struct Document *document, const char *selector);
171
189
 
172
190
  struct YerbaResult yerba_document_insert_objects(struct Document *document,
173
- const char *path,
191
+ const char *selector,
174
192
  const char *json);
175
193
 
176
194
  struct YerbaResult yerba_document_remove(struct Document *document,
177
- const char *path,
195
+ const char *selector,
178
196
  const char *value);
179
197
 
180
198
  struct YerbaResult yerba_document_remove_at(struct Document *document,
181
- const char *path,
199
+ const char *selector,
182
200
  uintptr_t index);
183
201
 
184
202
  struct YerbaResult yerba_document_move_item(struct Document *document,
185
- const char *path,
203
+ const char *selector,
186
204
  uintptr_t from,
187
205
  uintptr_t to);
188
206
 
@@ -191,26 +209,26 @@ struct YerbaResult yerba_document_rename(struct Document *document,
191
209
  const char *dest);
192
210
 
193
211
  struct YerbaResult yerba_document_sort(struct Document *document,
194
- const char *path,
212
+ const char *selector,
195
213
  const char *by,
196
214
  bool case_sensitive);
197
215
 
198
216
  struct YerbaResult yerba_document_reorder(struct Document *document,
199
- const char *path,
217
+ const char *selector,
200
218
  const char *by,
201
219
  const char *order_csv);
202
220
 
203
221
  struct YerbaResult yerba_document_sort_keys(struct Document *document,
204
- const char *path,
222
+ const char *selector,
205
223
  const char *order);
206
224
 
207
225
  struct YerbaResult yerba_document_quote_style(struct Document *document,
208
- const char *path,
226
+ const char *selector,
209
227
  const char *key_style,
210
228
  const char *value_style);
211
229
 
212
230
  struct YerbaResult yerba_document_blank_lines(struct Document *document,
213
- const char *path,
231
+ const char *selector,
214
232
  uintptr_t count);
215
233
 
216
234
  /**
@@ -237,14 +255,18 @@ void yerba_string_free(char *s);
237
255
 
238
256
  void yerba_result_free(struct YerbaResult result);
239
257
 
258
+ struct YerbaNodeList yerba_document_nodes(const struct Document *document);
259
+
260
+ void yerba_node_list_free(struct YerbaNodeList list);
261
+
240
262
  void yerba_get_result_free(struct YerbaGetResult result);
241
263
 
242
- struct YerbaTypedList yerba_glob_get(const char *glob_pattern, const char *path);
264
+ struct YerbaTypedList yerba_glob_get(const char *glob_pattern, const char *selector);
243
265
 
244
- struct YerbaTypedList yerba_document_get_all(const struct Document *document, const char *path);
266
+ struct YerbaTypedList yerba_document_get_all(const struct Document *document, const char *selector);
245
267
 
246
268
  struct YerbaTypedList yerba_glob_find(const char *glob_pattern,
247
- const char *path,
269
+ const char *selector,
248
270
  const char *condition,
249
271
  const char *select);
250
272