99
99
public class PsychParser extends RubyObject {
100
100
101
101
public static final String JRUBY_CALL_SITES = "_jruby_call_sites" ;
102
+ public static final String ENCODING_ANY = "ANY" ;
103
+ public static final String ENCODING_UTF8 = "UTF8" ;
104
+ public static final String ENCODING_UTF16LE = "UTF16LE" ;
105
+ public static final String ENCODING_UTF16BE = "UTF16BE" ;
106
+ public static final String MAX_ALIASES_FOR_COLLECTIONS = "max_aliases_for_collections" ;
107
+ public static final String ALLOW_DUPLICATE_KEYS = "allow_duplicate_keys" ;
108
+ public static final String ALLOW_RECURSIVE_KEYS = "allow_recursive_keys" ;
109
+ public static final String CODE_POINT_LIMIT = "code_point_limit" ;
102
110
103
111
public static void initPsychParser (Ruby runtime , RubyModule psych ) {
104
112
RubyClass psychParser = runtime .defineClassUnder ("Parser" , runtime .getObject (), PsychParser ::new , psych );
105
113
106
114
psychParser .setInternalVariable (JRUBY_CALL_SITES , new CallSites ());
107
115
108
116
runtime .getLoadService ().require ("psych/syntax_error" );
109
- psychParser .defineConstant ("ANY" , runtime .newFixnum (YAML_ANY_ENCODING .ordinal ()));
110
- psychParser .defineConstant ("UTF8" , runtime .newFixnum (YAML_UTF8_ENCODING .ordinal ()));
111
- psychParser .defineConstant ("UTF16LE" , runtime .newFixnum (YAML_UTF16LE_ENCODING .ordinal ()));
112
- psychParser .defineConstant ("UTF16BE" , runtime .newFixnum (YAML_UTF16BE_ENCODING .ordinal ()));
117
+ psychParser .defineConstant (ENCODING_ANY , runtime .newFixnum (YAML_ANY_ENCODING .ordinal ()));
118
+ psychParser .defineConstant (ENCODING_UTF8 , runtime .newFixnum (YAML_UTF8_ENCODING .ordinal ()));
119
+ psychParser .defineConstant (ENCODING_UTF16LE , runtime .newFixnum (YAML_UTF16LE_ENCODING .ordinal ()));
120
+ psychParser .defineConstant (ENCODING_UTF16BE , runtime .newFixnum (YAML_UTF16BE_ENCODING .ordinal ()));
113
121
114
122
psychParser .defineAnnotatedMethods (PsychParser .class );
115
123
116
124
// defaults for SnakeYAML load settings
117
125
LoadSettings defaults = LoadSettings .builder ().build ();
118
- psychParser .setInternalVariable ("max_aliases_for_collections" , runtime .newFixnum (defaults .getMaxAliasesForCollections ()));
119
- psychParser .setInternalVariable ("allow_duplicate_keys" , runtime .newBoolean (defaults .getAllowDuplicateKeys ()));
120
- psychParser .setInternalVariable ("allow_recursive_keys" , runtime .newBoolean (defaults .getAllowRecursiveKeys ()));
121
- psychParser .setInternalVariable ("code_point_limit" , runtime .newFixnum (defaults .getCodePointLimit ()));
126
+ psychParser .setInternalVariable (MAX_ALIASES_FOR_COLLECTIONS , runtime .newFixnum (defaults .getMaxAliasesForCollections ()));
127
+ psychParser .setInternalVariable (ALLOW_DUPLICATE_KEYS , runtime .newBoolean (defaults .getAllowDuplicateKeys ()));
128
+ psychParser .setInternalVariable (ALLOW_RECURSIVE_KEYS , runtime .newBoolean (defaults .getAllowRecursiveKeys ()));
129
+ psychParser .setInternalVariable (CODE_POINT_LIMIT , runtime .newFixnum (defaults .getCodePointLimit ()));
122
130
}
123
131
124
132
public PsychParser (Ruby runtime , RubyClass klass ) {
@@ -129,10 +137,10 @@ public PsychParser(Ruby runtime, RubyClass klass) {
129
137
// prepare settings builder and apply global defaults
130
138
LoadSettingsBuilder lsb = LoadSettings .builder ();
131
139
lsb .setSchema (new CoreSchema ());
132
- lsb .setMaxAliasesForCollections (((IRubyObject ) klass .getInternalVariable ("max_aliases_for_collections" )).convertToInteger ().getIntValue ());
133
- lsb .setAllowDuplicateKeys (((IRubyObject ) klass .getInternalVariable ("allow_duplicate_keys" )).isTrue ());
134
- lsb .setAllowRecursiveKeys (((IRubyObject ) klass .getInternalVariable ("allow_recursive_keys" )).isTrue ());
135
- lsb .setCodePointLimit (((IRubyObject ) klass .getInternalVariable ("code_point_limit" )).convertToInteger ().getIntValue ());
140
+ lsb .setMaxAliasesForCollections (((IRubyObject ) klass .getInternalVariable (MAX_ALIASES_FOR_COLLECTIONS )).convertToInteger ().getIntValue ());
141
+ lsb .setAllowDuplicateKeys (((IRubyObject ) klass .getInternalVariable (ALLOW_DUPLICATE_KEYS )).isTrue ());
142
+ lsb .setAllowRecursiveKeys (((IRubyObject ) klass .getInternalVariable (ALLOW_RECURSIVE_KEYS )).isTrue ());
143
+ lsb .setCodePointLimit (((IRubyObject ) klass .getInternalVariable (CODE_POINT_LIMIT )).convertToInteger ().getIntValue ());
136
144
this .loadSettingsBuilder = lsb ;
137
145
}
138
146
@@ -530,7 +538,7 @@ public IRubyObject max_aliases_for_collections_set(IRubyObject max) {
530
538
return max ;
531
539
}
532
540
533
- @ JRubyMethod (name = "max_aliases_for_collections" )
541
+ @ JRubyMethod (name = MAX_ALIASES_FOR_COLLECTIONS )
534
542
public IRubyObject max_aliases_for_collections (ThreadContext context ) {
535
543
return context .runtime .newFixnum (buildSettings ().getMaxAliasesForCollections ());
536
544
}
@@ -542,7 +550,7 @@ public IRubyObject allow_duplicate_keys_set(IRubyObject allow) {
542
550
return allow ;
543
551
}
544
552
545
- @ JRubyMethod (name = "allow_duplicate_keys" )
553
+ @ JRubyMethod (name = ALLOW_DUPLICATE_KEYS )
546
554
public IRubyObject allow_duplicate_keys (ThreadContext context ) {
547
555
return RubyBoolean .newBoolean (context , buildSettings ().getAllowDuplicateKeys ());
548
556
}
@@ -554,7 +562,7 @@ public IRubyObject allow_recursive_keys_set(IRubyObject allow) {
554
562
return allow ;
555
563
}
556
564
557
- @ JRubyMethod (name = "allow_recursive_keys" )
565
+ @ JRubyMethod (name = ALLOW_RECURSIVE_KEYS )
558
566
public IRubyObject allow_recursive_keys (ThreadContext context ) {
559
567
return RubyBoolean .newBoolean (context , buildSettings ().getAllowRecursiveKeys ());
560
568
}
@@ -566,7 +574,7 @@ public IRubyObject code_point_limit_set(IRubyObject limit) {
566
574
return limit ;
567
575
}
568
576
569
- @ JRubyMethod (name = "code_point_limit" )
577
+ @ JRubyMethod (name = CODE_POINT_LIMIT )
570
578
public IRubyObject code_point_limit (ThreadContext context ) {
571
579
return context .runtime .newFixnum (buildSettings ().getCodePointLimit ());
572
580
}
@@ -581,38 +589,38 @@ public static IRubyObject max_aliases_for_collections_set(ThreadContext context,
581
589
throw context .runtime .newRangeError ("max_aliases_for_collections must be positive" );
582
590
}
583
591
584
- self .getInternalVariables ().setInternalVariable ("max_aliases_for_collections" , max );
592
+ self .getInternalVariables ().setInternalVariable (MAX_ALIASES_FOR_COLLECTIONS , max );
585
593
586
594
return max ;
587
595
}
588
596
589
- @ JRubyMethod (name = "max_aliases_for_collections" )
597
+ @ JRubyMethod (name = MAX_ALIASES_FOR_COLLECTIONS )
590
598
public static IRubyObject max_aliases_for_collections (ThreadContext context , IRubyObject self ) {
591
- return (IRubyObject ) self .getInternalVariables ().getInternalVariable ("max_aliases_for_collections" );
599
+ return (IRubyObject ) self .getInternalVariables ().getInternalVariable (MAX_ALIASES_FOR_COLLECTIONS );
592
600
}
593
601
594
602
@ JRubyMethod (name = "allow_duplicate_keys=" , meta = true )
595
603
public static IRubyObject allow_duplicate_keys_set (IRubyObject self , IRubyObject allow ) {
596
- self .getInternalVariables ().setInternalVariable ("allow_duplicate_keys" , allow );
604
+ self .getInternalVariables ().setInternalVariable (ALLOW_DUPLICATE_KEYS , allow );
597
605
598
606
return allow ;
599
607
}
600
608
601
- @ JRubyMethod (name = "allow_duplicate_keys" , meta = true )
609
+ @ JRubyMethod (name = ALLOW_DUPLICATE_KEYS , meta = true )
602
610
public static IRubyObject allow_duplicate_keys (ThreadContext context , IRubyObject self ) {
603
- return (IRubyObject ) self .getInternalVariables ().getInternalVariable ("allow_duplicate_keys" );
611
+ return (IRubyObject ) self .getInternalVariables ().getInternalVariable (ALLOW_DUPLICATE_KEYS );
604
612
}
605
613
606
614
@ JRubyMethod (name = "allow_recursive_keys=" , meta = true )
607
615
public static IRubyObject allow_recursive_keys_set (IRubyObject self , IRubyObject allow ) {
608
- self .getInternalVariables ().setInternalVariable ("allow_recursive_keys" , allow );
616
+ self .getInternalVariables ().setInternalVariable (ALLOW_RECURSIVE_KEYS , allow );
609
617
610
618
return allow ;
611
619
}
612
620
613
- @ JRubyMethod (name = "allow_recursive_keys" , meta = true )
621
+ @ JRubyMethod (name = ALLOW_RECURSIVE_KEYS , meta = true )
614
622
public static IRubyObject allow_recursive_keys (ThreadContext context , IRubyObject self ) {
615
- return (IRubyObject ) self .getInternalVariables ().getInternalVariable ("allow_recursive_keys" );
623
+ return (IRubyObject ) self .getInternalVariables ().getInternalVariable (ALLOW_RECURSIVE_KEYS );
616
624
}
617
625
618
626
@ JRubyMethod (name = "code_point_limit=" , meta = true )
@@ -623,14 +631,14 @@ public static IRubyObject code_point_limit_set(ThreadContext context, IRubyObjec
623
631
throw context .runtime .newRangeError ("code_point_limit must be positive" );
624
632
}
625
633
626
- self .getInternalVariables ().setInternalVariable ("code_point_limit" , limit );
634
+ self .getInternalVariables ().setInternalVariable (CODE_POINT_LIMIT , limit );
627
635
628
636
return limit ;
629
637
}
630
638
631
- @ JRubyMethod (name = "code_point_limit" , meta = true )
639
+ @ JRubyMethod (name = CODE_POINT_LIMIT , meta = true )
632
640
public static IRubyObject code_point_limit (ThreadContext context , IRubyObject self ) {
633
- return (IRubyObject ) self .getInternalVariables ().getInternalVariable ("code_point_limit" );
641
+ return (IRubyObject ) self .getInternalVariables ().getInternalVariable (CODE_POINT_LIMIT );
634
642
}
635
643
636
644
private LoadSettings buildSettings () {
0 commit comments