graphql-c_parser 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5038dfe6e072d86fbd1e18e57bb7616374f4f37443ec4f0e7414a9cf514160d0
4
- data.tar.gz: 9c3d7d016eda6be1fba8ab054ebe6e1163271cbadb87b1f6c4e86a0560a97d00
3
+ metadata.gz: 4c3979cfbf6798e07cc891a6cf8533180789418b08bd78833ddd36c62be3c5df
4
+ data.tar.gz: fd9292270962ab840a442a3847fa125282ec697abbc7a60fa8a1c98e3668d70e
5
5
  SHA512:
6
- metadata.gz: cf3a0578d705b73ddb3a482c7fb92aecee25a11757d6d914b3d402c169dae8ebc251a1130a43e26451dc583d6d3537e1252c73c1523a24052847443542aa882e
7
- data.tar.gz: 573d534232d1acf2eb8c5f0011dbed98b56d263480969dac57a342d702a594d9a826cd37dcd6527e810678129ae9c7594783e1d5b8a378445b5f070fc95fb777
6
+ metadata.gz: fdf683b34458dde0e924c542b6e182a0157abf907fe2973fbb6d546888a4c01b5aa7c512f8ff8b45d5ee7136a8ebef2d00eeb1a50337071a5d0051fa688fbd03
7
+ data.tar.gz: 7da22594195af48a315eefca9705c68e58f6290bcdc773581815e606ae84d9521d703d2537fbeb88e66d11105f24ae03fa5bdaf3380d4089e66df349a52f4705
@@ -1,6 +1,6 @@
1
1
  #include "graphql_c_parser_ext.h"
2
2
 
