1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
# File 'ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c', line 1194
static VALUE CLexer_scan(VALUE self, VALUE input)
{
VALUE input_copy;
char *data;
size_t len;
VALUE listener = rb_iv_get(self, "@listener");
lexer_state *lexer;
lexer = NULL;
DATA_GET(self, lexer_state, lexer);
input_copy = rb_str_dup(input);
rb_str_append(input_copy, rb_str_new2("\n%_FEATURE_END_%"));
data = RSTRING_PTR(input_copy);
len = RSTRING_LEN(input_copy);
if (len == 0) {
rb_raise(rb_eGherkinLexingError, "No content to lex.");
} else {
const char *p, *pe, *eof;
int cs = 0;
VALUE current_row = Qnil;
p = data;
pe = data + len;
eof = pe;
assert(*pe == '\0' && "pointer does not end on NULL");
#line 1228 "ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c"
{
cs = lexer_start;
}
#line 410 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
#line 1235 "ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c"
{
int _klen;
unsigned int _trans;
const char *_acts;
unsigned int _nacts;
const char *_keys;
if ( p == pe )
goto _test_eof;
if ( cs == 0 )
goto _out;
_resume:
_keys = _lexer_trans_keys + _lexer_key_offsets[cs];
_trans = _lexer_index_offsets[cs];
_klen = _lexer_single_lengths[cs];
if ( _klen > 0 ) {
const char *_lower = _keys;
const char *_mid;
const char *_upper = _keys + _klen - 1;
while (1) {
if ( _upper < _lower )
break;
_mid = _lower + ((_upper-_lower) >> 1);
if ( (*p) < *_mid )
_upper = _mid - 1;
else if ( (*p) > *_mid )
_lower = _mid + 1;
else {
_trans += (_mid - _keys);
goto _match;
}
}
_keys += _klen;
_trans += _klen;
}
_klen = _lexer_range_lengths[cs];
if ( _klen > 0 ) {
const char *_lower = _keys;
const char *_mid;
const char *_upper = _keys + (_klen<<1) - 2;
while (1) {
if ( _upper < _lower )
break;
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
if ( (*p) < _mid[0] )
_upper = _mid - 2;
else if ( (*p) > _mid[1] )
_lower = _mid + 2;
else {
_trans += ((_mid - _keys)>>1);
goto _match;
}
}
_trans += _klen;
}
_match:
cs = _lexer_trans_targs[_trans];
if ( _lexer_trans_actions[_trans] == 0 )
goto _again;
_acts = _lexer_actions + _lexer_trans_actions[_trans];
_nacts = (unsigned int) *_acts++;
while ( _nacts-- > 0 )
{
switch ( *_acts++ )
{
case 0:
#line 81 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(content_start, p);
lexer->current_line = lexer->line_number;
lexer->start_col = lexer->content_start - lexer->last_newline - (lexer->keyword_end - lexer->keyword_start) + 2;
}
break;
case 1:
#line 87 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(content_start, p);
}
break;
case 2:
#line 91 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
lexer->current_line = lexer->line_number;
lexer->start_col = p - data - lexer->last_newline;
}
break;
case 3:
#line 96 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
int len = LEN(content_start, PTR_TO(final_newline));
if (len < 0) len = 0;
store_pystring_content(listener, lexer->start_col, PTR_TO(content_start), len, lexer->current_line);
}
break;
case 4:
#line 104 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_KW_END_CON(feature);
}
break;
case 5:
#line 108 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_KW_END_CON(background);
}
break;
case 6:
#line 112 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_KW_END_CON(scenario);
}
break;
case 7:
#line 116 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_KW_END_CON(scenario_outline);
}
break;
case 8:
#line 120 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_KW_END_CON(examples);
}
break;
case 9:
#line 124 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
store_kw_con(listener, "step",
PTR_TO(keyword_start), LEN(keyword_start, PTR_TO(keyword_end)),
PTR_TO(content_start), LEN(content_start, p),
lexer->current_line);
}
break;
case 10:
#line 131 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_ATTR(comment);
lexer->mark = 0;
}
break;
case 11:
#line 136 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
STORE_ATTR(tag);
lexer->mark = 0;
}
break;
case 12:
#line 141 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
lexer->line_number += 1;
MARK(final_newline, p);
}
break;
case 13:
#line 146 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(last_newline, p + 1);
}
break;
case 14:
#line 150 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
if (lexer->mark == 0) {
MARK(mark, p);
}
}
break;
case 15:
#line 156 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(keyword_end, p);
MARK(keyword_start, PTR_TO(mark));
MARK(content_start, p + 1);
lexer->mark = 0;
}
break;
case 16:
#line 163 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(content_end, p);
}
break;
case 17:
#line 167 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
p = p - 1;
lexer->current_line = lexer->line_number;
current_row = rb_ary_new();
}
break;
case 18:
#line 173 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
MARK(content_start, p);
}
break;
case 19:
#line 177 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
VALUE re_pipe, re_newline, re_backslash;
VALUE con = ENCODED_STR_NEW(PTR_TO(content_start), LEN(content_start, p));
rb_funcall(con, rb_intern("strip!"), 0);
re_pipe = rb_reg_regcomp(rb_str_new2("\\\\\\|"));
re_newline = rb_reg_regcomp(rb_str_new2("\\\\n"));
re_backslash = rb_reg_regcomp(rb_str_new2("\\\\\\\\"));
rb_funcall(con, rb_intern("gsub!"), 2, re_pipe, rb_str_new2("|"));
rb_funcall(con, rb_intern("gsub!"), 2, re_newline, rb_str_new2("\n"));
rb_funcall(con, rb_intern("gsub!"), 2, re_backslash, rb_str_new2("\\"));
rb_ary_push(current_row, con);
}
break;
case 20:
#line 191 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
rb_funcall(listener, rb_intern("row"), 2, current_row, INT2FIX(lexer->current_line));
}
break;
case 21:
#line 195 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
int line;
if (cs < lexer_first_final) {
size_t count = 0;
VALUE newstr_val;
char *newstr;
int newstr_count = 0;
size_t len;
const char *buff;
if (lexer->last_newline != 0) {
len = LEN(last_newline, eof);
buff = PTR_TO(last_newline);
} else {
len = strlen(data);
buff = data;
}
// Allocate as a ruby string so that it gets cleaned up by GC
newstr_val = rb_str_new(buff, len);
newstr = RSTRING_PTR(newstr_val);
for (count = 0; count < len; count++) {
if(buff[count] == 10) {
newstr[newstr_count] = '\0'; // terminate new string at first newline found
break;
} else {
if (buff[count] == '%') {
newstr[newstr_count++] = buff[count];
newstr[newstr_count] = buff[count];
} else {
newstr[newstr_count] = buff[count];
}
}
newstr_count++;
}
line = lexer->line_number;
lexer_init(lexer); // Re-initialize so we can scan again with the same lexer
raise_lexer_error(newstr, line);
} else {
rb_funcall(listener, rb_intern("eof"), 0);
}
}
break;
#line 1511 "ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c"
}
}
_again:
if ( cs == 0 )
goto _out;
if ( ++p != pe )
goto _resume;
_test_eof: {}
if ( p == eof )
{
const char *__acts = _lexer_actions + _lexer_eof_actions[cs];
unsigned int __nacts = (unsigned int) *__acts++;
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 21:
#line 195 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
{
int line;
if (cs < lexer_first_final) {
size_t count = 0;
VALUE newstr_val;
char *newstr;
int newstr_count = 0;
size_t len;
const char *buff;
if (lexer->last_newline != 0) {
len = LEN(last_newline, eof);
buff = PTR_TO(last_newline);
} else {
len = strlen(data);
buff = data;
}
// Allocate as a ruby string so that it gets cleaned up by GC
newstr_val = rb_str_new(buff, len);
newstr = RSTRING_PTR(newstr_val);
for (count = 0; count < len; count++) {
if(buff[count] == 10) {
newstr[newstr_count] = '\0'; // terminate new string at first newline found
break;
} else {
if (buff[count] == '%') {
newstr[newstr_count++] = buff[count];
newstr[newstr_count] = buff[count];
} else {
newstr[newstr_count] = buff[count];
}
}
newstr_count++;
}
line = lexer->line_number;
lexer_init(lexer); // Re-initialize so we can scan again with the same lexer
raise_lexer_error(newstr, line);
} else {
rb_funcall(listener, rb_intern("eof"), 0);
}
}
break;
#line 1574 "ext/gherkin_lexer_en_scouse/gherkin_lexer_en_scouse.c"
}
}
}
_out: {}
}
#line 411 "/Users/ahellesoy/scm/gherkin/tasks/../ragel/i18n/en_scouse.c.rl"
assert(p <= pe && "data overflow after parsing execute");
assert(lexer->content_start <= len && "content starts after data end");
assert(lexer->mark < len && "mark is after data end");
// Reset lexer by re-initializing the whole thing
lexer_init(lexer);
if (cs == lexer_error) {
rb_raise(rb_eGherkinLexingError, "Invalid format, lexing fails.");
} else {
return Qtrue;
}
}
}
|