@@ -52,7 +52,7 @@ check_string(VALUE value) {
52
52
53
53
// Check if the value is a string. If it's not, then raise a type error.
54
54
if (!RB_TYPE_P (value , T_STRING )) {
55
- rb_raise (rb_eTypeError , "wrong argument type %" PRIsVALUE " (expected String)" , rb_obj_class (value ));
55
+ rb_raise (rb_eTypeError , "wrong argument type %" PRIsVALUE " (expected String)" , rb_obj_class (value ));
56
56
}
57
57
58
58
// Otherwise, return the value as a C string.
@@ -66,7 +66,7 @@ static void
66
66
input_load_string (pm_string_t * input , VALUE string ) {
67
67
// Check if the string is a string. If it's not, then raise a type error.
68
68
if (!RB_TYPE_P (string , T_STRING )) {
69
- rb_raise (rb_eTypeError , "wrong argument type %" PRIsVALUE " (expected String)" , rb_obj_class (string ));
69
+ rb_raise (rb_eTypeError , "wrong argument type %" PRIsVALUE " (expected String)" , rb_obj_class (string ));
70
70
}
71
71
72
72
pm_string_constant_init (input , RSTRING_PTR (string ), RSTRING_LEN (string ));
@@ -1089,118 +1089,6 @@ parse_file_failure_p(int argc, VALUE *argv, VALUE self) {
1089
1089
return RTEST (parse_file_success_p (argc , argv , self )) ? Qfalse : Qtrue ;
1090
1090
}
1091
1091
1092
- /******************************************************************************/
1093
- /* Utility functions exposed to make testing easier */
1094
- /******************************************************************************/
1095
-
1096
- #ifndef PRISM_EXCLUDE_PRETTYPRINT
1097
-
1098
- /**
1099
- * call-seq:
1100
- * Debug::inspect_node(source) -> inspected
1101
- *
1102
- * Inspect the AST that represents the given source using the prism pretty print
1103
- * as opposed to the Ruby implementation.
1104
- */
1105
- static VALUE
1106
- inspect_node (VALUE self , VALUE source ) {
1107
- pm_string_t input ;
1108
- input_load_string (& input , source );
1109
-
1110
- pm_parser_t parser ;
1111
- pm_parser_init (& parser , pm_string_source (& input ), pm_string_length (& input ), NULL );
1112
-
1113
- pm_node_t * node = pm_parse (& parser );
1114
- pm_buffer_t buffer = { 0 };
1115
-
1116
- pm_prettyprint (& buffer , & parser , node );
1117
-
1118
- rb_encoding * encoding = rb_enc_find (parser .encoding -> name );
1119
- VALUE string = rb_enc_str_new (pm_buffer_value (& buffer ), pm_buffer_length (& buffer ), encoding );
1120
-
1121
- pm_buffer_free (& buffer );
1122
- pm_node_destroy (& parser , node );
1123
- pm_parser_free (& parser );
1124
-
1125
- return string ;
1126
- }
1127
-
1128
- #endif
1129
-
1130
- /**
1131
- * call-seq: Debug::Encoding.all -> Array[Debug::Encoding]
1132
- *
1133
- * Return an array of all of the encodings that prism knows about.
1134
- */
1135
- static VALUE
1136
- encoding_all (VALUE self ) {
1137
- VALUE encodings = rb_ary_new ();
1138
-
1139
- for (size_t index = 0 ; index < PM_ENCODING_MAXIMUM ; index ++ ) {
1140
- const pm_encoding_t * encoding = & pm_encodings [index ];
1141
-
1142
- VALUE encoding_argv [] = { rb_str_new_cstr (encoding -> name ), encoding -> multibyte ? Qtrue : Qfalse };
1143
- rb_ary_push (encodings , rb_class_new_instance (2 , encoding_argv , rb_cPrismDebugEncoding ));
1144
- }
1145
-
1146
- return encodings ;
1147
- }
1148
-
1149
- static const pm_encoding_t *
1150
- encoding_find (VALUE name ) {
1151
- const uint8_t * source = (const uint8_t * ) RSTRING_PTR (name );
1152
- size_t length = RSTRING_LEN (name );
1153
-
1154
- const pm_encoding_t * encoding = pm_encoding_find (source , source + length );
1155
- if (encoding == NULL ) { rb_raise (rb_eArgError , "Unknown encoding: %s" , source ); }
1156
-
1157
- return encoding ;
1158
- }
1159
-
1160
- /**
1161
- * call-seq: Debug::Encoding.width(source) -> Integer
1162
- *
1163
- * Returns the width of the first character in the given string if it is valid
1164
- * in the encoding. If it is not, this function returns 0.
1165
- */
1166
- static VALUE
1167
- encoding_char_width (VALUE self , VALUE name , VALUE value ) {
1168
- return ULONG2NUM (encoding_find (name )-> char_width ((const uint8_t * ) RSTRING_PTR (value ), RSTRING_LEN (value )));
1169
- }
1170
-
1171
- /**
1172
- * call-seq: Debug::Encoding.alnum?(source) -> true | false
1173
- *
1174
- * Returns true if the first character in the given string is an alphanumeric
1175
- * character in the encoding.
1176
- */
1177
- static VALUE
1178
- encoding_alnum_char (VALUE self , VALUE name , VALUE value ) {
1179
- return encoding_find (name )-> alnum_char ((const uint8_t * ) RSTRING_PTR (value ), RSTRING_LEN (value )) > 0 ? Qtrue : Qfalse ;
1180
- }
1181
-
1182
- /**
1183
- * call-seq: Debug::Encoding.alpha?(source) -> true | false
1184
- *
1185
- * Returns true if the first character in the given string is an alphabetic
1186
- * character in the encoding.
1187
- */
1188
- static VALUE
1189
- encoding_alpha_char (VALUE self , VALUE name , VALUE value ) {
1190
- return encoding_find (name )-> alpha_char ((const uint8_t * ) RSTRING_PTR (value ), RSTRING_LEN (value )) > 0 ? Qtrue : Qfalse ;
1191
- }
1192
-
1193
- /**
1194
- * call-seq: Debug::Encoding.upper?(source) -> true | false
1195
- *
1196
- * Returns true if the first character in the given string is an uppercase
1197
- * character in the encoding.
1198
- */
1199
- static VALUE
1200
- encoding_isupper_char (VALUE self , VALUE name , VALUE value ) {
1201
- return encoding_find (name )-> isupper_char ((const uint8_t * ) RSTRING_PTR (value ), RSTRING_LEN (value )) ? Qtrue : Qfalse ;
1202
- }
1203
-
1204
1092
/******************************************************************************/
1205
1093
/* Initialization of the extension */
1206
1094
/******************************************************************************/
@@ -1276,23 +1164,6 @@ Init_prism(void) {
1276
1164
rb_define_singleton_method (rb_cPrism , "dump_file" , dump_file , -1 );
1277
1165
#endif
1278
1166
1279
- // Next, the functions that will be called by the parser to perform various
1280
- // internal tasks. We expose these to make them easier to test.
1281
- VALUE rb_cPrismDebug = rb_define_module_under (rb_cPrism , "Debug" );
1282
-
1283
- #ifndef PRISM_EXCLUDE_PRETTYPRINT
1284
- rb_define_singleton_method (rb_cPrismDebug , "inspect_node" , inspect_node , 1 );
1285
- #endif
1286
-
1287
- // Next, define the functions that are exposed through the private
1288
- // Debug::Encoding class.
1289
- rb_cPrismDebugEncoding = rb_define_class_under (rb_cPrismDebug , "Encoding" , rb_cObject );
1290
- rb_define_singleton_method (rb_cPrismDebugEncoding , "all" , encoding_all , 0 );
1291
- rb_define_singleton_method (rb_cPrismDebugEncoding , "_width" , encoding_char_width , 2 );
1292
- rb_define_singleton_method (rb_cPrismDebugEncoding , "_alnum?" , encoding_alnum_char , 2 );
1293
- rb_define_singleton_method (rb_cPrismDebugEncoding , "_alpha?" , encoding_alpha_char , 2 );
1294
- rb_define_singleton_method (rb_cPrismDebugEncoding , "_upper?" , encoding_isupper_char , 2 );
1295
-
1296
1167
// Next, initialize the other APIs.
1297
1168
Init_prism_api_node ();
1298
1169
Init_prism_pack ();
0 commit comments