3
- VALUE GraphQL_CParser_Lexer_tokenize(VALUE self, VALUE query_string) {
3
+ VALUE GraphQL_CParser_Lexer_tokenize_with_c(VALUE self, VALUE query_string) {
4
4
  return tokenize(query_string);
5
5
  }
6
6
 
@@ -13,7 +13,7 @@ void Init_graphql_c_parser_ext() {
13
13
  VALUE GraphQL = rb_define_module("GraphQL");
14
14
  VALUE CParser = rb_define_module_under(GraphQL, "CParser");
15
15
  VALUE Lexer = rb_define_module_under(CParser, "Lexer");
16
- rb_define_singleton_method(Lexer, "tokenize", GraphQL_CParser_Lexer_tokenize, 1);
16
+ rb_define_singleton_method(Lexer, "tokenize_with_c", GraphQL_CParser_Lexer_tokenize_with_c, 1);
17
17
  setup_static_token_variables();
18
18
 
19
19
  VALUE Parser = rb_define_class_under(CParser, "Parser", rb_cObject);
@@ -769,7 +769,8 @@ typedef enum TokenType {
769
769
  BLOCK_STRING,
770
770
  QUOTED_STRING,
771
771
  UNKNOWN_CHAR,
772
- COMMENT
772
+ COMMENT,
773
+ BAD_UNICODE_ESCAPE
773
774
  } TokenType;
774
775
 
775
776
  typedef struct Meta {
@@ -885,6 +886,10 @@ void emit(TokenType tt, char *ts, char *te, Meta *meta) {
885
886
  token_content = rb_funcall(mGraphQLLanguageBlockString, rb_intern("trim_whitespace"), 1, token_content);
886
887
  }
887
888
 
889
+ // The parser doesn't distinguish between these,
890
+ // Maybe updated below if it's invalid UTF-8
891
+ tt = STRING;
892
+
888
893
  if (
889
894
  RB_TEST(rb_funcall(token_content, rb_intern("valid_encoding?"), 0)) &&
890
895
  RB_TEST(rb_funcall(token_content, rb_intern("match?"), 1, valid_string_pattern))
@@ -892,14 +897,12 @@ void emit(TokenType tt, char *ts, char *te, Meta *meta) {
892
897
  rb_funcall(mGraphQLLanguageLexer, rb_intern("replace_escaped_characters_in_place"), 1, token_content);
893
898
  if (!RB_TEST(rb_funcall(token_content, rb_intern("valid_encoding?"), 0))) {
894
899
  token_sym = ID2SYM(rb_intern("BAD_UNICODE_ESCAPE"));
900
+ tt = BAD_UNICODE_ESCAPE;
895
901
  }
896
-
897
-
898
902
  } else {
899
903
  token_sym = ID2SYM(rb_intern("BAD_UNICODE_ESCAPE"));
904
+ tt = BAD_UNICODE_ESCAPE;
900
905
  }
901
- // The parser doesn't distinguish between these:
902
- tt = STRING;
903
906
  }
904
907
 
905
908
  VALUE token = rb_ary_new_from_args(6,
@@ -935,7 +938,7 @@ VALUE tokenize(VALUE query_rbstr) {
935
938
  Meta *meta = &meta_s;
936
939
 
937
940
 
938
- #line 939 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
941
+ #line 942 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
939
942
  {
940
943
  cs = (int)graphql_c_lexer_start;
941
944
  ts = 0;
@@ -943,10 +946,10 @@ VALUE tokenize(VALUE query_rbstr) {
943
946
  act = 0;
944
947
  }
945
948
 
946
- #line 351 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
949
+ #line 354 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
947
950
 
948
951
 
949
- #line 950 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
952
+ #line 953 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
950
953
  {
951
954
  unsigned int _trans = 0;
952
955
  const char * _keys;
@@ -961,7 +964,7 @@ VALUE tokenize(VALUE query_rbstr) {
961
964
  #line 1 "NONE"
962
965
  {ts = p;}}
963
966
 
964
- #line 965 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
967
+ #line 968 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
965
968
 
966
969
 
967
970
  break;
@@ -999,7 +1002,7 @@ VALUE tokenize(VALUE query_rbstr) {
999
1002
  #line 1 "NONE"
1000
1003
  {te = p+1;}}
1001
1004
 
1002
- #line 1003 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1005
+ #line 1006 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1003
1006
 
1004
1007
 
1005
1008
  break;
@@ -1012,7 +1015,7 @@ VALUE tokenize(VALUE query_rbstr) {
1012
1015
  emit(RCURLY, ts, te, meta); }
1013
1016
  }}
1014
1017
 
1015
- #line 1016 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1018
+ #line 1019 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1016
1019
 
1017
1020
 
1018
1021
  break;
@@ -1025,7 +1028,7 @@ VALUE tokenize(VALUE query_rbstr) {
1025
1028
  emit(LCURLY, ts, te, meta); }
1026
1029
  }}
1027
1030
 
1028
- #line 1029 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1031
+ #line 1032 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1029
1032
 
1030
1033
 
1031
1034
  break;
@@ -1038,7 +1041,7 @@ VALUE tokenize(VALUE query_rbstr) {
1038
1041
  emit(RPAREN, ts, te, meta); }
1039
1042
  }}
1040
1043
 
1041
- #line 1042 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1044
+ #line 1045 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1042
1045
 
1043
1046
 
1044
1047
  break;
@@ -1051,7 +1054,7 @@ VALUE tokenize(VALUE query_rbstr) {
1051
1054
  emit(LPAREN, ts, te, meta); }
1052
1055
  }}
1053
1056
 
1054
- #line 1055 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1057
+ #line 1058 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1055
1058
 
1056
1059
 
1057
1060
  break;
@@ -1064,7 +1067,7 @@ VALUE tokenize(VALUE query_rbstr) {
1064
1067
  emit(RBRACKET, ts, te, meta); }
1065
1068
  }}
1066
1069
 
1067
- #line 1068 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1070
+ #line 1071 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1068
1071
 
1069
1072
 
1070
1073
  break;
@@ -1077,7 +1080,7 @@ VALUE tokenize(VALUE query_rbstr) {
1077
1080
  emit(LBRACKET, ts, te, meta); }
1078
1081
  }}
1079
1082
 
1080
- #line 1081 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1083
+ #line 1084 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1081
1084
 
1082
1085
 
1083
1086
  break;
@@ -1090,7 +1093,7 @@ VALUE tokenize(VALUE query_rbstr) {
1090
1093
  emit(COLON, ts, te, meta); }
