lrama 0.5.1 → 0.5.3
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/.github/workflows/test.yaml +2 -3
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/LEGAL.md +1 -16
- data/README.md +1 -1
- data/Steepfile +3 -0
- data/doc/TODO.md +4 -3
- data/exe/lrama +1 -1
- data/lib/lrama/command.rb +90 -71
- data/lib/lrama/context.rb +11 -1
- data/lib/lrama/grammar/code.rb +123 -0
- data/lib/lrama/grammar/error_token.rb +9 -0
- data/lib/lrama/grammar/precedence.rb +11 -0
- data/lib/lrama/grammar/printer.rb +9 -0
- data/lib/lrama/grammar/reference.rb +22 -0
- data/lib/lrama/grammar/rule.rb +33 -0
- data/lib/lrama/grammar/symbol.rb +94 -0
- data/lib/lrama/grammar/union.rb +10 -0
- data/lib/lrama/grammar.rb +67 -285
- data/lib/lrama/lexer/token.rb +76 -0
- data/lib/lrama/lexer.rb +12 -48
- data/lib/lrama/output.rb +31 -3
- data/lib/lrama/parser/token_scanner.rb +4 -0
- data/lib/lrama/parser.rb +19 -5
- data/lib/lrama/report/duration.rb +25 -0
- data/lib/lrama/report/profile.rb +25 -0
- data/lib/lrama/report.rb +2 -47
- data/lib/lrama/state/resolved_conflict.rb +29 -0
- data/lib/lrama/state.rb +3 -28
- data/lib/lrama/states/item.rb +43 -0
- data/lib/lrama/states.rb +3 -41
- data/lib/lrama/version.rb +1 -1
- data/lrama.gemspec +2 -2
- data/rbs_collection.lock.yaml +26 -0
- data/rbs_collection.yaml +22 -0
- data/sig/lrama/report/duration.rbs +11 -0
- data/sig/lrama/report/profile.rbs +7 -0
- data/sig/lrama/warning.rbs +16 -0
- data/template/bison/yacc.c +397 -32
- metadata +23 -5
data/template/bison/yacc.c
CHANGED
@@ -114,7 +114,7 @@
|
|
114
114
|
#ifndef YYDEBUG
|
115
115
|
# define YYDEBUG 0
|
116
116
|
#endif
|
117
|
-
#if YYDEBUG
|
117
|
+
#if YYDEBUG && !defined(yydebug)
|
118
118
|
extern int yydebug;
|
119
119
|
#endif
|
120
120
|
<%-# b4_percent_code_get([[requires]]). %code is not supported -%>
|
@@ -542,6 +542,13 @@ static const <%= output.int_type_for(output.context.yytranslate) %> yytranslate[
|
|
542
542
|
<%= output.yytranslate %>
|
543
543
|
};
|
544
544
|
|
545
|
+
<%- if output.error_recovery -%>
|
546
|
+
/* YYTRANSLATE_INVERTED[SYMBOL-NUM] -- Token number corresponding to SYMBOL-NUM */
|
547
|
+
static const <%= output.int_type_for(output.context.yytranslate_inverted) %> yytranslate_inverted[] =
|
548
|
+
{
|
549
|
+
<%= output.yytranslate_inverted %>
|
550
|
+
};
|
551
|
+
<%- end -%>
|
545
552
|
#if YYDEBUG
|
546
553
|
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
|
547
554
|
static const <%= output.int_type_for(output.context.yyrline) %> yyrline[] =
|
@@ -731,7 +738,7 @@ do { \
|
|
731
738
|
|
732
739
|
/* Temporary convenience wrapper in case some people defined the
|
733
740
|
undocumented and private YY_LOCATION_PRINT macros. */
|
734
|
-
# define YYLOCATION_PRINT(File, Loc) YY_LOCATION_PRINT(File, *(Loc))
|
741
|
+
# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) YY_LOCATION_PRINT(File, *(Loc)<%= output.user_args %>)
|
735
742
|
|
736
743
|
# elif defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
|
737
744
|
|
@@ -767,11 +774,11 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
|
|
767
774
|
|
768
775
|
/* Temporary convenience wrapper in case some people defined the
|
769
776
|
undocumented and private YY_LOCATION_PRINT macros. */
|
770
|
-
# define YY_LOCATION_PRINT(File, Loc) YYLOCATION_PRINT(File, &(Loc))
|
777
|
+
# define YY_LOCATION_PRINT(File, Loc<%= output.user_args %>) YYLOCATION_PRINT(File, &(Loc)<%= output.user_args %>)
|
771
778
|
|
772
779
|
# else
|
773
780
|
|
774
|
-
# define YYLOCATION_PRINT(File, Loc) ((void) 0)
|
781
|
+
# define YYLOCATION_PRINT(File, Loc<%= output.user_args %>) ((void) 0)
|
775
782
|
/* Temporary convenience wrapper in case some people defined the
|
776
783
|
undocumented and private YY_LOCATION_PRINT macros. */
|
777
784
|
# define YY_LOCATION_PRINT YYLOCATION_PRINT
|
@@ -780,13 +787,13 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
|
|
780
787
|
# endif /* !defined YYLOCATION_PRINT */
|
781
788
|
|
782
789
|
|
783
|
-
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
|
790
|
+
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>) \
|
784
791
|
do { \
|
785
792
|
if (yydebug) \
|
786
793
|
{ \
|
787
794
|
YYFPRINTF (stderr, "%s ", Title); \
|
788
795
|
yy_symbol_print (stderr, \
|
789
|
-
Kind, Value, Location
|
796
|
+
Kind, Value, Location<%= output.user_args %>); \
|
790
797
|
YYFPRINTF (stderr, "\n"); \
|
791
798
|
} \
|
792
799
|
} while (0)
|
@@ -828,9 +835,9 @@ yy_symbol_print (FILE *yyo,
|
|
828
835
|
YYFPRINTF (yyo, "%s %s (",
|
829
836
|
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
|
830
837
|
|
831
|
-
YYLOCATION_PRINT (yyo, yylocationp);
|
838
|
+
YYLOCATION_PRINT (yyo, yylocationp<%= output.user_args %>);
|
832
839
|
YYFPRINTF (yyo, ": ");
|
833
|
-
yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp
|
840
|
+
yy_symbol_value_print (yyo, yykind, yyvaluep, yylocationp<%= output.user_args %>);
|
834
841
|
YYFPRINTF (yyo, ")");
|
835
842
|
}
|
836
843
|
|
@@ -840,7 +847,7 @@ yy_symbol_print (FILE *yyo,
|
|
840
847
|
`------------------------------------------------------------------*/
|
841
848
|
|
842
849
|
static void
|
843
|
-
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
|
850
|
+
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop<%= output.user_formals %>)
|
844
851
|
{
|
845
852
|
YYFPRINTF (stderr, "Stack now");
|
846
853
|
for (; yybottom <= yytop; yybottom++)
|
@@ -851,10 +858,10 @@ yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
|
|
851
858
|
YYFPRINTF (stderr, "\n");
|
852
859
|
}
|
853
860
|
|
854
|
-
# define YY_STACK_PRINT(Bottom, Top)
|
861
|
+
# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>) \
|
855
862
|
do { \
|
856
863
|
if (yydebug) \
|
857
|
-
yy_stack_print ((Bottom), (Top));
|
864
|
+
yy_stack_print ((Bottom), (Top)<%= output.user_args %>); \
|
858
865
|
} while (0)
|
859
866
|
|
860
867
|
|
@@ -878,25 +885,27 @@ yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp,
|
|
878
885
|
yy_symbol_print (stderr,
|
879
886
|
YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
|
880
887
|
&yyvsp[(yyi + 1) - (yynrhs)],
|
881
|
-
&(yylsp[(yyi + 1) - (yynrhs)])
|
888
|
+
&(yylsp[(yyi + 1) - (yynrhs)])<%= output.user_args %>);
|
882
889
|
YYFPRINTF (stderr, "\n");
|
883
890
|
}
|
884
891
|
}
|
885
892
|
|
886
|
-
# define YY_REDUCE_PRINT(Rule)
|
893
|
+
# define YY_REDUCE_PRINT(Rule<%= output.user_args %>) \
|
887
894
|
do { \
|
888
895
|
if (yydebug) \
|
889
|
-
yy_reduce_print (yyssp, yyvsp, yylsp, Rule
|
896
|
+
yy_reduce_print (yyssp, yyvsp, yylsp, Rule<%= output.user_args %>); \
|
890
897
|
} while (0)
|
891
898
|
|
892
899
|
/* Nonzero means print parse trace. It is left uninitialized so that
|
893
900
|
multiple parsers can coexist. */
|
901
|
+
#ifndef yydebug
|
894
902
|
int yydebug;
|
903
|
+
#endif
|
895
904
|
#else /* !YYDEBUG */
|
896
905
|
# define YYDPRINTF(Args) ((void) 0)
|
897
|
-
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
|
898
|
-
# define YY_STACK_PRINT(Bottom, Top)
|
899
|
-
# define YY_REDUCE_PRINT(Rule)
|
906
|
+
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location<%= output.user_args %>)
|
907
|
+
# define YY_STACK_PRINT(Bottom, Top<%= output.user_args %>)
|
908
|
+
# define YY_REDUCE_PRINT(Rule<%= output.user_args %>)
|
900
909
|
#endif /* !YYDEBUG */
|
901
910
|
|
902
911
|
|
@@ -1110,7 +1119,7 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx,
|
|
1110
1119
|
required number of bytes is too large to store. */
|
1111
1120
|
static int
|
1112
1121
|
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
|
1113
|
-
const yypcontext_t *yyctx)
|
1122
|
+
const yypcontext_t *yyctx<%= output.user_formals %>)
|
1114
1123
|
{
|
1115
1124
|
enum { YYARGS_MAX = 5 };
|
1116
1125
|
/* Internationalized format string. */
|
@@ -1200,7 +1209,7 @@ yydestruct (const char *yymsg,
|
|
1200
1209
|
<%= output.parse_param_use("yyvaluep", "yylocationp") %>
|
1201
1210
|
if (!yymsg)
|
1202
1211
|
yymsg = "Deleting";
|
1203
|
-
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
|
1212
|
+
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp<%= output.user_args %>);
|
1204
1213
|
|
1205
1214
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
1206
1215
|
YY_USE (yykind);
|
@@ -1209,6 +1218,303 @@ yydestruct (const char *yymsg,
|
|
1209
1218
|
|
1210
1219
|
|
1211
1220
|
|
1221
|
+
<%- if output.error_recovery -%>
|
1222
|
+
#ifndef YYMAXREPAIR
|
1223
|
+
# define YYMAXREPAIR 3
|
1224
|
+
#endif
|
1225
|
+
|
1226
|
+
enum repair_type {
|
1227
|
+
insert,
|
1228
|
+
delete,
|
1229
|
+
shift,
|
1230
|
+
};
|
1231
|
+
|
1232
|
+
struct repair {
|
1233
|
+
enum repair_type type;
|
1234
|
+
yysymbol_kind_t term;
|
1235
|
+
};
|
1236
|
+
typedef struct repair repair;
|
1237
|
+
|
1238
|
+
struct repairs {
|
1239
|
+
/* For debug */
|
1240
|
+
int id;
|
1241
|
+
/* For breadth-first traversing */
|
1242
|
+
struct repairs *next;
|
1243
|
+
YYPTRDIFF_T stack_length;
|
1244
|
+
/* Bottom of states */
|
1245
|
+
yy_state_t *states;
|
1246
|
+
/* Top of states */
|
1247
|
+
yy_state_t *state;
|
1248
|
+
/* repair length */
|
1249
|
+
int repair_length;
|
1250
|
+
/* */
|
1251
|
+
struct repairs *prev_repair;
|
1252
|
+
struct repair repair;
|
1253
|
+
};
|
1254
|
+
typedef struct repairs repairs;
|
1255
|
+
|
1256
|
+
struct yy_term {
|
1257
|
+
yysymbol_kind_t kind;
|
1258
|
+
YYSTYPE value;
|
1259
|
+
YYLTYPE location;
|
1260
|
+
};
|
1261
|
+
typedef struct yy_term yy_term;
|
1262
|
+
|
1263
|
+
struct repair_terms {
|
1264
|
+
int id;
|
1265
|
+
int length;
|
1266
|
+
yy_term terms[];
|
1267
|
+
};
|
1268
|
+
typedef struct repair_terms repair_terms;
|
1269
|
+
|
1270
|
+
static void
|
1271
|
+
yy_error_token_initialize (yysymbol_kind_t yykind, YYSTYPE * const yyvaluep, YYLTYPE * const yylocationp<%= output.user_formals %>)
|
1272
|
+
{
|
1273
|
+
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
1274
|
+
switch (yykind)
|
1275
|
+
{
|
1276
|
+
<%= output.symbol_actions_for_error_token -%>
|
1277
|
+
default:
|
1278
|
+
break;
|
1279
|
+
}
|
1280
|
+
YY_IGNORE_MAYBE_UNINITIALIZED_END
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
static repair_terms *
|
1284
|
+
yy_create_repair_terms(repairs *reps)
|
1285
|
+
{
|
1286
|
+
repairs *r = reps;
|
1287
|
+
repair_terms *rep_terms;
|
1288
|
+
int count = 0;
|
1289
|
+
|
1290
|
+
while (r->prev_repair)
|
1291
|
+
{
|
1292
|
+
count++;
|
1293
|
+
r = r->prev_repair;
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
rep_terms = (repair_terms *) malloc (sizeof (repair_terms) + sizeof (yy_term) * count);
|
1297
|
+
rep_terms->id = reps->id;
|
1298
|
+
rep_terms->length = count;
|
1299
|
+
|
1300
|
+
r = reps;
|
1301
|
+
while (r->prev_repair)
|
1302
|
+
{
|
1303
|
+
rep_terms->terms[count-1].kind = r->repair.term;
|
1304
|
+
count--;
|
1305
|
+
r = r->prev_repair;
|
1306
|
+
}
|
1307
|
+
|
1308
|
+
return rep_terms;
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
static void
|
1312
|
+
yy_print_repairs(repairs *reps)
|
1313
|
+
{
|
1314
|
+
repairs *r = reps;
|
1315
|
+
|
1316
|
+
fprintf (stderr,
|
1317
|
+
"id: %d, repair_length: %d, repair_state: %d, prev_repair_id: %d\n",
|
1318
|
+
reps->id, reps->repair_length, *reps->state, reps->prev_repair->id);
|
1319
|
+
|
1320
|
+
while (r->prev_repair)
|
1321
|
+
{
|
1322
|
+
fprintf (stderr, "%s ", yysymbol_name (r->repair.term));
|
1323
|
+
r = r->prev_repair;
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
fprintf (stderr, "\n");
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
static void
|
1330
|
+
yy_print_repair_terms(repair_terms *rep_terms)
|
1331
|
+
{
|
1332
|
+
for (int i = 0; i < rep_terms->length; i++)
|
1333
|
+
fprintf (stderr, "%s ", yysymbol_name (rep_terms->terms[i].kind));
|
1334
|
+
|
1335
|
+
fprintf (stderr, "\n");
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
static void
|
1339
|
+
yy_free_repairs(repairs *reps)
|
1340
|
+
{
|
1341
|
+
while (reps)
|
1342
|
+
{
|
1343
|
+
repairs *r = reps;
|
1344
|
+
reps = reps->next;
|
1345
|
+
free (r->states);
|
1346
|
+
free (r);
|
1347
|
+
}
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
static int
|
1351
|
+
yy_process_repairs(repairs *reps, yysymbol_kind_t token)
|
1352
|
+
{
|
1353
|
+
int yyn;
|
1354
|
+
int yystate = *reps->state;
|
1355
|
+
int yylen = 0;
|
1356
|
+
yysymbol_kind_t yytoken = token;
|
1357
|
+
|
1358
|
+
goto yyrecover_backup;
|
1359
|
+
|
1360
|
+
yyrecover_newstate:
|
1361
|
+
// TODO: check reps->stack_length
|
1362
|
+
reps->state += 1;
|
1363
|
+
*reps->state = (yy_state_t) yystate;
|
1364
|
+
|
1365
|
+
|
1366
|
+
yyrecover_backup:
|
1367
|
+
yyn = yypact[yystate];
|
1368
|
+
if (yypact_value_is_default (yyn))
|
1369
|
+
goto yyrecover_default;
|
1370
|
+
|
1371
|
+
/* "Reading a token" */
|
1372
|
+
if (yytoken == YYSYMBOL_YYEMPTY)
|
1373
|
+
return 1;
|
1374
|
+
|
1375
|
+
yyn += yytoken;
|
1376
|
+
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
|
1377
|
+
goto yyrecover_default;
|
1378
|
+
yyn = yytable[yyn];
|
1379
|
+
if (yyn <= 0)
|
1380
|
+
{
|
1381
|
+
if (yytable_value_is_error (yyn))
|
1382
|
+
goto yyrecover_errlab;
|
1383
|
+
yyn = -yyn;
|
1384
|
+
goto yyrecover_reduce;
|
1385
|
+
}
|
1386
|
+
|
1387
|
+
/* shift */
|
1388
|
+
yystate = yyn;
|
1389
|
+
yytoken = YYSYMBOL_YYEMPTY;
|
1390
|
+
goto yyrecover_newstate;
|
1391
|
+
|
1392
|
+
|
1393
|
+
yyrecover_default:
|
1394
|
+
yyn = yydefact[yystate];
|
1395
|
+
if (yyn == 0)
|
1396
|
+
goto yyrecover_errlab;
|
1397
|
+
goto yyrecover_reduce;
|
1398
|
+
|
1399
|
+
|
1400
|
+
yyrecover_reduce:
|
1401
|
+
yylen = yyr2[yyn];
|
1402
|
+
/* YYPOPSTACK */
|
1403
|
+
reps->state -= yylen;
|
1404
|
+
yylen = 0;
|
1405
|
+
|
1406
|
+
{
|
1407
|
+
const int yylhs = yyr1[yyn] - YYNTOKENS;
|
1408
|
+
const int yyi = yypgoto[yylhs] + *reps->state;
|
1409
|
+
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *reps->state
|
1410
|
+
? yytable[yyi]
|
1411
|
+
: yydefgoto[yylhs]);
|
1412
|
+
}
|
1413
|
+
|
1414
|
+
goto yyrecover_newstate;
|
1415
|
+
|
1416
|
+
yyrecover_errlab:
|
1417
|
+
return 0;
|
1418
|
+
}
|
1419
|
+
|
1420
|
+
static repair_terms *
|
1421
|
+
yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
|
1422
|
+
{
|
1423
|
+
yysymbol_kind_t yytoken = YYTRANSLATE (yychar);
|
1424
|
+
repair_terms *rep_terms = YY_NULLPTR;
|
1425
|
+
int count = 0;
|
1426
|
+
|
1427
|
+
repairs *head = (repairs *) malloc (sizeof (repairs));
|
1428
|
+
repairs *current = head;
|
1429
|
+
repairs *tail = head;
|
1430
|
+
YYPTRDIFF_T stack_length = yyssp - yyss + 1;
|
1431
|
+
|
1432
|
+
head->id = count;
|
1433
|
+
head->next = 0;
|
1434
|
+
head->stack_length = stack_length;
|
1435
|
+
head->states = (yy_state_t *) malloc (sizeof (yy_state_t) * (stack_length));
|
1436
|
+
head->state = head->states + (yyssp - yyss);
|
1437
|
+
YYCOPY (head->states, yyss, stack_length);
|
1438
|
+
head->repair_length = 0;
|
1439
|
+
head->prev_repair = 0;
|
1440
|
+
|
1441
|
+
stack_length = (stack_length * 2 > 100) ? (stack_length * 2) : 100;
|
1442
|
+
count++;
|
1443
|
+
|
1444
|
+
while (current)
|
1445
|
+
{
|
1446
|
+
int yystate = *current->state;
|
1447
|
+
int yyn = yypact[yystate];
|
1448
|
+
/* See also: yypcontext_expected_tokens */
|
1449
|
+
if (!yypact_value_is_default (yyn))
|
1450
|
+
{
|
1451
|
+
int yyxbegin = yyn < 0 ? -yyn : 0;
|
1452
|
+
int yychecklim = YYLAST - yyn + 1;
|
1453
|
+
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
1454
|
+
int yyx;
|
1455
|
+
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
1456
|
+
{
|
1457
|
+
if (yyx != YYSYMBOL_YYerror)
|
1458
|
+
{
|
1459
|
+
if (current->repair_length + 1 > YYMAXREPAIR)
|
1460
|
+
continue;
|
1461
|
+
|
1462
|
+
repairs *new = (repairs *) malloc (sizeof (repairs));
|
1463
|
+
new->id = count;
|
1464
|
+
new->next = 0;
|
1465
|
+
new->stack_length = stack_length;
|
1466
|
+
new->states = (yy_state_t *) malloc (sizeof (yy_state_t) * (stack_length));
|
1467
|
+
new->state = new->states + (current->state - current->states);
|
1468
|
+
YYCOPY (new->states, current->states, current->state - current->states + 1);
|
1469
|
+
new->repair_length = current->repair_length + 1;
|
1470
|
+
new->prev_repair = current;
|
1471
|
+
new->repair.type = insert;
|
1472
|
+
new->repair.term = (yysymbol_kind_t) yyx;
|
1473
|
+
|
1474
|
+
/* Process PDA assuming next token is yyx */
|
1475
|
+
if (! yy_process_repairs (new, yyx))
|
1476
|
+
{
|
1477
|
+
free (new);
|
1478
|
+
continue;
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
tail->next = new;
|
1482
|
+
tail = new;
|
1483
|
+
count++;
|
1484
|
+
|
1485
|
+
if (yyx == yytoken)
|
1486
|
+
{
|
1487
|
+
rep_terms = yy_create_repair_terms (current);
|
1488
|
+
fprintf (stderr, "repair_terms found. id: %d, length: %d\n", rep_terms->id, rep_terms->length);
|
1489
|
+
yy_print_repairs (current);
|
1490
|
+
yy_print_repair_terms (rep_terms);
|
1491
|
+
|
1492
|
+
goto done;
|
1493
|
+
}
|
1494
|
+
|
1495
|
+
fprintf (stderr,
|
1496
|
+
"New repairs is enqueued. count: %d, yystate: %d, yyx: %d\n",
|
1497
|
+
count, yystate, yyx);
|
1498
|
+
yy_print_repairs (new);
|
1499
|
+
}
|
1500
|
+
}
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
current = current->next;
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
done:
|
1507
|
+
|
1508
|
+
yy_free_repairs(head);
|
1509
|
+
|
1510
|
+
if (!rep_terms)
|
1511
|
+
{
|
1512
|
+
fprintf (stderr, "repair_terms not found\n");
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
return rep_terms;
|
1516
|
+
}
|
1517
|
+
<%- end -%>
|
1212
1518
|
|
1213
1519
|
|
1214
1520
|
|
@@ -1227,11 +1533,11 @@ int yychar;
|
|
1227
1533
|
/* The semantic value of the lookahead symbol. */
|
1228
1534
|
/* Default value used for initialization, for pacifying older GCCs
|
1229
1535
|
or non-GCC compilers. */
|
1230
|
-
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
|
1536
|
+
YY_INITIAL_VALUE (static const YYSTYPE yyval_default;)
|
1231
1537
|
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
|
1232
1538
|
|
1233
1539
|
/* Location data for the lookahead symbol. */
|
1234
|
-
static YYLTYPE yyloc_default
|
1540
|
+
static const YYLTYPE yyloc_default
|
1235
1541
|
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
|
1236
1542
|
= { 1, 1, 1, 1 }
|
1237
1543
|
# endif
|
@@ -1279,6 +1585,12 @@ YYLTYPE yylloc = yyloc_default;
|
|
1279
1585
|
|
1280
1586
|
/* The locations where the error started and ended. */
|
1281
1587
|
YYLTYPE yyerror_range[3];
|
1588
|
+
<%- if output.error_recovery -%>
|
1589
|
+
repair_terms *rep_terms = 0;
|
1590
|
+
yy_term term_backup;
|
1591
|
+
int rep_terms_index;
|
1592
|
+
int yychar_backup;
|
1593
|
+
<%- end -%>
|
1282
1594
|
|
1283
1595
|
/* Buffer for error messages, and its allocated size. */
|
1284
1596
|
char yymsgbuf[128];
|
@@ -1322,7 +1634,7 @@ yysetstate:
|
|
1322
1634
|
YY_IGNORE_USELESS_CAST_BEGIN
|
1323
1635
|
*yyssp = YY_CAST (yy_state_t, yystate);
|
1324
1636
|
YY_IGNORE_USELESS_CAST_END
|
1325
|
-
YY_STACK_PRINT (yyss, yyssp);
|
1637
|
+
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1326
1638
|
|
1327
1639
|
if (yyss + yystacksize - 1 <= yyssp)
|
1328
1640
|
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
|
@@ -1413,6 +1725,36 @@ yybackup:
|
|
1413
1725
|
|
1414
1726
|
/* Not known => get a lookahead token if don't already have one. */
|
1415
1727
|
|
1728
|
+
<%- if output.error_recovery -%>
|
1729
|
+
if (yychar == YYEMPTY && rep_terms)
|
1730
|
+
{
|
1731
|
+
|
1732
|
+
if (rep_terms_index < rep_terms->length)
|
1733
|
+
{
|
1734
|
+
YYDPRINTF ((stderr, "An error recovery token is used\n"));
|
1735
|
+
yy_term term = rep_terms->terms[rep_terms_index];
|
1736
|
+
yytoken = term.kind;
|
1737
|
+
yylval = term.value;
|
1738
|
+
yylloc = term.location;
|
1739
|
+
yychar = yytranslate_inverted[yytoken];
|
1740
|
+
YY_SYMBOL_PRINT ("Next error recovery token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
|
1741
|
+
rep_terms_index++;
|
1742
|
+
}
|
1743
|
+
else
|
1744
|
+
{
|
1745
|
+
YYDPRINTF ((stderr, "Error recovery is completed\n"));
|
1746
|
+
yytoken = term_backup.kind;
|
1747
|
+
yylval = term_backup.value;
|
1748
|
+
yylloc = term_backup.location;
|
1749
|
+
yychar = yychar_backup;
|
1750
|
+
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
|
1751
|
+
|
1752
|
+
free (rep_terms);
|
1753
|
+
rep_terms = 0;
|
1754
|
+
yychar_backup = 0;
|
1755
|
+
}
|
1756
|
+
}
|
1757
|
+
<%- end -%>
|
1416
1758
|
/* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
|
1417
1759
|
if (yychar == YYEMPTY)
|
1418
1760
|
{
|
@@ -1440,7 +1782,7 @@ yybackup:
|
|
1440
1782
|
else
|
1441
1783
|
{
|
1442
1784
|
yytoken = YYTRANSLATE (yychar);
|
1443
|
-
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
|
1785
|
+
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
|
1444
1786
|
}
|
1445
1787
|
|
1446
1788
|
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
@@ -1463,7 +1805,7 @@ yybackup:
|
|
1463
1805
|
yyerrstatus--;
|
1464
1806
|
|
1465
1807
|
/* Shift the lookahead token. */
|
1466
|
-
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
1808
|
+
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc<%= output.user_args %>);
|
1467
1809
|
yystate = yyn;
|
1468
1810
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
1469
1811
|
*++yyvsp = yylval;
|
@@ -1505,7 +1847,7 @@ yyreduce:
|
|
1505
1847
|
/* Default location. */
|
1506
1848
|
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
|
1507
1849
|
yyerror_range[1] = yyloc;
|
1508
|
-
YY_REDUCE_PRINT (yyn);
|
1850
|
+
YY_REDUCE_PRINT (yyn<%= output.user_args %>);
|
1509
1851
|
switch (yyn)
|
1510
1852
|
{
|
1511
1853
|
<%= output.user_actions -%>
|
@@ -1523,7 +1865,7 @@ yyreduce:
|
|
1523
1865
|
case of YYERROR or YYBACKUP, subsequent parser actions might lead
|
1524
1866
|
to an incorrect destructor call or verbose syntax error message
|
1525
1867
|
before the lookahead is translated. */
|
1526
|
-
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
|
1868
|
+
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc<%= output.user_args %>);
|
1527
1869
|
|
1528
1870
|
YYPOPSTACK (yylen);
|
1529
1871
|
yylen = 0;
|
@@ -1561,7 +1903,7 @@ yyerrlab:
|
|
1561
1903
|
= {yyssp, yytoken, &yylloc};
|
1562
1904
|
char const *yymsgp = YY_("syntax error");
|
1563
1905
|
int yysyntax_error_status;
|
1564
|
-
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
|
1906
|
+
yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>);
|
1565
1907
|
if (yysyntax_error_status == 0)
|
1566
1908
|
yymsgp = yymsg;
|
1567
1909
|
else if (yysyntax_error_status == -1)
|
@@ -1573,7 +1915,7 @@ yyerrlab:
|
|
1573
1915
|
if (yymsg)
|
1574
1916
|
{
|
1575
1917
|
yysyntax_error_status
|
1576
|
-
= yysyntax_error (&yymsg_alloc, &yymsg, &yyctx);
|
1918
|
+
= yysyntax_error (&yymsg_alloc, &yymsg, &yyctx<%= output.user_args %>);
|
1577
1919
|
yymsgp = yymsg;
|
1578
1920
|
}
|
1579
1921
|
else
|
@@ -1628,7 +1970,7 @@ yyerrorlab:
|
|
1628
1970
|
this YYERROR. */
|
1629
1971
|
YYPOPSTACK (yylen);
|
1630
1972
|
yylen = 0;
|
1631
|
-
YY_STACK_PRINT (yyss, yyssp);
|
1973
|
+
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1632
1974
|
yystate = *yyssp;
|
1633
1975
|
goto yyerrlab1;
|
1634
1976
|
|
@@ -1637,6 +1979,29 @@ yyerrorlab:
|
|
1637
1979
|
| yyerrlab1 -- common code for both syntax error and YYERROR. |
|
1638
1980
|
`-------------------------------------------------------------*/
|
1639
1981
|
yyerrlab1:
|
1982
|
+
<%- if output.error_recovery -%>
|
1983
|
+
{
|
1984
|
+
rep_terms = yyrecover (yyss, yyssp, yychar);
|
1985
|
+
if (rep_terms)
|
1986
|
+
{
|
1987
|
+
for (int i = 0; i < rep_terms->length; i++)
|
1988
|
+
{
|
1989
|
+
yy_term *term = &rep_terms->terms[i];
|
1990
|
+
yy_error_token_initialize (term->kind, &term->value, &term->location<%= output.user_args %>);
|
1991
|
+
}
|
1992
|
+
|
1993
|
+
yychar_backup = yychar;
|
1994
|
+
/* Can be packed into (the tail of) rep_terms? */
|
1995
|
+
term_backup.kind = yytoken;
|
1996
|
+
term_backup.value = yylval;
|
1997
|
+
term_backup.location = yylloc;
|
1998
|
+
rep_terms_index = 0;
|
1999
|
+
yychar = YYEMPTY;
|
2000
|
+
|
2001
|
+
goto yybackup;
|
2002
|
+
}
|
2003
|
+
}
|
2004
|
+
<%- end -%>
|
1640
2005
|
yyerrstatus = 3; /* Each real token shifted decrements this. */
|
1641
2006
|
|
1642
2007
|
/* Pop stack until we find a state that shifts the error token. */
|
@@ -1663,7 +2028,7 @@ yyerrlab1:
|
|
1663
2028
|
YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp<%= output.user_args %>);
|
1664
2029
|
YYPOPSTACK (1);
|
1665
2030
|
yystate = *yyssp;
|
1666
|
-
YY_STACK_PRINT (yyss, yyssp);
|
2031
|
+
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1667
2032
|
}
|
1668
2033
|
|
1669
2034
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
@@ -1675,7 +2040,7 @@ yyerrlab1:
|
|
1675
2040
|
YYLLOC_DEFAULT (*yylsp, yyerror_range, 2);
|
1676
2041
|
|
1677
2042
|
/* Shift the error token. */
|
1678
|
-
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
|
2043
|
+
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>);
|
1679
2044
|
|
1680
2045
|
yystate = yyn;
|
1681
2046
|
goto yynewstate;
|
@@ -1721,7 +2086,7 @@ yyreturnlab:
|
|
1721
2086
|
/* Do not reclaim the symbols of the rule whose action triggered
|
1722
2087
|
this YYABORT or YYACCEPT. */
|
1723
2088
|
YYPOPSTACK (yylen);
|
1724
|
-
YY_STACK_PRINT (yyss, yyssp);
|
2089
|
+
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1725
2090
|
while (yyssp != yyss)
|
1726
2091
|
{
|
1727
2092
|
yydestruct ("Cleanup: popping",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lrama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichiro Kaneko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05
|
11
|
+
date: 2023-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: LALR (1) parser generator written by Ruby
|
14
14
|
email:
|
@@ -36,28 +36,46 @@ files:
|
|
36
36
|
- lib/lrama/context.rb
|
37
37
|
- lib/lrama/digraph.rb
|
38
38
|
- lib/lrama/grammar.rb
|
39
|
+
- lib/lrama/grammar/code.rb
|
40
|
+
- lib/lrama/grammar/error_token.rb
|
41
|
+
- lib/lrama/grammar/precedence.rb
|
42
|
+
- lib/lrama/grammar/printer.rb
|
43
|
+
- lib/lrama/grammar/reference.rb
|
44
|
+
- lib/lrama/grammar/rule.rb
|
45
|
+
- lib/lrama/grammar/symbol.rb
|
46
|
+
- lib/lrama/grammar/union.rb
|
39
47
|
- lib/lrama/lexer.rb
|
48
|
+
- lib/lrama/lexer/token.rb
|
40
49
|
- lib/lrama/output.rb
|
41
50
|
- lib/lrama/parser.rb
|
42
51
|
- lib/lrama/parser/token_scanner.rb
|
43
52
|
- lib/lrama/report.rb
|
53
|
+
- lib/lrama/report/duration.rb
|
54
|
+
- lib/lrama/report/profile.rb
|
44
55
|
- lib/lrama/state.rb
|
45
56
|
- lib/lrama/state/reduce.rb
|
57
|
+
- lib/lrama/state/resolved_conflict.rb
|
46
58
|
- lib/lrama/state/shift.rb
|
47
59
|
- lib/lrama/states.rb
|
60
|
+
- lib/lrama/states/item.rb
|
48
61
|
- lib/lrama/states_reporter.rb
|
49
62
|
- lib/lrama/version.rb
|
50
63
|
- lib/lrama/warning.rb
|
51
64
|
- lrama.gemspec
|
65
|
+
- rbs_collection.lock.yaml
|
66
|
+
- rbs_collection.yaml
|
52
67
|
- sample/calc.output
|
53
68
|
- sample/calc.y
|
54
69
|
- sample/parse.y
|
55
70
|
- sig/lrama/bitmap.rbs
|
71
|
+
- sig/lrama/report/duration.rbs
|
72
|
+
- sig/lrama/report/profile.rbs
|
73
|
+
- sig/lrama/warning.rbs
|
56
74
|
- template/bison/yacc.c
|
57
75
|
- template/bison/yacc.h
|
58
|
-
homepage: https://github.com/
|
76
|
+
homepage: https://github.com/ruby/lrama
|
59
77
|
licenses:
|
60
|
-
-
|
78
|
+
- GPL-3.0-or-later
|
61
79
|
metadata: {}
|
62
80
|
post_install_message:
|
63
81
|
rdoc_options: []
|
@@ -74,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
92
|
- !ruby/object:Gem::Version
|
75
93
|
version: '0'
|
76
94
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.4.1
|
78
96
|
signing_key:
|
79
97
|
specification_version: 4
|
80
98
|
summary: LALR (1) parser generator written by Ruby
|