psych 5.0.2-java → 5.1.0.pre1-java
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/Mavenfile +1 -1
- data/ext/java/org/jruby/ext/psych/PsychEmitter.java +112 -102
- data/ext/java/org/jruby/ext/psych/PsychLibrary.java +5 -27
- data/ext/java/org/jruby/ext/psych/PsychParser.java +193 -136
- data/ext/java/org/jruby/ext/psych/PsychToRuby.java +3 -2
- data/lib/psych/versions.rb +2 -2
- data/lib/psych/visitors/yaml_tree.rb +2 -2
- data/lib/psych.jar +0 -0
- data/lib/psych_jars.rb +1 -1
- data/psych.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3ca9e0683d2ca342865ab6fa4609d505446db917a5745a30d66aa929970190
|
4
|
+
data.tar.gz: 2519befec441ec3e4a5637ae31db529ebc70985474a257f2699bc5a6169ef8b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '05581e2dbd2f83ccde48d893c1555673b123ba5314589e785f6583c4f89624441d9e2feda37e7b1689ecf78fc9d95272f58a5adc6fddcdf8705f7940c0ad588f'
|
7
|
+
data.tar.gz: '0966f93bd2e9bd437205eed8b1f3bf15a6609db548c7f4aca4328514ce7e26f9aff7aa06ae283870f74cd4935ea75a732b67d92bb85044091819acc411ee7ef8'
|
data/Mavenfile
CHANGED
@@ -27,48 +27,54 @@
|
|
27
27
|
***** END LICENSE BLOCK *****/
|
28
28
|
package org.jruby.ext.psych;
|
29
29
|
|
30
|
-
import java.io.IOException;
|
31
|
-
import java.io.OutputStreamWriter;
|
32
|
-
import java.io.Writer;
|
33
|
-
import java.nio.charset.Charset;
|
34
|
-
import java.util.HashMap;
|
35
|
-
import java.util.Map;
|
36
|
-
|
37
30
|
import org.jcodings.Encoding;
|
38
31
|
import org.jcodings.specific.UTF8Encoding;
|
39
32
|
import org.jruby.Ruby;
|
40
33
|
import org.jruby.RubyArray;
|
41
34
|
import org.jruby.RubyBoolean;
|
42
35
|
import org.jruby.RubyClass;
|
43
|
-
import org.jruby.
|
36
|
+
import org.jruby.RubyEncoding;
|
44
37
|
import org.jruby.RubyModule;
|
45
38
|
import org.jruby.RubyObject;
|
46
39
|
import org.jruby.RubyString;
|
47
40
|
import org.jruby.anno.JRubyMethod;
|
48
|
-
import org.jruby.runtime.ObjectAllocator;
|
49
41
|
import org.jruby.runtime.ThreadContext;
|
50
42
|
import org.jruby.runtime.builtin.IRubyObject;
|
43
|
+
import org.jruby.util.ByteList;
|
51
44
|
import org.jruby.util.IOOutputStream;
|
52
45
|
import org.jruby.util.TypeConverter;
|
53
46
|
import org.jruby.util.io.EncodingUtils;
|
54
|
-
import org.
|
55
|
-
import org.
|
56
|
-
import org.
|
57
|
-
import org.
|
58
|
-
import org.
|
59
|
-
import org.
|
60
|
-
import org.
|
61
|
-
import org.
|
62
|
-
import org.
|
63
|
-
import org.
|
64
|
-
import org.
|
65
|
-
import org.
|
66
|
-
import org.
|
67
|
-
import org.
|
68
|
-
import org.
|
69
|
-
import org.
|
70
|
-
|
71
|
-
import
|
47
|
+
import org.snakeyaml.engine.v2.api.DumpSettings;
|
48
|
+
import org.snakeyaml.engine.v2.api.DumpSettingsBuilder;
|
49
|
+
import org.snakeyaml.engine.v2.api.StreamDataWriter;
|
50
|
+
import org.snakeyaml.engine.v2.api.YamlOutputStreamWriter;
|
51
|
+
import org.snakeyaml.engine.v2.common.Anchor;
|
52
|
+
import org.snakeyaml.engine.v2.common.FlowStyle;
|
53
|
+
import org.snakeyaml.engine.v2.common.ScalarStyle;
|
54
|
+
import org.snakeyaml.engine.v2.common.SpecVersion;
|
55
|
+
import org.snakeyaml.engine.v2.emitter.Emitter;
|
56
|
+
import org.snakeyaml.engine.v2.events.AliasEvent;
|
57
|
+
import org.snakeyaml.engine.v2.events.DocumentEndEvent;
|
58
|
+
import org.snakeyaml.engine.v2.events.DocumentStartEvent;
|
59
|
+
import org.snakeyaml.engine.v2.events.Event;
|
60
|
+
import org.snakeyaml.engine.v2.events.ImplicitTuple;
|
61
|
+
import org.snakeyaml.engine.v2.events.MappingEndEvent;
|
62
|
+
import org.snakeyaml.engine.v2.events.MappingStartEvent;
|
63
|
+
import org.snakeyaml.engine.v2.events.ScalarEvent;
|
64
|
+
import org.snakeyaml.engine.v2.events.SequenceEndEvent;
|
65
|
+
import org.snakeyaml.engine.v2.events.SequenceStartEvent;
|
66
|
+
import org.snakeyaml.engine.v2.events.StreamEndEvent;
|
67
|
+
import org.snakeyaml.engine.v2.events.StreamStartEvent;
|
68
|
+
import org.snakeyaml.engine.v2.exceptions.EmitterException;
|
69
|
+
import org.snakeyaml.engine.v2.exceptions.Mark;
|
70
|
+
|
71
|
+
import java.io.IOException;
|
72
|
+
import java.nio.charset.Charset;
|
73
|
+
import java.util.HashMap;
|
74
|
+
import java.util.Map;
|
75
|
+
import java.util.Optional;
|
76
|
+
|
77
|
+
import static org.jruby.runtime.Visibility.PRIVATE;
|
72
78
|
|
73
79
|
public class PsychEmitter extends RubyObject {
|
74
80
|
public static void initPsychEmitter(Ruby runtime, RubyModule psych) {
|
@@ -84,8 +90,7 @@ public class PsychEmitter extends RubyObject {
|
|
84
90
|
|
85
91
|
@JRubyMethod(visibility = PRIVATE)
|
86
92
|
public IRubyObject initialize(ThreadContext context, IRubyObject io) {
|
87
|
-
|
88
|
-
options.setIndent(2);
|
93
|
+
dumpSettingsBuilder.setIndent(2);
|
89
94
|
|
90
95
|
this.io = io;
|
91
96
|
|
@@ -98,10 +103,8 @@ public class PsychEmitter extends RubyObject {
|
|
98
103
|
IRubyObject canonical = rbOptions.callMethod(context, "canonical");
|
99
104
|
IRubyObject level = rbOptions.callMethod(context, "indentation");
|
100
105
|
|
101
|
-
|
102
|
-
|
103
|
-
options.setCanonical(canonical.isTrue());
|
104
|
-
options.setIndent((int)level.convertToInteger().getLongValue());
|
106
|
+
dumpSettingsBuilder.setCanonical(canonical.isTrue());
|
107
|
+
dumpSettingsBuilder.setIndent((int)level.convertToInteger().getLongValue());
|
105
108
|
line_width_set(context, width);
|
106
109
|
|
107
110
|
this.io = io;
|
@@ -115,17 +118,14 @@ public class PsychEmitter extends RubyObject {
|
|
115
118
|
|
116
119
|
initEmitter(context, encoding);
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
emit(context, event);
|
121
|
+
emit(context, NULL_STREAM_START_EVENT);
|
121
122
|
|
122
123
|
return this;
|
123
124
|
}
|
124
125
|
|
125
126
|
@JRubyMethod
|
126
127
|
public IRubyObject end_stream(ThreadContext context) {
|
127
|
-
|
128
|
-
emit(context, event);
|
128
|
+
emit(context, NULL_STREAM_START_EVENT);
|
129
129
|
return this;
|
130
130
|
}
|
131
131
|
|
@@ -133,30 +133,28 @@ public class PsychEmitter extends RubyObject {
|
|
133
133
|
public IRubyObject start_document(ThreadContext context, IRubyObject _version, IRubyObject tags, IRubyObject implicit) {
|
134
134
|
Ruby runtime = context.runtime;
|
135
135
|
|
136
|
-
DumperOptions.Version version = null;
|
137
136
|
boolean implicitBool = implicit.isTrue();
|
138
|
-
Map<String, String> tagsMap = null;
|
139
137
|
|
140
138
|
RubyClass arrayClass = runtime.getArray();
|
141
139
|
TypeConverter.checkType(context, _version, arrayClass);
|
142
140
|
|
143
141
|
RubyArray versionAry = _version.convertToArray();
|
142
|
+
Optional<SpecVersion> specVersion;
|
144
143
|
if (versionAry.size() == 2) {
|
145
144
|
int versionInt0 = versionAry.eltInternal(0).convertToInteger().getIntValue();
|
146
145
|
int versionInt1 = versionAry.eltInternal(1).convertToInteger().getIntValue();
|
147
146
|
|
148
|
-
if (versionInt0
|
149
|
-
if (versionInt1 == 0) {
|
150
|
-
version = DumperOptions.Version.V1_0;
|
151
|
-
} else if (versionInt1 == 1) {
|
152
|
-
version = DumperOptions.Version.V1_1;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
if (version == null) {
|
147
|
+
if (versionInt0 != 1) {
|
156
148
|
throw runtime.newArgumentError("invalid YAML version: " + versionAry);
|
157
149
|
}
|
150
|
+
|
151
|
+
specVersion = Optional.of(new SpecVersion(versionInt0, versionInt1));
|
152
|
+
} else {
|
153
|
+
specVersion = Optional.empty();
|
158
154
|
}
|
159
155
|
|
156
|
+
Map<String, String> tagsMap = new HashMap<>();
|
157
|
+
|
160
158
|
if (!tags.isNil()) {
|
161
159
|
TypeConverter.checkType(context, tags, arrayClass);
|
162
160
|
|
@@ -177,14 +175,14 @@ public class PsychEmitter extends RubyObject {
|
|
177
175
|
}
|
178
176
|
}
|
179
177
|
|
180
|
-
DocumentStartEvent event = new DocumentStartEvent(
|
178
|
+
DocumentStartEvent event = new DocumentStartEvent(!implicitBool, specVersion, tagsMap, NULL_MARK, NULL_MARK);
|
181
179
|
emit(context, event);
|
182
180
|
return this;
|
183
181
|
}
|
184
182
|
|
185
183
|
@JRubyMethod
|
186
184
|
public IRubyObject end_document(ThreadContext context, IRubyObject implicit) {
|
187
|
-
DocumentEndEvent event = new DocumentEndEvent(
|
185
|
+
DocumentEndEvent event = new DocumentEndEvent(!implicit.isTrue(), NULL_MARK, NULL_MARK);
|
188
186
|
emit(context, event);
|
189
187
|
return this;
|
190
188
|
}
|
@@ -206,17 +204,17 @@ public class PsychEmitter extends RubyObject {
|
|
206
204
|
|
207
205
|
valueStr = EncodingUtils.strConvEnc(context, valueStr, valueStr.getEncoding(), UTF8Encoding.INSTANCE);
|
208
206
|
|
209
|
-
|
210
|
-
|
207
|
+
String anchorStr = exportToUTF8(context, anchor, stringClass);
|
208
|
+
String tagStr = exportToUTF8(context, tag, stringClass);
|
211
209
|
|
212
210
|
ScalarEvent event = new ScalarEvent(
|
213
|
-
anchorStr == null ? null : anchorStr
|
214
|
-
|
211
|
+
Optional.ofNullable(anchorStr == null ? null : new Anchor(anchorStr)),
|
212
|
+
Optional.ofNullable(tagStr),
|
215
213
|
new ImplicitTuple(plain.isTrue(), quoted.isTrue()),
|
216
214
|
valueStr.asJavaString(),
|
215
|
+
SCALAR_STYLES[style.convertToInteger().getIntValue()],
|
217
216
|
NULL_MARK,
|
218
|
-
NULL_MARK
|
219
|
-
SCALAR_STYLES[style.convertToInteger().getIntValue()]);
|
217
|
+
NULL_MARK);
|
220
218
|
|
221
219
|
emit(context, event);
|
222
220
|
|
@@ -232,16 +230,16 @@ public class PsychEmitter extends RubyObject {
|
|
232
230
|
|
233
231
|
RubyClass stringClass = context.runtime.getString();
|
234
232
|
|
235
|
-
|
236
|
-
|
233
|
+
String anchorStr = exportToUTF8(context, anchor, stringClass);
|
234
|
+
String tagStr = exportToUTF8(context, tag, stringClass);
|
237
235
|
|
238
236
|
SequenceStartEvent event = new SequenceStartEvent(
|
239
|
-
anchorStr == null ? null : anchorStr
|
240
|
-
|
237
|
+
Optional.ofNullable(anchorStr == null ? null : new Anchor(anchorStr)),
|
238
|
+
Optional.ofNullable(tagStr),
|
241
239
|
implicit.isTrue(),
|
240
|
+
FLOW_STYLES[style.convertToInteger().getIntValue()],
|
242
241
|
NULL_MARK,
|
243
|
-
NULL_MARK
|
244
|
-
FLOW_STYLES[style.convertToInteger().getIntValue()]);
|
242
|
+
NULL_MARK);
|
245
243
|
emit(context, event);
|
246
244
|
return this;
|
247
245
|
}
|
@@ -262,16 +260,16 @@ public class PsychEmitter extends RubyObject {
|
|
262
260
|
|
263
261
|
RubyClass stringClass = context.runtime.getString();
|
264
262
|
|
265
|
-
|
266
|
-
|
263
|
+
String anchorStr = exportToUTF8(context, anchor, stringClass);
|
264
|
+
String tagStr = exportToUTF8(context, tag, stringClass);
|
267
265
|
|
268
266
|
MappingStartEvent event = new MappingStartEvent(
|
269
|
-
anchorStr == null ? null : anchorStr
|
270
|
-
|
267
|
+
Optional.ofNullable(anchorStr == null ? null : new Anchor(anchorStr)),
|
268
|
+
Optional.ofNullable(tagStr),
|
271
269
|
implicit.isTrue(),
|
270
|
+
FLOW_STYLES[style.convertToInteger().getIntValue()],
|
272
271
|
NULL_MARK,
|
273
|
-
NULL_MARK
|
274
|
-
FLOW_STYLES[style.convertToInteger().getIntValue()]);
|
272
|
+
NULL_MARK);
|
275
273
|
|
276
274
|
emit(context, event);
|
277
275
|
|
@@ -289,9 +287,9 @@ public class PsychEmitter extends RubyObject {
|
|
289
287
|
public IRubyObject alias(ThreadContext context, IRubyObject anchor) {
|
290
288
|
RubyClass stringClass = context.runtime.getString();
|
291
289
|
|
292
|
-
|
290
|
+
String anchorStr = exportToUTF8(context, anchor, stringClass);
|
293
291
|
|
294
|
-
AliasEvent event = new AliasEvent(
|
292
|
+
AliasEvent event = new AliasEvent(Optional.of(new Anchor(anchorStr)), NULL_MARK, NULL_MARK);
|
295
293
|
emit(context, event);
|
296
294
|
return this;
|
297
295
|
}
|
@@ -299,40 +297,40 @@ public class PsychEmitter extends RubyObject {
|
|
299
297
|
@JRubyMethod(name = "canonical=")
|
300
298
|
public IRubyObject canonical_set(ThreadContext context, IRubyObject canonical) {
|
301
299
|
// TODO: unclear if this affects a running emitter
|
302
|
-
|
300
|
+
dumpSettingsBuilder.setCanonical(canonical.isTrue());
|
303
301
|
return canonical;
|
304
302
|
}
|
305
303
|
|
306
304
|
@JRubyMethod
|
307
305
|
public IRubyObject canonical(ThreadContext context) {
|
308
306
|
// TODO: unclear if this affects a running emitter
|
309
|
-
return RubyBoolean.newBoolean(context,
|
307
|
+
return RubyBoolean.newBoolean(context, buildDumpSettings().isCanonical());
|
310
308
|
}
|
311
309
|
|
312
310
|
@JRubyMethod(name = "indentation=")
|
313
311
|
public IRubyObject indentation_set(ThreadContext context, IRubyObject level) {
|
314
312
|
// TODO: unclear if this affects a running emitter
|
315
|
-
|
313
|
+
dumpSettingsBuilder.setIndent(level.convertToInteger().getIntValue());
|
316
314
|
return level;
|
317
315
|
}
|
318
316
|
|
319
317
|
@JRubyMethod
|
320
318
|
public IRubyObject indentation(ThreadContext context) {
|
321
319
|
// TODO: unclear if this affects a running emitter
|
322
|
-
return context.runtime.newFixnum(
|
320
|
+
return context.runtime.newFixnum(buildDumpSettings().getIndent());
|
323
321
|
}
|
324
322
|
|
325
323
|
@JRubyMethod(name = "line_width=")
|
326
324
|
public IRubyObject line_width_set(ThreadContext context, IRubyObject width) {
|
327
|
-
int newWidth =
|
325
|
+
int newWidth = width.convertToInteger().getIntValue();
|
328
326
|
if (newWidth <= 0) newWidth = Integer.MAX_VALUE;
|
329
|
-
|
327
|
+
dumpSettingsBuilder.setWidth(newWidth);
|
330
328
|
return width;
|
331
329
|
}
|
332
330
|
|
333
331
|
@JRubyMethod
|
334
332
|
public IRubyObject line_width(ThreadContext context) {
|
335
|
-
return context.runtime.newFixnum(
|
333
|
+
return context.runtime.newFixnum(buildDumpSettings().getWidth());
|
336
334
|
}
|
337
335
|
|
338
336
|
private void emit(ThreadContext context, Event event) {
|
@@ -343,8 +341,6 @@ public class PsychEmitter extends RubyObject {
|
|
343
341
|
|
344
342
|
// flush writer after each emit
|
345
343
|
writer.flush();
|
346
|
-
} catch (IOException ioe) {
|
347
|
-
throw context.runtime.newIOErrorFromException(ioe);
|
348
344
|
} catch (EmitterException ee) {
|
349
345
|
throw context.runtime.newRuntimeError(ee.toString());
|
350
346
|
}
|
@@ -356,41 +352,55 @@ public class PsychEmitter extends RubyObject {
|
|
356
352
|
Encoding encoding = PsychLibrary.YAMLEncoding.values()[(int)_encoding.convertToInteger().getLongValue()].encoding;
|
357
353
|
Charset charset = context.runtime.getEncodingService().charsetForEncoding(encoding);
|
358
354
|
|
359
|
-
writer = new
|
360
|
-
|
355
|
+
writer = new YamlOutputStreamWriter(new IOOutputStream(io, encoding), charset) {
|
356
|
+
@Override
|
357
|
+
public void processIOException(IOException ioe) {
|
358
|
+
throw context.runtime.newIOErrorFromException(ioe);
|
359
|
+
}
|
360
|
+
};
|
361
|
+
emitter = new Emitter(buildDumpSettings(), writer);
|
362
|
+
}
|
363
|
+
|
364
|
+
private DumpSettings buildDumpSettings() {
|
365
|
+
return dumpSettingsBuilder.build();
|
361
366
|
}
|
362
367
|
|
363
|
-
private
|
364
|
-
|
365
|
-
|
366
|
-
TypeConverter.checkType(context, tag, stringClass);
|
367
|
-
tagStr = (RubyString) tag;
|
368
|
-
tagStr = EncodingUtils.strConvEnc(context, tagStr, tagStr.getEncoding(), UTF8Encoding.INSTANCE);
|
368
|
+
private String exportToUTF8(ThreadContext context, IRubyObject maybeString, RubyClass stringClass) {
|
369
|
+
if (maybeString.isNil()) {
|
370
|
+
return null;
|
369
371
|
}
|
370
|
-
|
372
|
+
|
373
|
+
RubyString string;
|
374
|
+
|
375
|
+
TypeConverter.checkType(context, maybeString, stringClass);
|
376
|
+
string = (RubyString) maybeString;
|
377
|
+
ByteList bytes = string.getByteList();
|
378
|
+
|
379
|
+
return RubyEncoding.decodeUTF8(bytes.unsafeBytes(), bytes.begin(), bytes.realSize());
|
371
380
|
}
|
372
381
|
|
373
382
|
Emitter emitter;
|
374
|
-
|
375
|
-
|
383
|
+
StreamDataWriter writer;
|
384
|
+
final DumpSettingsBuilder dumpSettingsBuilder = DumpSettings.builder();
|
376
385
|
IRubyObject io;
|
377
386
|
|
378
|
-
private static final Mark NULL_MARK =
|
387
|
+
private static final Optional<Mark> NULL_MARK = Optional.empty();
|
388
|
+
private static final StreamStartEvent NULL_STREAM_START_EVENT = new StreamStartEvent(NULL_MARK, NULL_MARK);
|
379
389
|
|
380
390
|
// Map style constants from Psych values (ANY = 0 ... FOLDED = 5)
|
381
391
|
// to SnakeYaml values; see psych/nodes/scalar.rb.
|
382
|
-
private static final
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
392
|
+
private static final ScalarStyle[] SCALAR_STYLES = {
|
393
|
+
ScalarStyle.PLAIN, // ANY
|
394
|
+
ScalarStyle.PLAIN,
|
395
|
+
ScalarStyle.SINGLE_QUOTED,
|
396
|
+
ScalarStyle.DOUBLE_QUOTED,
|
397
|
+
ScalarStyle.LITERAL,
|
398
|
+
ScalarStyle.FOLDED
|
389
399
|
};
|
390
400
|
|
391
|
-
private static final
|
392
|
-
|
393
|
-
|
394
|
-
|
401
|
+
private static final FlowStyle[] FLOW_STYLES = {
|
402
|
+
FlowStyle.AUTO,
|
403
|
+
FlowStyle.BLOCK,
|
404
|
+
FlowStyle.FLOW
|
395
405
|
};
|
396
406
|
}
|
@@ -27,10 +27,6 @@
|
|
27
27
|
***** END LICENSE BLOCK *****/
|
28
28
|
package org.jruby.ext.psych;
|
29
29
|
|
30
|
-
import java.io.InputStream;
|
31
|
-
import java.io.IOException;
|
32
|
-
import java.util.Properties;
|
33
|
-
|
34
30
|
import org.jcodings.Encoding;
|
35
31
|
import org.jcodings.specific.UTF16BEEncoding;
|
36
32
|
import org.jcodings.specific.UTF16LEEncoding;
|
@@ -44,7 +40,10 @@ import org.jruby.runtime.ThreadContext;
|
|
44
40
|
import org.jruby.runtime.Visibility;
|
45
41
|
import org.jruby.runtime.builtin.IRubyObject;
|
46
42
|
import org.jruby.runtime.load.Library;
|
47
|
-
|
43
|
+
|
44
|
+
import java.io.IOException;
|
45
|
+
import java.io.InputStream;
|
46
|
+
import java.util.Properties;
|
48
47
|
|
49
48
|
public class PsychLibrary implements Library {
|
50
49
|
private static final String DUMMY_VERSION = "0.0";
|
@@ -54,7 +53,7 @@ public class PsychLibrary implements Library {
|
|
54
53
|
|
55
54
|
// load version from properties packed with the jar
|
56
55
|
Properties props = new Properties();
|
57
|
-
try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.
|
56
|
+
try( InputStream is = runtime.getJRubyClassLoader().getResourceAsStream("META-INF/maven/org.snakeyaml/snakeyaml-engine/pom.properties") ) {
|
58
57
|
props.load(is);
|
59
58
|
}
|
60
59
|
catch( IOException e ) {
|
@@ -66,27 +65,6 @@ public class PsychLibrary implements Library {
|
|
66
65
|
snakeyamlVersion = snakeyamlVersion.substring(0, snakeyamlVersion.length() - "-SNAPSHOT".length());
|
67
66
|
}
|
68
67
|
|
69
|
-
// Try to determine if we have a new enough SnakeYAML.
|
70
|
-
// Versions before 1.21 removed a Mark constructor that JRuby uses.
|
71
|
-
// See https://github.com/bundler/bundler/issues/6878
|
72
|
-
if (snakeyamlVersion.equals(DUMMY_VERSION)) {
|
73
|
-
try {
|
74
|
-
// Use reflection to try to confirm we have a new enough version
|
75
|
-
Mark.class.getConstructor(String.class, int.class, int.class, int.class, int[].class, int.class);
|
76
|
-
} catch (NoSuchMethodException nsme) {
|
77
|
-
throw runtime.newLoadError("bad SnakeYAML version, required 1.21 or higher; check your CLASSPATH for a conflicting jar");
|
78
|
-
}
|
79
|
-
} else {
|
80
|
-
// Parse version string to check for 1.21+
|
81
|
-
String[] majorMinor = snakeyamlVersion.split("\\.");
|
82
|
-
|
83
|
-
if (majorMinor.length < 2 || Integer.parseInt(majorMinor[0]) < 1 || Integer.parseInt(majorMinor[1]) < 21) {
|
84
|
-
throw runtime.newLoadError(
|
85
|
-
"bad SnakeYAML version " + snakeyamlVersion +
|
86
|
-
", required 1.21 or higher; check your CLASSPATH for a conflicting jar");
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
68
|
RubyString version = runtime.newString(snakeyamlVersion + ".0");
|
91
69
|
version.setFrozen(true);
|
92
70
|
psych.setConstant("SNAKEYAML_VERSION", version);
|
@@ -27,15 +27,6 @@
|
|
27
27
|
***** END LICENSE BLOCK *****/
|
28
28
|
package org.jruby.ext.psych;
|
29
29
|
|
30
|
-
import java.io.ByteArrayInputStream;
|
31
|
-
import java.io.InputStreamReader;
|
32
|
-
import java.nio.charset.Charset;
|
33
|
-
import java.nio.charset.CharsetDecoder;
|
34
|
-
import java.nio.charset.CodingErrorAction;
|
35
|
-
import java.nio.charset.MalformedInputException;
|
36
|
-
import java.util.Arrays;
|
37
|
-
import java.util.Map;
|
38
|
-
|
39
30
|
import org.jcodings.Encoding;
|
40
31
|
import org.jcodings.specific.UTF16BEEncoding;
|
41
32
|
import org.jcodings.specific.UTF16LEEncoding;
|
@@ -52,48 +43,59 @@ import org.jruby.RubyModule;
|
|
52
43
|
import org.jruby.RubyObject;
|
53
44
|
import org.jruby.RubyString;
|
54
45
|
import org.jruby.anno.JRubyMethod;
|
55
|
-
import static org.jruby.ext.psych.PsychLibrary.YAMLEncoding.*;
|
56
46
|
import org.jruby.runtime.Block;
|
57
47
|
import org.jruby.runtime.Helpers;
|
58
48
|
import org.jruby.runtime.ThreadContext;
|
59
49
|
import org.jruby.runtime.builtin.IRubyObject;
|
60
50
|
import org.jruby.runtime.callsite.CachingCallSite;
|
61
51
|
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
|
52
|
+
import org.jruby.util.ByteList;
|
62
53
|
import org.jruby.util.IOInputStream;
|
63
54
|
import org.jruby.util.io.EncodingUtils;
|
64
|
-
import org.
|
65
|
-
import org.
|
66
|
-
import org.
|
67
|
-
import org.
|
68
|
-
import org.
|
69
|
-
import org.
|
70
|
-
import org.
|
71
|
-
import org.
|
72
|
-
import org.
|
73
|
-
import org.
|
74
|
-
import org.
|
75
|
-
import org.
|
76
|
-
import org.
|
77
|
-
import org.
|
78
|
-
import org.
|
79
|
-
import org.
|
80
|
-
import org.
|
81
|
-
import org.
|
55
|
+
import org.snakeyaml.engine.v2.api.LoadSettings;
|
56
|
+
import org.snakeyaml.engine.v2.api.LoadSettingsBuilder;
|
57
|
+
import org.snakeyaml.engine.v2.common.Anchor;
|
58
|
+
import org.snakeyaml.engine.v2.common.FlowStyle;
|
59
|
+
import org.snakeyaml.engine.v2.common.ScalarStyle;
|
60
|
+
import org.snakeyaml.engine.v2.common.SpecVersion;
|
61
|
+
import org.snakeyaml.engine.v2.events.AliasEvent;
|
62
|
+
import org.snakeyaml.engine.v2.events.DocumentEndEvent;
|
63
|
+
import org.snakeyaml.engine.v2.events.DocumentStartEvent;
|
64
|
+
import org.snakeyaml.engine.v2.events.Event;
|
65
|
+
import org.snakeyaml.engine.v2.events.ImplicitTuple;
|
66
|
+
import org.snakeyaml.engine.v2.events.MappingStartEvent;
|
67
|
+
import org.snakeyaml.engine.v2.events.ScalarEvent;
|
68
|
+
import org.snakeyaml.engine.v2.events.SequenceStartEvent;
|
69
|
+
import org.snakeyaml.engine.v2.exceptions.Mark;
|
70
|
+
import org.snakeyaml.engine.v2.exceptions.MarkedYamlEngineException;
|
71
|
+
import org.snakeyaml.engine.v2.exceptions.ParserException;
|
72
|
+
import org.snakeyaml.engine.v2.exceptions.ReaderException;
|
73
|
+
import org.snakeyaml.engine.v2.exceptions.ScannerException;
|
74
|
+
import org.snakeyaml.engine.v2.exceptions.YamlEngineException;
|
75
|
+
import org.snakeyaml.engine.v2.parser.Parser;
|
76
|
+
import org.snakeyaml.engine.v2.parser.ParserImpl;
|
77
|
+
import org.snakeyaml.engine.v2.scanner.ScannerImpl;
|
78
|
+
import org.snakeyaml.engine.v2.scanner.StreamReader;
|
79
|
+
import org.snakeyaml.engine.v2.schema.CoreSchema;
|
82
80
|
|
81
|
+
import java.io.ByteArrayInputStream;
|
82
|
+
import java.io.InputStreamReader;
|
83
|
+
import java.nio.charset.Charset;
|
84
|
+
import java.nio.charset.CharsetDecoder;
|
85
|
+
import java.nio.charset.CodingErrorAction;
|
86
|
+
import java.nio.charset.MalformedInputException;
|
87
|
+
import java.util.Arrays;
|
88
|
+
import java.util.Map;
|
89
|
+
import java.util.Optional;
|
90
|
+
|
91
|
+
import static org.jruby.ext.psych.PsychLibrary.YAMLEncoding.*;
|
83
92
|
import static org.jruby.runtime.Helpers.arrayOf;
|
84
93
|
import static org.jruby.runtime.Helpers.invoke;
|
85
|
-
import org.jruby.util.ByteList;
|
86
94
|
|
87
95
|
public class PsychParser extends RubyObject {
|
88
96
|
|
89
97
|
public static final String JRUBY_CALL_SITES = "_jruby_call_sites";
|
90
98
|
|
91
|
-
private enum Call {
|
92
|
-
path, event_location, start_stream, start_document, end_document, alias, scalar, start_sequence, end_sequence, start_mapping, end_mapping, end_stream
|
93
|
-
}
|
94
|
-
|
95
|
-
final CachingCallSite[] sites;
|
96
|
-
|
97
99
|
public static void initPsychParser(Ruby runtime, RubyModule psych) {
|
98
100
|
RubyClass psychParser = runtime.defineClassUnder("Parser", runtime.getObject(), PsychParser::new, psych);
|
99
101
|
|
@@ -115,44 +117,72 @@ public class PsychParser extends RubyObject {
|
|
115
117
|
public PsychParser(Ruby runtime, RubyClass klass) {
|
116
118
|
super(runtime, klass);
|
117
119
|
|
118
|
-
|
120
|
+
CachingCallSite[] sites = (CachingCallSite[]) klass.getInternalVariable(JRUBY_CALL_SITES);
|
121
|
+
this.path = sites[Call.path.ordinal()];
|
122
|
+
this.event_location = sites[Call.event_location.ordinal()];
|
123
|
+
this.start_stream = sites[Call.start_stream.ordinal()];
|
124
|
+
this.start_document = sites[Call.start_document.ordinal()];
|
125
|
+
this.end_document = sites[Call.end_document.ordinal()];
|
126
|
+
this.alias = sites[Call.alias.ordinal()];
|
127
|
+
this.scalar = sites[Call.scalar.ordinal()];
|
128
|
+
this.start_sequence = sites[Call.start_sequence.ordinal()];
|
129
|
+
this.end_sequence = sites[Call.end_sequence.ordinal()];
|
130
|
+
this.start_mapping = sites[Call.start_mapping.ordinal()];
|
131
|
+
this.end_mapping = sites[Call.end_mapping.ordinal()];
|
132
|
+
this.end_stream = sites[Call.end_stream.ordinal()];
|
133
|
+
this.loadSettingsBuilder = LoadSettings.builder().setSchema(new CoreSchema());
|
119
134
|
}
|
120
135
|
|
121
|
-
private IRubyObject
|
122
|
-
if (value
|
136
|
+
private IRubyObject stringOrNilForAnchor(ThreadContext context, Optional<Anchor> value) {
|
137
|
+
if (!value.isPresent()) return context.nil;
|
123
138
|
|
124
|
-
return stringFor(context, value);
|
139
|
+
return stringFor(context, value.get().getValue());
|
140
|
+
}
|
141
|
+
|
142
|
+
private IRubyObject stringOrNilFor(ThreadContext context, Optional<String> value) {
|
143
|
+
if (!value.isPresent()) return context.nil;
|
144
|
+
|
145
|
+
return stringFor(context, value.get());
|
125
146
|
}
|
126
147
|
|
127
|
-
private
|
148
|
+
private IRubyObject stringFor(ThreadContext context, String value) {
|
128
149
|
Ruby runtime = context.runtime;
|
129
150
|
|
151
|
+
boolean isUTF8 = true;
|
152
|
+
Charset charset = RubyEncoding.UTF8;
|
153
|
+
|
130
154
|
Encoding encoding = runtime.getDefaultInternalEncoding();
|
131
155
|
if (encoding == null) {
|
132
156
|
encoding = UTF8Encoding.INSTANCE;
|
157
|
+
charset = RubyEncoding.UTF8;
|
158
|
+
} else {
|
159
|
+
Charset encodingCharset = encoding.getCharset();
|
160
|
+
if (encodingCharset != null) {
|
161
|
+
isUTF8 = encodingCharset == RubyEncoding.UTF8;
|
162
|
+
charset = encodingCharset;
|
163
|
+
}
|
133
164
|
}
|
134
165
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
ByteList bytes = new ByteList(value.getBytes(charset), encoding);
|
166
|
+
ByteList bytes = new ByteList(
|
167
|
+
isUTF8 ?
|
168
|
+
RubyEncoding.encodeUTF8(value) :
|
169
|
+
RubyEncoding.encode(value, charset),
|
170
|
+
encoding);
|
141
171
|
RubyString string = RubyString.newString(runtime, bytes);
|
142
172
|
|
143
173
|
return string;
|
144
174
|
}
|
145
175
|
|
146
|
-
private StreamReader readerFor(ThreadContext context, IRubyObject yaml) {
|
176
|
+
private StreamReader readerFor(ThreadContext context, IRubyObject yaml, LoadSettings loadSettings) {
|
147
177
|
if (yaml instanceof RubyString) {
|
148
|
-
return readerForString(context, (RubyString) yaml);
|
178
|
+
return readerForString(context, (RubyString) yaml, loadSettings);
|
149
179
|
}
|
150
180
|
|
151
181
|
// fall back on IOInputStream, using default charset
|
152
|
-
return readerForIO(context, yaml);
|
182
|
+
return readerForIO(context, yaml, loadSettings);
|
153
183
|
}
|
154
184
|
|
155
|
-
private static StreamReader readerForIO(ThreadContext context, IRubyObject yaml) {
|
185
|
+
private static StreamReader readerForIO(ThreadContext context, IRubyObject yaml, LoadSettings loadSettings) {
|
156
186
|
boolean isIO = yaml instanceof RubyIO;
|
157
187
|
if (isIO || yaml.respondsTo("read")) {
|
158
188
|
// default to UTF8 unless RubyIO has UTF16 as encoding
|
@@ -170,7 +200,7 @@ public class PsychParser extends RubyObject {
|
|
170
200
|
CharsetDecoder decoder = charset.newDecoder();
|
171
201
|
decoder.onMalformedInput(CodingErrorAction.REPORT);
|
172
202
|
|
173
|
-
return new StreamReader(new InputStreamReader(new IOInputStream(yaml), decoder));
|
203
|
+
return new StreamReader(loadSettings, new InputStreamReader(new IOInputStream(yaml), decoder));
|
174
204
|
} else {
|
175
205
|
Ruby runtime = context.runtime;
|
176
206
|
|
@@ -178,7 +208,7 @@ public class PsychParser extends RubyObject {
|
|
178
208
|
}
|
179
209
|
}
|
180
210
|
|
181
|
-
private static StreamReader readerForString(ThreadContext context, RubyString string) {
|
211
|
+
private static StreamReader readerForString(ThreadContext context, RubyString string, LoadSettings loadSettings) {
|
182
212
|
ByteList byteList = string.getByteList();
|
183
213
|
Encoding enc = byteList.getEncoding();
|
184
214
|
|
@@ -196,7 +226,7 @@ public class PsychParser extends RubyObject {
|
|
196
226
|
|
197
227
|
InputStreamReader isr = new InputStreamReader(bais, charset);
|
198
228
|
|
199
|
-
return new StreamReader(isr);
|
229
|
+
return new StreamReader(loadSettings, isr);
|
200
230
|
}
|
201
231
|
|
202
232
|
@JRubyMethod(name = "_native_parse")
|
@@ -204,52 +234,61 @@ public class PsychParser extends RubyObject {
|
|
204
234
|
Ruby runtime = context.runtime;
|
205
235
|
|
206
236
|
try {
|
207
|
-
|
237
|
+
LoadSettings loadSettings = loadSettingsBuilder.build();
|
238
|
+
parser = new ParserImpl(loadSettings, new ScannerImpl(loadSettings, readerFor(context, yaml, loadSettings)));
|
208
239
|
|
209
240
|
if (path.isNil() && yaml.respondsTo("path")) {
|
210
|
-
path =
|
241
|
+
path = this.path.call(context, this, yaml);
|
211
242
|
}
|
212
243
|
|
213
|
-
while (
|
214
|
-
event = parser.
|
244
|
+
while (parser.hasNext()) {
|
245
|
+
event = parser.next();
|
215
246
|
|
216
|
-
Mark start = event.getStartMark();
|
247
|
+
Mark start = event.getStartMark().orElseThrow(RuntimeException::new);
|
217
248
|
IRubyObject start_line = runtime.newFixnum(start.getLine());
|
218
249
|
IRubyObject start_column = runtime.newFixnum(start.getColumn());
|
219
250
|
|
220
|
-
Mark end = event.getEndMark();
|
251
|
+
Mark end = event.getEndMark().orElseThrow(RuntimeException::new);
|
221
252
|
IRubyObject end_line = runtime.newFixnum(end.getLine());
|
222
253
|
IRubyObject end_column = runtime.newFixnum(end.getColumn());
|
223
254
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
255
|
+
event_location.call(context, this, handler, start_line, start_column, end_line, end_column);
|
256
|
+
|
257
|
+
switch (event.getEventId()) {
|
258
|
+
case StreamStart:
|
259
|
+
start_stream.call(context, this, handler, runtime.newFixnum(YAML_ANY_ENCODING.ordinal()));
|
260
|
+
break;
|
261
|
+
case DocumentStart:
|
262
|
+
handleDocumentStart(context, (DocumentStartEvent) event, handler);
|
263
|
+
break;
|
264
|
+
case DocumentEnd:
|
265
|
+
IRubyObject notExplicit = runtime.newBoolean(!((DocumentEndEvent) event).isExplicit());
|
266
|
+
|
267
|
+
end_document.call(context, this, handler, notExplicit);
|
268
|
+
break;
|
269
|
+
case Alias:
|
270
|
+
IRubyObject alias = stringOrNilForAnchor(context, ((AliasEvent) event).getAnchor());
|
271
|
+
|
272
|
+
this.alias.call(context, this, handler, alias);
|
273
|
+
break;
|
274
|
+
case Scalar:
|
275
|
+
handleScalar(context, (ScalarEvent) event, handler);
|
276
|
+
break;
|
277
|
+
case SequenceStart:
|
278
|
+
handleSequenceStart(context, (SequenceStartEvent) event, handler);
|
279
|
+
break;
|
280
|
+
case SequenceEnd:
|
281
|
+
end_sequence.call(context, this, handler);
|
282
|
+
break;
|
283
|
+
case MappingStart:
|
284
|
+
handleMappingStart(context, (MappingStartEvent) event, handler);
|
285
|
+
break;
|
286
|
+
case MappingEnd:
|
287
|
+
end_mapping.call(context, this, handler);
|
288
|
+
break;
|
289
|
+
case StreamEnd:
|
290
|
+
end_stream.call(context, this, handler);
|
291
|
+
break;
|
253
292
|
}
|
254
293
|
}
|
255
294
|
} catch (ParserException pe) {
|
@@ -268,7 +307,7 @@ public class PsychParser extends RubyObject {
|
|
268
307
|
parser = null;
|
269
308
|
raiseParserException(context, re, path);
|
270
309
|
|
271
|
-
} catch (
|
310
|
+
} catch (YamlEngineException ye) {
|
272
311
|
Throwable cause = ye.getCause();
|
273
312
|
|
274
313
|
if (cause instanceof MalformedInputException) {
|
@@ -288,92 +327,97 @@ public class PsychParser extends RubyObject {
|
|
288
327
|
|
289
328
|
private void handleDocumentStart(ThreadContext context, DocumentStartEvent dse, IRubyObject handler) {
|
290
329
|
Ruby runtime = context.runtime;
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
330
|
+
|
331
|
+
Optional<SpecVersion> specVersion = dse.getSpecVersion();
|
332
|
+
IRubyObject version = specVersion.isPresent() ?
|
333
|
+
RubyArray.newArray(runtime, runtime.newFixnum(specVersion.get().getMajor()), runtime.newFixnum(specVersion.get().getMinor())) :
|
334
|
+
RubyArray.newEmptyArray(runtime);
|
335
|
+
|
296
336
|
Map<String, String> tagsMap = dse.getTags();
|
297
|
-
RubyArray tags
|
298
|
-
|
337
|
+
RubyArray tags;
|
338
|
+
int size;
|
339
|
+
if (tagsMap != null && (size = tagsMap.size()) > 0) {
|
340
|
+
tags = RubyArray.newArray(runtime, size);
|
299
341
|
for (Map.Entry<String, String> tag : tagsMap.entrySet()) {
|
300
|
-
IRubyObject key
|
342
|
+
IRubyObject key = stringFor(context, tag.getKey());
|
301
343
|
IRubyObject value = stringFor(context, tag.getValue());
|
302
344
|
|
303
345
|
tags.append(RubyArray.newArray(runtime, key, value));
|
304
346
|
}
|
347
|
+
} else {
|
348
|
+
tags = RubyArray.newEmptyArray(runtime);
|
305
349
|
}
|
306
|
-
IRubyObject notExplicit = runtime.newBoolean(!dse.getExplicit());
|
307
350
|
|
308
|
-
|
351
|
+
IRubyObject notExplicit = runtime.newBoolean(!dse.isExplicit());
|
352
|
+
|
353
|
+
start_document.call(context, this, handler, version, tags, notExplicit);
|
309
354
|
}
|
310
355
|
|
311
356
|
private void handleMappingStart(ThreadContext context, MappingStartEvent mse, IRubyObject handler) {
|
312
357
|
Ruby runtime = context.runtime;
|
313
|
-
IRubyObject anchor =
|
358
|
+
IRubyObject anchor = stringOrNilForAnchor(context, mse.getAnchor());
|
314
359
|
IRubyObject tag = stringOrNilFor(context, mse.getTag());
|
315
|
-
IRubyObject implicit = runtime.newBoolean(mse.
|
360
|
+
IRubyObject implicit = runtime.newBoolean(mse.isImplicit());
|
316
361
|
IRubyObject style = runtime.newFixnum(translateFlowStyle(mse.getFlowStyle()));
|
317
362
|
|
318
|
-
|
363
|
+
start_mapping.call(context, this, handler, anchor, tag, implicit, style);
|
319
364
|
}
|
320
365
|
|
321
366
|
private void handleScalar(ThreadContext context, ScalarEvent se, IRubyObject handler) {
|
322
367
|
Ruby runtime = context.runtime;
|
323
368
|
|
324
|
-
IRubyObject anchor =
|
369
|
+
IRubyObject anchor = stringOrNilForAnchor(context, se.getAnchor());
|
325
370
|
IRubyObject tag = stringOrNilFor(context, se.getTag());
|
326
|
-
|
327
|
-
IRubyObject
|
371
|
+
ImplicitTuple implicit = se.getImplicit();
|
372
|
+
IRubyObject plain_implicit = runtime.newBoolean(implicit.canOmitTagInPlainScalar());
|
373
|
+
IRubyObject quoted_implicit = runtime.newBoolean(implicit.canOmitTagInNonPlainScalar());
|
328
374
|
IRubyObject style = runtime.newFixnum(translateStyle(se.getScalarStyle()));
|
329
375
|
IRubyObject val = stringFor(context, se.getValue());
|
330
376
|
|
331
|
-
|
377
|
+
scalar.call(context, this, handler, val, anchor, tag, plain_implicit,
|
332
378
|
quoted_implicit, style);
|
333
379
|
}
|
334
380
|
|
335
381
|
private void handleSequenceStart(ThreadContext context, SequenceStartEvent sse, IRubyObject handler) {
|
336
382
|
Ruby runtime = context.runtime;
|
337
|
-
IRubyObject anchor =
|
383
|
+
IRubyObject anchor = stringOrNilForAnchor(context, sse.getAnchor());
|
338
384
|
IRubyObject tag = stringOrNilFor(context, sse.getTag());
|
339
|
-
IRubyObject implicit = runtime.newBoolean(sse.
|
385
|
+
IRubyObject implicit = runtime.newBoolean(sse.isImplicit());
|
340
386
|
IRubyObject style = runtime.newFixnum(translateFlowStyle(sse.getFlowStyle()));
|
341
387
|
|
342
|
-
|
388
|
+
start_sequence.call(context, this, handler, anchor, tag, implicit, style);
|
343
389
|
}
|
344
390
|
|
345
391
|
private static void raiseParserException(ThreadContext context, ReaderException re, IRubyObject rbPath) {
|
346
|
-
Ruby runtime;
|
392
|
+
Ruby runtime = context.runtime;
|
347
393
|
RubyClass se;
|
348
394
|
IRubyObject exception;
|
349
395
|
|
350
|
-
|
351
|
-
se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError");
|
396
|
+
se = (RubyClass) runtime.getModule("Psych").getConstant("SyntaxError");
|
352
397
|
|
353
398
|
exception = se.newInstance(context,
|
354
399
|
new IRubyObject[] {
|
355
400
|
rbPath,
|
356
|
-
|
357
|
-
|
401
|
+
RubyFixnum.zero(runtime),
|
402
|
+
RubyFixnum.zero(runtime),
|
358
403
|
runtime.newFixnum(re.getPosition()),
|
359
|
-
(null == re.getName() ?
|
360
|
-
(null == re.toString() ?
|
404
|
+
(null == re.getName() ? context.nil : runtime.newString(re.getName())),
|
405
|
+
(null == re.toString() ? context.nil : runtime.newString(re.toString()))
|
361
406
|
},
|
362
407
|
Block.NULL_BLOCK);
|
363
408
|
|
364
409
|
RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK);
|
365
410
|
}
|
366
411
|
|
367
|
-
private static void raiseParserException(ThreadContext context,
|
368
|
-
Ruby runtime;
|
412
|
+
private static void raiseParserException(ThreadContext context, MarkedYamlEngineException mye, IRubyObject rbPath) {
|
413
|
+
Ruby runtime = context.runtime;
|
369
414
|
Mark mark;
|
370
415
|
RubyClass se;
|
371
416
|
IRubyObject exception;
|
372
417
|
|
373
|
-
runtime = context.runtime;
|
374
418
|
se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError");
|
375
419
|
|
376
|
-
mark = mye.getProblemMark();
|
420
|
+
mark = mye.getProblemMark().get();
|
377
421
|
|
378
422
|
exception = se.newInstance(context,
|
379
423
|
new IRubyObject[] {
|
@@ -381,8 +425,8 @@ public class PsychParser extends RubyObject {
|
|
381
425
|
runtime.newFixnum(mark.getLine() + 1),
|
382
426
|
runtime.newFixnum(mark.getColumn() + 1),
|
383
427
|
runtime.newFixnum(mark.getIndex()),
|
384
|
-
(null == mye.getProblem() ?
|
385
|
-
(null == mye.getContext() ?
|
428
|
+
(null == mye.getProblem() ? context.nil : runtime.newString(mye.getProblem())),
|
429
|
+
(null == mye.getContext() ? context.nil : runtime.newString(mye.getContext()))
|
386
430
|
},
|
387
431
|
Block.NULL_BLOCK);
|
388
432
|
|
@@ -390,11 +434,10 @@ public class PsychParser extends RubyObject {
|
|
390
434
|
}
|
391
435
|
|
392
436
|
private static void raiseParserException(ThreadContext context, MalformedInputException mie, IRubyObject rbPath) {
|
393
|
-
Ruby runtime
|
437
|
+
Ruby runtime = context.runtime;
|
394
438
|
RubyClass se;
|
395
439
|
IRubyObject exception;
|
396
440
|
|
397
|
-
runtime = context.runtime;
|
398
441
|
se = (RubyClass)runtime.getModule("Psych").getConstant("SyntaxError");
|
399
442
|
|
400
443
|
mie.getInputLength();
|
@@ -402,18 +445,18 @@ public class PsychParser extends RubyObject {
|
|
402
445
|
exception = se.newInstance(context,
|
403
446
|
arrayOf(
|
404
447
|
rbPath,
|
405
|
-
|
406
|
-
|
448
|
+
RubyFixnum.minus_one(runtime),
|
449
|
+
RubyFixnum.minus_one(runtime),
|
407
450
|
runtime.newFixnum(mie.getInputLength()),
|
408
|
-
|
409
|
-
|
451
|
+
context.nil,
|
452
|
+
context.nil
|
410
453
|
),
|
411
454
|
Block.NULL_BLOCK);
|
412
455
|
|
413
456
|
RubyKernel.raise(context, runtime.getKernel(), new IRubyObject[] { exception }, Block.NULL_BLOCK);
|
414
457
|
}
|
415
458
|
|
416
|
-
private static int translateStyle(
|
459
|
+
private static int translateStyle(ScalarStyle style) {
|
417
460
|
if (style == null) return 0; // any
|
418
461
|
|
419
462
|
switch (style) {
|
@@ -426,7 +469,7 @@ public class PsychParser extends RubyObject {
|
|
426
469
|
}
|
427
470
|
}
|
428
471
|
|
429
|
-
private static int translateFlowStyle(
|
472
|
+
private static int translateFlowStyle(FlowStyle flowStyle) {
|
430
473
|
switch (flowStyle) {
|
431
474
|
case AUTO: return 0;
|
432
475
|
case BLOCK: return 1;
|
@@ -441,14 +484,17 @@ public class PsychParser extends RubyObject {
|
|
441
484
|
|
442
485
|
Event event = null;
|
443
486
|
|
487
|
+
Parser parser = this.parser;
|
444
488
|
if (parser != null) {
|
445
|
-
|
446
|
-
|
447
|
-
|
489
|
+
if (parser.hasNext()) {
|
490
|
+
event = parser.peekEvent();
|
491
|
+
} else {
|
492
|
+
event = this.event;
|
493
|
+
}
|
448
494
|
}
|
449
495
|
|
450
496
|
if (event == null) {
|
451
|
-
return ((RubyClass)
|
497
|
+
return ((RubyClass) runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
|
452
498
|
context,
|
453
499
|
RubyFixnum.zero(runtime),
|
454
500
|
RubyFixnum.zero(runtime),
|
@@ -457,9 +503,9 @@ public class PsychParser extends RubyObject {
|
|
457
503
|
);
|
458
504
|
}
|
459
505
|
|
460
|
-
Mark mark = event.getStartMark();
|
506
|
+
Mark mark = event.getStartMark().orElseThrow(RuntimeException::new);
|
461
507
|
|
462
|
-
return ((RubyClass)
|
508
|
+
return ((RubyClass) runtime.getClassFromPath("Psych::Parser::Mark")).newInstance(
|
463
509
|
context,
|
464
510
|
RubyFixnum.zero(runtime),
|
465
511
|
runtime.newFixnum(mark.getLine()),
|
@@ -468,6 +514,17 @@ public class PsychParser extends RubyObject {
|
|
468
514
|
);
|
469
515
|
}
|
470
516
|
|
517
|
+
private LoadSettings buildSettings() {
|
518
|
+
return loadSettingsBuilder.build();
|
519
|
+
}
|
520
|
+
|
471
521
|
private Parser parser;
|
472
522
|
private Event event;
|
523
|
+
private final LoadSettingsBuilder loadSettingsBuilder;
|
524
|
+
|
525
|
+
private enum Call {
|
526
|
+
path, event_location, start_stream, start_document, end_document, alias, scalar, start_sequence, end_sequence, start_mapping, end_mapping, end_stream
|
527
|
+
}
|
528
|
+
|
529
|
+
private final CachingCallSite path, event_location, start_stream, start_document, end_document, alias, scalar, start_sequence, end_sequence, start_mapping, end_mapping, end_stream;
|
473
530
|
}
|
@@ -29,14 +29,15 @@ package org.jruby.ext.psych;
|
|
29
29
|
|
30
30
|
import org.jruby.Ruby;
|
31
31
|
import org.jruby.RubyClass;
|
32
|
+
import org.jruby.RubyException;
|
32
33
|
import org.jruby.RubyModule;
|
33
34
|
import org.jruby.RubyObject;
|
34
|
-
import org.jruby.RubyException;
|
35
35
|
import org.jruby.anno.JRubyMethod;
|
36
36
|
import org.jruby.exceptions.RaiseException;
|
37
37
|
import org.jruby.runtime.ThreadContext;
|
38
38
|
import org.jruby.runtime.builtin.IRubyObject;
|
39
|
-
|
39
|
+
|
40
|
+
import static org.jruby.runtime.Visibility.PRIVATE;
|
40
41
|
|
41
42
|
public class PsychToRuby {
|
42
43
|
public static void initPsychToRuby(Ruby runtime, RubyModule psych) {
|
data/lib/psych/versions.rb
CHANGED
@@ -568,7 +568,7 @@ module Psych
|
|
568
568
|
raise BadAlias, "Tried to dump an aliased object"
|
569
569
|
end
|
570
570
|
|
571
|
-
unless @permitted_classes[target.class]
|
571
|
+
unless Symbol === target || @permitted_classes[target.class]
|
572
572
|
raise DisallowedClass.new('dump', target.class.name || target.class.inspect)
|
573
573
|
end
|
574
574
|
|
@@ -576,7 +576,7 @@ module Psych
|
|
576
576
|
end
|
577
577
|
|
578
578
|
def visit_Symbol sym
|
579
|
-
unless @permitted_symbols[sym]
|
579
|
+
unless @permitted_classes[Symbol] || @permitted_symbols[sym]
|
580
580
|
raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
|
581
581
|
end
|
582
582
|
|
data/lib/psych.jar
CHANGED
Binary file
|
data/lib/psych_jars.rb
CHANGED
data/psych.gemspec
CHANGED
@@ -55,7 +55,7 @@ DESCRIPTION
|
|
55
55
|
"lib/psych_jars.rb",
|
56
56
|
"lib/psych.jar"
|
57
57
|
]
|
58
|
-
s.requirements = "jar org.
|
58
|
+
s.requirements = "jar org.snakeyaml:snakeyaml-engine, #{version_module::Psych::DEFAULT_SNAKEYAML_VERSION}"
|
59
59
|
s.add_dependency 'jar-dependencies', '>= 0.1.7'
|
60
60
|
else
|
61
61
|
s.extensions = ["ext/psych/extconf.rb"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psych
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.1.0.pre1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-01-
|
13
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements:
|
128
|
-
- jar org.
|
128
|
+
- jar org.snakeyaml:snakeyaml-engine, 2.6
|
129
129
|
rubygems_version: 3.3.25
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|