1091
1094
  }}
1092
1095
 
1093
- #line 1094 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1096
+ #line 1097 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1094
1097
 
1095
1098
 
1096
1099
  break;
@@ -1103,7 +1106,7 @@ VALUE tokenize(VALUE query_rbstr) {
1103
1106
  emit(BLOCK_STRING, ts, te, meta); }
1104
1107
  }}
1105
1108
 
1106
- #line 1107 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1109
+ #line 1110 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1107
1110
 
1108
1111
 
1109
1112
  break;
@@ -1116,7 +1119,7 @@ VALUE tokenize(VALUE query_rbstr) {
1116
1119
  emit(QUOTED_STRING, ts, te, meta); }
1117
1120
  }}
1118
1121
 
1119
- #line 1120 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1122
+ #line 1123 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1120
1123
 
1121
1124
 
1122
1125
  break;
@@ -1129,7 +1132,7 @@ VALUE tokenize(VALUE query_rbstr) {
1129
1132
  emit(VAR_SIGN, ts, te, meta); }
1130
1133
  }}
1131
1134
 
1132
- #line 1133 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1135
+ #line 1136 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1133
1136
 
1134
1137
 
1135
1138
  break;
@@ -1142,7 +1145,7 @@ VALUE tokenize(VALUE query_rbstr) {
1142
1145
  emit(DIR_SIGN, ts, te, meta); }
1143
1146
  }}
1144
1147
 
1145
- #line 1146 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1148
+ #line 1149 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1146
1149
 
1147
1150
 
1148
1151
  break;
@@ -1155,7 +1158,7 @@ VALUE tokenize(VALUE query_rbstr) {
1155
1158
  emit(ELLIPSIS, ts, te, meta); }
1156
1159
  }}
1157
1160
 
1158
- #line 1159 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1161
+ #line 1162 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1159
1162
 
1160
1163
 
1161
1164
  break;
@@ -1168,7 +1171,7 @@ VALUE tokenize(VALUE query_rbstr) {
1168
1171
  emit(EQUALS, ts, te, meta); }
1169
1172
  }}
1170
1173
 
1171
- #line 1172 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1174
+ #line 1175 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1172
1175
 
1173
1176
 
1174
1177
  break;
@@ -1181,7 +1184,7 @@ VALUE tokenize(VALUE query_rbstr) {
1181
1184
  emit(BANG, ts, te, meta); }
1182
1185
  }}
1183
1186
 
1184
- #line 1185 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1187
+ #line 1188 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1185
1188
 
1186
1189
 
1187
1190
  break;
@@ -1194,7 +1197,7 @@ VALUE tokenize(VALUE query_rbstr) {
1194
1197
  emit(PIPE, ts, te, meta); }
1195
1198
  }}
1196
1199
 
1197
- #line 1198 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1200
+ #line 1201 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1198
1201
 
1199
1202
 
1200
1203
  break;
@@ -1207,7 +1210,7 @@ VALUE tokenize(VALUE query_rbstr) {
1207
1210
  emit(AMP, ts, te, meta); }
1208
1211
  }}
1209
1212
 
1210
- #line 1211 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1213
+ #line 1214 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1211
1214
 
1212
1215
 
1213
1216
  break;
@@ -1223,7 +1226,7 @@ VALUE tokenize(VALUE query_rbstr) {
1223
1226
  }
1224
1227
  }}
1225
1228
 
1226
- #line 1227 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1229
+ #line 1230 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1227
1230
 
1228
1231
 
1229
1232
  break;
@@ -1236,7 +1239,7 @@ VALUE tokenize(VALUE query_rbstr) {
1236
1239
  emit(UNKNOWN_CHAR, ts, te, meta); }
1237
1240
  }}
1238
1241
 
1239
- #line 1240 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1242
+ #line 1243 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1240
1243
 
1241
1244
 
1242
1245
  break;
@@ -1249,7 +1252,7 @@ VALUE tokenize(VALUE query_rbstr) {
1249
1252
  emit(INT, ts, te, meta); }
1250
1253
  }}
1251
1254
 
1252
- #line 1253 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1255
+ #line 1256 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1253
1256
 
1254
1257
 
1255
1258
  break;
@@ -1262,7 +1265,7 @@ VALUE tokenize(VALUE query_rbstr) {
1262
1265
  emit(FLOAT, ts, te, meta); }
1263
1266
  }}
1264
1267
 
1265
- #line 1266 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1268
+ #line 1269 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1266
1269
 
1267
1270
 
1268
1271
  break;
@@ -1275,7 +1278,7 @@ VALUE tokenize(VALUE query_rbstr) {
1275
1278
  emit(BLOCK_STRING, ts, te, meta); }
1276
1279
  }}
1277
1280
 
1278
- #line 1279 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1281
+ #line 1282 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1279
1282
 
1280
1283
 
1281
1284
  break;
@@ -1288,7 +1291,7 @@ VALUE tokenize(VALUE query_rbstr) {
1288
1291
  emit(QUOTED_STRING, ts, te, meta); }
1289
1292
  }}
1290
1293
 
1291
- #line 1292 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1294
+ #line 1295 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1292
1295
 
1293
1296
 
1294
1297
  break;
@@ -1301,7 +1304,7 @@ VALUE tokenize(VALUE query_rbstr) {
1301
1304
  emit(IDENTIFIER, ts, te, meta); }
1302
1305
  }}
1303
1306
 
1304
- #line 1305 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1307
+ #line 1308 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1305
1308
 
1306
1309
 
1307
1310
  break;
@@ -1314,7 +1317,7 @@ VALUE tokenize(VALUE query_rbstr) {
1314
1317
  emit(COMMENT, ts, te, meta); }
1315
1318
  }}
1316
1319
 
1317
- #line 1318 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1320
+ #line 1321 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1318
1321
 
1319
1322
 
1320
1323
  break;
@@ -1327,7 +1330,7 @@ VALUE tokenize(VALUE query_rbstr) {
1327
1330
  meta->col += te - ts; }
1328
1331
  }}
1329
1332
 
1330
- #line 1331 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1333
+ #line 1334 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1331
1334
 
1332
1335
 
1333
1336
  break;
@@ -1340,7 +1343,7 @@ VALUE tokenize(VALUE query_rbstr) {
1340
1343
  emit(UNKNOWN_CHAR, ts, te, meta); }
1341
1344
  }}
1342
1345
 
1343
- #line 1344 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1346
+ #line 1347 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1344
1347
 
1345
1348
 
1346
1349
  break;
@@ -1354,7 +1357,7 @@ VALUE tokenize(VALUE query_rbstr) {
1354
1357
  emit(INT, ts, te, meta); }
1355
1358
  }}
1356
1359
 
1357
- #line 1358 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1360
+ #line 1361 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1358
1361
 
1359
1362
 
1360
1363
  break;
@@ -1368,7 +1371,7 @@ VALUE tokenize(VALUE query_rbstr) {
1368
1371
  emit(UNKNOWN_CHAR, ts, te, meta); }
1369
1372
  }}
1370
1373
 
1371
- #line 1372 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1374
+ #line 1375 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1372
1375
 
1373
1376
 
1374
1377
  break;
@@ -1548,7 +1551,7 @@ VALUE tokenize(VALUE query_rbstr) {
1548
1551
  }}
1549
1552
  }
1550
1553
 
1551
- #line 1552 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1554
+ #line 1555 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1552
1555
 
1553
1556
 
1554
1557
  break;
@@ -1558,13 +1561,13 @@ VALUE tokenize(VALUE query_rbstr) {
1558
1561
  #line 1 "NONE"
1559
1562
  {te = p+1;}}
1560
1563
 
1561
- #line 1562 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1564
+ #line 1565 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1562
1565
 
1563
1566
  {
1564
1567
  #line 54 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1565
1568
  {act = 1;}}
1566
1569
 
1567
- #line 1568 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1570
+ #line 1571 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1568
1571
 
1569
1572
 
1570
1573
  break;
@@ -1574,13 +1577,13 @@ VALUE tokenize(VALUE query_rbstr) {
1574
1577
  #line 1 "NONE"
1575
1578
  {te = p+1;}}
1576
1579
 
1577
- #line 1578 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1580
+ #line 1581 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1578
1581
 
1579
1582
  {
1580
1583
  #line 55 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1581
1584
  {act = 2;}}
1582
1585
 
1583
- #line 1584 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1586
+ #line 1587 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1584
1587
 
1585
1588
 
1586
1589
  break;
@@ -1590,13 +1593,13 @@ VALUE tokenize(VALUE query_rbstr) {
1590
1593
  #line 1 "NONE"
1591
1594
  {te = p+1;}}
1592
1595
 
1593
- #line 1594 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1596
+ #line 1597 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1594
1597
 
1595
1598
  {
1596
1599
  #line 56 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1597
1600
  {act = 3;}}
1598
1601
 
1599
- #line 1600 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1602
+ #line 1603 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1600
1603
 
1601
1604
 
1602
1605
  break;
@@ -1606,13 +1609,13 @@ VALUE tokenize(VALUE query_rbstr) {
1606
1609
  #line 1 "NONE"
1607
1610
  {te = p+1;}}
1608
1611
 
1609
- #line 1610 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1612
+ #line 1613 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1610
1613
 
1611
1614
  {
1612
1615
  #line 57 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1613
1616
  {act = 4;}}
1614
1617
 
1615
- #line 1616 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1618
+ #line 1619 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1616
1619
 
1617
1620
 
1618
1621
  break;
@@ -1622,13 +1625,13 @@ VALUE tokenize(VALUE query_rbstr) {
1622
1625
  #line 1 "NONE"
1623
1626
  {te = p+1;}}
1624
1627
 
1625
- #line 1626 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1628
+ #line 1629 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1626
1629
 
1627
1630
  {
1628
1631
  #line 58 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1629
1632
  {act = 5;}}
1630
1633
 
1631
- #line 1632 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1634
+ #line 1635 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1632
1635
 
1633
1636
 
1634
1637
  break;
@@ -1638,13 +1641,13 @@ VALUE tokenize(VALUE query_rbstr) {
1638
1641
  #line 1 "NONE"
1639
1642
  {te = p+1;}}
1640
1643
 
1641
- #line 1642 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1644
+ #line 1645 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1642
1645
 
1643
1646
  {
1644
1647
  #line 59 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1645
1648
  {act = 6;}}
1646
1649
 
1647
- #line 1648 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1650
+ #line 1651 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1648
1651
 
1649
1652
 
1650
1653
  break;
@@ -1654,13 +1657,13 @@ VALUE tokenize(VALUE query_rbstr) {
1654
1657
  #line 1 "NONE"
1655
1658
  {te = p+1;}}
1656
1659
 
1657
- #line 1658 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1660
+ #line 1661 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1658
1661
 
1659
1662
  {
1660
1663
  #line 60 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1661
1664
  {act = 7;}}
1662
1665
 
1663
- #line 1664 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1666
+ #line 1667 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1664
1667
 
1665
1668
 
1666
1669
  break;
@@ -1670,13 +1673,13 @@ VALUE tokenize(VALUE query_rbstr) {
1670
1673
  #line 1 "NONE"
1671
1674
  {te = p+1;}}
1672
1675
 
1673
- #line 1674 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1676
+ #line 1677 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1674
1677
 
1675
1678
  {
1676
1679
  #line 61 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1677
1680
  {act = 8;}}
1678
1681
 
1679
- #line 1680 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1682
+ #line 1683 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1680
1683
 
1681
1684
 
1682
1685
  break;
@@ -1686,13 +1689,13 @@ VALUE tokenize(VALUE query_rbstr) {
1686
1689
  #line 1 "NONE"
1687
1690
  {te = p+1;}}
1688
1691
 
1689
- #line 1690 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1692
+ #line 1693 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1690
1693
 
1691
1694
  {
1692
1695
  #line 62 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1693
1696
  {act = 9;}}
1694
1697
 
1695
- #line 1696 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1698
+ #line 1699 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1696
1699
 
1697
1700
 
1698
1701
  break;
@@ -1702,13 +1705,13 @@ VALUE tokenize(VALUE query_rbstr) {
1702
1705
  #line 1 "NONE"
1703
1706
  {te = p+1;}}
1704
1707
 
1705
- #line 1706 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1708
+ #line 1709 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1706
1709
 
1707
1710
  {
1708
1711
  #line 63 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1709
1712
  {act = 10;}}
1710
1713
 
1711
- #line 1712 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1714
+ #line 1715 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1712
1715
 
1713
1716
 
1714
1717
  break;
@@ -1718,13 +1721,13 @@ VALUE tokenize(VALUE query_rbstr) {
1718
1721
  #line 1 "NONE"
1719
1722
  {te = p+1;}}
1720
1723
 
1721
- #line 1722 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1724
+ #line 1725 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1722
1725
 
1723
1726
  {
1724
1727
  #line 64 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1725
1728
  {act = 11;}}
1726
1729
 
1727
- #line 1728 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1730
+ #line 1731 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1728
1731
 
1729
1732
 
1730
1733
  break;
@@ -1734,13 +1737,13 @@ VALUE tokenize(VALUE query_rbstr) {
1734
1737
  #line 1 "NONE"
1735
1738
  {te = p+1;}}
1736
1739
 
1737
- #line 1738 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1740
+ #line 1741 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1738
1741
 
1739
1742
  {
1740
1743
  #line 65 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1741
1744
  {act = 12;}}
1742
1745
 
1743
- #line 1744 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1746
+ #line 1747 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1744
1747
 
1745
1748
 
1746
1749
  break;
@@ -1750,13 +1753,13 @@ VALUE tokenize(VALUE query_rbstr) {
1750
1753
  #line 1 "NONE"
1751
1754
  {te = p+1;}}
1752
1755
 
1753
- #line 1754 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1756
+ #line 1757 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1754
1757
 
1755
1758
  {
1756
1759
  #line 66 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1757
1760
  {act = 13;}}
1758
1761
 
1759
- #line 1760 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1762
+ #line 1763 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1760
1763
 
1761
1764
 
1762
1765
  break;
@@ -1766,13 +1769,13 @@ VALUE tokenize(VALUE query_rbstr) {
1766
1769
  #line 1 "NONE"
1767
1770
  {te = p+1;}}
1768
1771
 
1769
- #line 1770 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1772
+ #line 1773 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1770
1773
 
1771
1774
  {
1772
1775
  #line 67 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1773
1776
  {act = 14;}}
1774
1777
 
1775
- #line 1776 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1778
+ #line 1779 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1776
1779
 
1777
1780
 
1778
1781
  break;
@@ -1782,13 +1785,13 @@ VALUE tokenize(VALUE query_rbstr) {
1782
1785
  #line 1 "NONE"
1783
1786
  {te = p+1;}}
1784
1787
 
1785
- #line 1786 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1788
+ #line 1789 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1786
1789
 
1787
1790
  {
1788
1791
  #line 68 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1789
1792
  {act = 15;}}
1790
1793
 
1791
- #line 1792 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1794
+ #line 1795 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1792
1795
 
1793
1796
 
1794
1797
  break;
@@ -1798,13 +1801,13 @@ VALUE tokenize(VALUE query_rbstr) {
1798
1801
  #line 1 "NONE"
1799
1802
  {te = p+1;}}
1800
1803
 
1801
- #line 1802 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1804
+ #line 1805 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1802
1805
 
1803
1806
  {
1804
1807
  #line 69 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1805
1808
  {act = 16;}}
1806
1809
 
1807
- #line 1808 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1810
+ #line 1811 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1808
1811
 
1809
1812
 
1810
1813
  break;
@@ -1814,13 +1817,13 @@ VALUE tokenize(VALUE query_rbstr) {
1814
1817
  #line 1 "NONE"
1815
1818
  {te = p+1;}}
1816
1819
 
1817
- #line 1818 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1820
+ #line 1821 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1818
1821
 
1819
1822
  {
1820
1823
  #line 70 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1821
1824
  {act = 17;}}
1822
1825
 
1823
- #line 1824 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1826
+ #line 1827 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1824
1827
 
1825
1828
 
1826
1829
  break;
@@ -1830,13 +1833,13 @@ VALUE tokenize(VALUE query_rbstr) {
1830
1833
  #line 1 "NONE"
1831
1834
  {te = p+1;}}
1832
1835
 
1833
- #line 1834 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1836
+ #line 1837 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1834
1837
 
1835
1838
  {
1836
1839
  #line 71 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1837
1840
  {act = 18;}}
1838
1841
 
1839
- #line 1840 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1842
+ #line 1843 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1840
1843
 
1841
1844
 
1842
1845
  break;
@@ -1846,13 +1849,13 @@ VALUE tokenize(VALUE query_rbstr) {
1846
1849
  #line 1 "NONE"
1847
1850
  {te = p+1;}}
1848
1851
 
1849
- #line 1850 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1852
+ #line 1853 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1850
1853
 
1851
1854
  {
1852
1855
  #line 72 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1853
1856
  {act = 19;}}
1854
1857
 
1855
- #line 1856 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1858
+ #line 1859 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1856
1859
 
1857
1860
 
1858
1861
  break;
@@ -1862,13 +1865,13 @@ VALUE tokenize(VALUE query_rbstr) {
1862
1865
  #line 1 "NONE"
1863
1866
  {te = p+1;}}
1864
1867
 
1865
- #line 1866 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1868
+ #line 1869 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1866
1869
 
1867
1870
  {
1868
1871
  #line 73 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1869
1872
  {act = 20;}}
1870
1873
 
1871
- #line 1872 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1874
+ #line 1875 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1872
1875
 
1873
1876
 
1874
1877
  break;
@@ -1878,13 +1881,13 @@ VALUE tokenize(VALUE query_rbstr) {
1878
1881
  #line 1 "NONE"
1879
1882
  {te = p+1;}}
1880
1883
 
1881
- #line 1882 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1884
+ #line 1885 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1882
1885
 
1883
1886
  {
1884
1887
  #line 74 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1885
1888
  {act = 21;}}
1886
1889
 
1887
- #line 1888 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1890
+ #line 1891 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1888
1891
 
1889
1892
 
1890
1893
  break;
@@ -1894,13 +1897,13 @@ VALUE tokenize(VALUE query_rbstr) {
1894
1897
  #line 1 "NONE"
1895
1898
  {te = p+1;}}
1896
1899
 
1897
- #line 1898 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1900
+ #line 1901 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1898
1901
 
1899
1902
  {
1900
1903
  #line 82 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1901
1904
  {act = 29;}}
1902
1905
 
1903
- #line 1904 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1906
+ #line 1907 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1904
1907
 
1905
1908
 
1906
1909
  break;
@@ -1910,13 +1913,13 @@ VALUE tokenize(VALUE query_rbstr) {
1910
1913
  #line 1 "NONE"
1911
1914
  {te = p+1;}}
1912
1915
 
1913
- #line 1914 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1916
+ #line 1917 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1914
1917
 
1915
1918
  {
1916
1919
  #line 83 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1917
1920
  {act = 30;}}
1918
1921
 
1919
- #line 1920 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1922
+ #line 1923 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1920
1923
 
1921
1924
 
1922
1925
  break;
@@ -1926,13 +1929,13 @@ VALUE tokenize(VALUE query_rbstr) {
1926
1929
  #line 1 "NONE"
1927
1930
  {te = p+1;}}
1928
1931
 
1929
- #line 1930 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1932
+ #line 1933 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1930
1933
 
1931
1934
  {
1932
1935
  #line 91 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1933
1936
  {act = 38;}}
1934
1937
 
1935
- #line 1936 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1938
+ #line 1939 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1936
1939
 
1937
1940
 
1938
1941
  break;
@@ -1952,7 +1955,7 @@ VALUE tokenize(VALUE query_rbstr) {
1952
1955
  #line 1 "NONE"
1953
1956
  {ts = 0;}}
1954
1957
 
1955
- #line 1956 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1958
+ #line 1959 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.c"
1956
1959
 
1957
1960
 
1958
1961
  break;
@@ -1965,7 +1968,7 @@ VALUE tokenize(VALUE query_rbstr) {
1965
1968
  _out: {}
1966
1969
  }
1967
1970
 
1968
- #line 352 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1971
+ #line 355 "graphql-c_parser/ext/graphql_c_parser_ext/lexer.rl"
1969
1972
 
1970
1973
 
1971
1974
  return tokens;
@@ -3233,7 +3233,8 @@ yyreturnlab:
3233
3233
 
3234
3234
  // Custom functions
3235
3235
  int yylex (YYSTYPE *lvalp, VALUE parser, VALUE filename) {
3236
- int next_token_idx = FIX2INT(rb_ivar_get(parser, rb_intern("@next_token_index")));
3236
+ VALUE next_token_idx_rb_int = rb_ivar_get(parser, rb_intern("@next_token_index"));
3237
+ int next_token_idx = FIX2INT(next_token_idx_rb_int);
3237
3238
  VALUE tokens = rb_ivar_get(parser, rb_intern("@tokens"));
3238
3239
  VALUE next_token = rb_ary_entry(tokens, next_token_idx);
3239
3240
 
@@ -3243,7 +3244,15 @@ int yylex (YYSTYPE *lvalp, VALUE parser, VALUE filename) {
3243
3244
  rb_ivar_set(parser, rb_intern("@next_token_index"), INT2FIX(next_token_idx + 1));
3244
3245
  VALUE token_type_rb_int = rb_ary_entry(next_token, 5);
3245
3246
  int next_token_type = FIX2INT(token_type_rb_int);
3246
-
3247
+ if (next_token_type == 241) { // BAD_UNICODE_ESCAPE
3248
+ VALUE mGraphQL = rb_const_get_at(rb_cObject, rb_intern("GraphQL"));
3249
+ VALUE mCParser = rb_const_get_at(mGraphQL, rb_intern("CParser"));
3250
+ VALUE bad_unicode_error = rb_funcall(
3251
+ mCParser, rb_intern("prepare_bad_unicode_error"), 1,
3252
+ parser
3253
+ );
3254
+ rb_exc_raise(bad_unicode_error);
3255
+ }
3247
3256
  *lvalp = next_token;
3248
3257
  return next_token_type;
3249
3258
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module CParser
5
- VERSION = "1.0.2"
5
+ VERSION = "1.0.3"
6
6
  end
7
7
  end
@@ -40,6 +40,40 @@ module GraphQL
40
40
  GraphQL::ParseError.new(message, line, col, parser.query_string, filename: parser.filename)
41
41
  end
42
42
 
43
+ def self.prepare_bad_unicode_error(parser)
44
+ token = parser.tokens[parser.next_token_index - 1]
45
+ line = token[1]
46
+ col = token[2]
47
+ GraphQL::ParseError.new(
48
+ "Parse error on bad Unicode escape sequence: #{token[3].inspect} (error) at [#{line}, #{col}]",
49
+ line,
50
+ col,
51
+ parser.query_string,
52
+ filename: parser.filename
53
+ )
54
+ end
55
+
56
+ module Lexer
57
+ def self.tokenize(graphql_string)
58
+ if !(graphql_string.encoding == Encoding::UTF_8 || graphql_string.ascii_only?)
59
+ graphql_string = graphql_string.dup.force_encoding(Encoding::UTF_8)
60
+ end
61
+ if !graphql_string.valid_encoding?
62
+ return [
63
+ [
64
+ :BAD_UNICODE_ESCAPE,
65
+ 1,
66
+ 1,
67
+ graphql_string,
68
+ nil, # prev token
69
+ 241 # BAD_UNICODE_ESCAPE in lexer.rl
70
+ ]
71
+ ]
72
+ end
73
+ tokenize_with_c(graphql_string)
74
+ end
75
+ end
76
+
43
77
  class Parser
44
78
  def initialize(query_string, filename, trace)
45
79
  if query_string.nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-c_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2023-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql