#line 1 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
#include <assert.h>
#include <ruby.h>

#if defined(_WIN32)
#include <stddef.h>
#endif

#ifdef HAVE_RUBY_RE_H
#include <ruby/re.h>
#else
#include <re.h>
#endif

#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
#define ENCODED_STR_NEW(ptr, len) \
    rb_enc_str_new(ptr, len, rb_utf8_encoding())
#else
#define ENCODED_STR_NEW(ptr, len) \
    rb_str_new(ptr, len)
#endif

#define LF_FLAG      0
#define CRLF_FLAG    1
#define LF           "\n"
#define CRLF         "\r\n"

#ifndef RSTRING_PTR
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
#endif

#ifndef RSTRING_LEN
#define RSTRING_LEN(s) (RSTRING(s)->len)
#endif

#define DATA_GET(FROM, TYPE, NAME) \
  Data_Get_Struct(FROM, TYPE, NAME); \
  if (NAME == NULL) { \
    rb_raise(rb_eArgError, "NULL found for " # NAME " when it shouldn't be."); \
  }
 
typedef struct lexer_state {
  int content_len;
  int line_number;
  int current_line;
  int start_col;
  int eol;
  size_t mark;
  size_t keyword_start;
  size_t keyword_end;
  size_t next_keyword_start;
  size_t content_start;
  size_t content_end;
  size_t query_start;
  size_t last_newline;
  size_t final_newline;
} lexer_state;

static VALUE mGherkin;
static VALUE mCLexer;
static VALUE cI18nLexer;
static VALUE rb_eGherkinLexingError;

#define LEN(AT, P) (P - data - lexer->AT)
#define MARK(M, P) (lexer->M = (P) - data)
#define PTR_TO(P) (data + lexer->P)

#define STORE_KW_END_CON(EVENT) \
  store_kw_con(listener, # EVENT, \
    PTR_TO(keyword_start), LEN(keyword_start, PTR_TO(keyword_end - 1)), \
    PTR_TO(content_start), LEN(content_start, PTR_TO(content_end)), \
    lexer->current_line, lexer->eol); \
    if (lexer->content_end != 0) { \
      p = PTR_TO(content_end - 1); \
    } \
    lexer->content_end = 0

#define STORE_ATTR(ATTR) \
    store_attr(listener, # ATTR, \
      PTR_TO(content_start), LEN(content_start, p), \
      lexer->line_number)


#line 235 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"


/** Data **/

#line 92 "ext/gherkin_lexer_en/gherkin_lexer_en.c"
static const char _lexer_actions[] = {
	0, 1, 0, 1, 1, 1, 2, 1, 
	3, 1, 4, 1, 5, 1, 6, 1, 
	7, 1, 9, 1, 10, 1, 11, 1, 
	14, 1, 15, 1, 16, 1, 17, 1, 
	18, 1, 19, 1, 20, 1, 21, 2, 
	1, 16, 2, 11, 0, 2, 12, 13, 
	2, 15, 0, 2, 15, 2, 2, 15, 
	14, 2, 15, 17, 2, 16, 4, 2, 
	16, 5, 2, 16, 6, 2, 16, 7, 
	2, 16, 8, 2, 16, 14, 2, 18, 
	19, 2, 20, 0, 2, 20, 2, 2, 
	20, 14, 2, 20, 17, 3, 3, 12, 
	13, 3, 9, 12, 13, 3, 10, 12, 
	13, 3, 11, 12, 13, 3, 12, 13, 
	16, 3, 15, 12, 13, 4, 1, 12, 
	13, 16, 4, 15, 0, 12, 13
};

static const short _lexer_key_offsets[] = {
	0, 0, 18, 19, 20, 24, 29, 34, 
	39, 44, 48, 52, 54, 55, 56, 57, 
	58, 59, 60, 61, 62, 63, 64, 65, 
	66, 67, 68, 69, 70, 71, 73, 78, 
	85, 90, 91, 92, 94, 95, 96, 97, 
	98, 99, 100, 101, 102, 103, 104, 105, 
	119, 121, 123, 125, 127, 129, 131, 133, 
	135, 137, 139, 141, 143, 145, 147, 149, 
	167, 168, 169, 170, 171, 172, 173, 174, 
	175, 176, 177, 182, 183, 184, 185, 186, 
	187, 188, 189, 190, 191, 200, 202, 204, 
	206, 208, 210, 212, 214, 216, 218, 220, 
	222, 224, 226, 228, 230, 232, 234, 236, 
	238, 240, 242, 244, 246, 248, 250, 252, 
	254, 256, 258, 260, 262, 265, 267, 269, 
	271, 273, 275, 277, 279, 280, 281, 282, 
	283, 284, 285, 286, 287, 288, 289, 290, 
	293, 294, 295, 296, 297, 298, 299, 300, 
	301, 302, 303, 317, 319, 321, 323, 325, 
	327, 329, 331, 333, 335, 337, 339, 341, 
	343, 345, 347, 349, 351, 353, 355, 357, 
	359, 361, 363, 365, 367, 369, 371, 373, 
	375, 377, 379, 381, 382, 383, 397, 399, 
	401, 403, 405, 407, 409, 411, 413, 415, 
	417, 419, 421, 423, 425, 427, 429, 431, 
	433, 435, 437, 439, 441, 443, 445, 447, 
	449, 451, 453, 455, 457, 460, 462, 464, 
	466, 468, 470, 472, 474, 476, 478, 479, 
	483, 488, 489, 494, 512, 514, 516, 518, 
	520, 522, 524, 526, 528, 530, 532, 534, 
	536, 538, 540, 542, 545, 547, 549, 551, 
	553, 555, 557, 559, 561, 563, 564
};

static const char _lexer_trans_keys[] = {
	10, 32, 34, 35, 37, 42, 64, 65, 
	66, 69, 70, 71, 83, 84, 87, 124, 
	9, 13, 34, 34, 10, 32, 9, 13, 
	10, 32, 34, 9, 13, 10, 32, 34, 
	9, 13, 10, 32, 34, 9, 13, 10, 
	32, 34, 9, 13, 10, 32, 9, 13, 
	10, 32, 9, 13, 10, 13, 10, 95, 
	70, 69, 65, 84, 85, 82, 69, 95, 
	69, 78, 68, 95, 37, 32, 10, 10, 
	13, 13, 32, 64, 9, 10, 9, 10, 
	13, 32, 64, 11, 12, 10, 32, 64, 
	9, 13, 110, 100, 97, 117, 99, 107, 
	103, 114, 111, 117, 110, 100, 58, 10, 
	10, 10, 32, 35, 37, 42, 64, 65, 
	66, 71, 83, 84, 87, 9, 13, 10, 
	95, 10, 70, 10, 69, 10, 65, 10, 
	84, 10, 85, 10, 82, 10, 69, 10, 
	95, 10, 69, 10, 78, 10, 68, 10, 
	95, 10, 37, 10, 32, 10, 32, 34, 
	35, 37, 42, 64, 65, 66, 69, 70, 
	71, 83, 84, 87, 124, 9, 13, 120, 
	97, 109, 112, 108, 101, 115, 58, 10, 
	10, 10, 32, 124, 9, 13, 101, 97, 
	116, 117, 114, 101, 58, 10, 10, 10, 
	32, 35, 37, 64, 66, 83, 9, 13, 
	10, 95, 10, 70, 10, 69, 10, 65, 
	10, 84, 10, 85, 10, 82, 10, 69, 
	10, 95, 10, 69, 10, 78, 10, 68, 
	10, 95, 10, 37, 10, 97, 10, 99, 
	10, 107, 10, 103, 10, 114, 10, 111, 
	10, 117, 10, 110, 10, 100, 10, 58, 
	10, 99, 10, 101, 10, 110, 10, 97, 
	10, 114, 10, 105, 10, 111, 10, 32, 
	58, 10, 79, 10, 117, 10, 116, 10, 
	108, 10, 105, 10, 110, 10, 101, 105, 
	118, 101, 110, 99, 101, 110, 97, 114, 
	105, 111, 32, 58, 115, 79, 117, 116, 
	108, 105, 110, 101, 58, 10, 10, 10, 
	32, 35, 37, 42, 64, 65, 66, 71, 
	83, 84, 87, 9, 13, 10, 95, 10, 
	70, 10, 69, 10, 65, 10, 84, 10, 
	85, 10, 82, 10, 69, 10, 95, 10, 
	69, 10, 78, 10, 68, 10, 95, 10, 
	37, 10, 32, 10, 110, 10, 100, 10, 
	117, 10, 116, 10, 105, 10, 118, 10, 
	101, 10, 110, 10, 99, 10, 101, 10, 
	110, 10, 97, 10, 114, 10, 105, 10, 
	111, 10, 58, 10, 104, 10, 10, 10, 
	32, 35, 37, 42, 64, 65, 66, 71, 
	83, 84, 87, 9, 13, 10, 95, 10, 
	70, 10, 69, 10, 65, 10, 84, 10, 
	85, 10, 82, 10, 69, 10, 95, 10, 
	69, 10, 78, 10, 68, 10, 95, 10, 
	37, 10, 32, 10, 110, 10, 100, 10, 
	117, 10, 116, 10, 105, 10, 118, 10, 
	101, 10, 110, 10, 99, 10, 101, 10, 
	110, 10, 97, 10, 114, 10, 105, 10, 
	111, 10, 32, 58, 10, 79, 10, 117, 
	10, 116, 10, 108, 10, 105, 10, 110, 
	10, 101, 10, 58, 10, 104, 104, 32, 
	124, 9, 13, 10, 32, 124, 9, 13, 
	124, 10, 32, 124, 9, 13, 10, 32, 
	34, 35, 37, 42, 64, 65, 66, 69, 
	70, 71, 83, 84, 87, 124, 9, 13, 
	10, 110, 10, 100, 10, 117, 10, 116, 
	10, 105, 10, 118, 10, 101, 10, 110, 
	10, 99, 10, 101, 10, 110, 10, 97, 
	10, 114, 10, 105, 10, 111, 10, 32, 
	58, 10, 79, 10, 117, 10, 116, 10, 
	108, 10, 105, 10, 110, 10, 101, 10, 
	58, 10, 104, 116, 0
};

static const char _lexer_single_lengths[] = {
	0, 16, 1, 1, 2, 3, 3, 3, 
	3, 2, 2, 2, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 2, 3, 5, 
	3, 1, 1, 2, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 12, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 16, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 3, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 7, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 3, 2, 2, 2, 
	2, 2, 2, 2, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 3, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 12, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 1, 1, 12, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 2, 3, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 1, 2, 
	3, 1, 3, 16, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	2, 2, 2, 3, 2, 2, 2, 2, 
	2, 2, 2, 2, 2, 1, 0
};

static const char _lexer_range_lengths[] = {
	0, 1, 0, 0, 1, 1, 1, 1, 
	1, 1, 1, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 1, 1, 
	1, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 1, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 1, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 1, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 1, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 1, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 1, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 1, 
	1, 0, 1, 1, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0
};

static const short _lexer_index_offsets[] = {
	0, 0, 18, 20, 22, 26, 31, 36, 
	41, 46, 50, 54, 57, 59, 61, 63, 
	65, 67, 69, 71, 73, 75, 77, 79, 
	81, 83, 85, 87, 89, 91, 94, 99, 
	106, 111, 113, 115, 118, 120, 122, 124, 
	126, 128, 130, 132, 134, 136, 138, 140, 
	154, 157, 160, 163, 166, 169, 172, 175, 
	178, 181, 184, 187, 190, 193, 196, 199, 
	217, 219, 221, 223, 225, 227, 229, 231, 
	233, 235, 237, 242, 244, 246, 248, 250, 
	252, 254, 256, 258, 260, 269, 272, 275, 
	278, 281, 284, 287, 290, 293, 296, 299, 
	302, 305, 308, 311, 314, 317, 320, 323, 
	326, 329, 332, 335, 338, 341, 344, 347, 
	350, 353, 356, 359, 362, 366, 369, 372, 
	375, 378, 381, 384, 387, 389, 391, 393, 
	395, 397, 399, 401, 403, 405, 407, 409, 
	413, 415, 417, 419, 421, 423, 425, 427, 
	429, 431, 433, 447, 450, 453, 456, 459, 
	462, 465, 468, 471, 474, 477, 480, 483, 
	486, 489, 492, 495, 498, 501, 504, 507, 
	510, 513, 516, 519, 522, 525, 528, 531, 
	534, 537, 540, 543, 545, 547, 561, 564, 
	567, 570, 573, 576, 579, 582, 585, 588, 
	591, 594, 597, 600, 603, 606, 609, 612, 
	615, 618, 621, 624, 627, 630, 633, 636, 
	639, 642, 645, 648, 651, 655, 658, 661, 
	664, 667, 670, 673, 676, 679, 682, 684, 
	688, 693, 695, 700, 718, 721, 724, 727, 
	730, 733, 736, 739, 742, 745, 748, 751, 
	754, 757, 760, 763, 767, 770, 773, 776, 
	779, 782, 785, 788, 791, 794, 796
};

static const unsigned char _lexer_trans_targs[] = {
	1, 1, 2, 11, 13, 27, 30, 33, 
	35, 64, 75, 124, 128, 222, 222, 223, 
	1, 0, 3, 0, 4, 0, 5, 4, 
	4, 0, 6, 6, 7, 6, 6, 6, 
	6, 7, 6, 6, 6, 6, 8, 6, 
	6, 6, 6, 9, 6, 6, 1, 10, 
	10, 0, 1, 10, 10, 0, 1, 12, 
	11, 1, 0, 14, 0, 15, 0, 16, 
	0, 17, 0, 18, 0, 19, 0, 20, 
	0, 21, 0, 22, 0, 23, 0, 24, 
	0, 25, 0, 26, 0, 254, 0, 28, 
	0, 0, 29, 1, 12, 29, 0, 0, 
	0, 0, 31, 32, 1, 32, 32, 30, 
	31, 31, 1, 32, 30, 32, 0, 34, 
	0, 27, 0, 36, 253, 0, 37, 0, 
	38, 0, 39, 0, 40, 0, 41, 0, 
	42, 0, 43, 0, 44, 0, 45, 0, 
	47, 46, 47, 46, 47, 47, 1, 48, 
	62, 1, 228, 230, 232, 236, 252, 252, 
	47, 46, 47, 49, 46, 47, 50, 46, 
	47, 51, 46, 47, 52, 46, 47, 53, 
	46, 47, 54, 46, 47, 55, 46, 47, 
	56, 46, 47, 57, 46, 47, 58, 46, 
	47, 59, 46, 47, 60, 46, 47, 61, 
	46, 47, 1, 46, 47, 63, 46, 1, 
	1, 2, 11, 13, 27, 30, 33, 35, 
	64, 75, 124, 128, 222, 222, 223, 1, 
	0, 65, 0, 66, 0, 67, 0, 68, 
	0, 69, 0, 70, 0, 71, 0, 72, 
	0, 74, 73, 74, 73, 74, 74, 1, 
	74, 73, 76, 0, 77, 0, 78, 0, 
	79, 0, 80, 0, 81, 0, 82, 0, 
	84, 83, 84, 83, 84, 84, 1, 85, 
	1, 99, 109, 84, 83, 84, 86, 83, 
	84, 87, 83, 84, 88, 83, 84, 89, 
	83, 84, 90, 83, 84, 91, 83, 84, 
	92, 83, 84, 93, 83, 84, 94, 83, 
	84, 95, 83, 84, 96, 83, 84, 97, 
	83, 84, 98, 83, 84, 1, 83, 84, 
	100, 83, 84, 101, 83, 84, 102, 83, 
	84, 103, 83, 84, 104, 83, 84, 105, 
	83, 84, 106, 83, 84, 107, 83, 84, 
	108, 83, 84, 63, 83, 84, 110, 83, 
	84, 111, 83, 84, 112, 83, 84, 113, 
	83, 84, 114, 83, 84, 115, 83, 84, 
	116, 83, 84, 117, 63, 83, 84, 118, 
	83, 84, 119, 83, 84, 120, 83, 84, 
	121, 83, 84, 122, 83, 84, 123, 83, 
	84, 108, 83, 125, 0, 126, 0, 127, 
	0, 27, 0, 129, 0, 130, 0, 131, 
	0, 132, 0, 133, 0, 134, 0, 135, 
	0, 136, 179, 71, 0, 137, 0, 138, 
	0, 139, 0, 140, 0, 141, 0, 142, 
	0, 143, 0, 144, 0, 146, 145, 146, 
	145, 146, 146, 1, 147, 161, 1, 162, 
	164, 166, 170, 178, 178, 146, 145, 146, 
	148, 145, 146, 149, 145, 146, 150, 145, 
	146, 151, 145, 146, 152, 145, 146, 153, 
	145, 146, 154, 145, 146, 155, 145, 146, 
	156, 145, 146, 157, 145, 146, 158, 145, 
	146, 159, 145, 146, 160, 145, 146, 1, 
	145, 146, 63, 145, 146, 163, 145, 146, 
	161, 145, 146, 165, 145, 146, 161, 145, 
	146, 167, 145, 146, 168, 145, 146, 169, 
	145, 146, 161, 145, 146, 171, 145, 146, 
	172, 145, 146, 173, 145, 146, 174, 145, 
	146, 175, 145, 146, 176, 145, 146, 177, 
	145, 146, 63, 145, 146, 168, 145, 181, 
	180, 181, 180, 181, 181, 1, 182, 196, 
	1, 197, 199, 201, 205, 221, 221, 181, 
	180, 181, 183, 180, 181, 184, 180, 181, 
	185, 180, 181, 186, 180, 181, 187, 180, 
	181, 188, 180, 181, 189, 180, 181, 190, 
	180, 181, 191, 180, 181, 192, 180, 181, 
	193, 180, 181, 194, 180, 181, 195, 180, 
	181, 1, 180, 181, 63, 180, 181, 198, 
	180, 181, 196, 180, 181, 200, 180, 181, 
	196, 180, 181, 202, 180, 181, 203, 180, 
	181, 204, 180, 181, 196, 180, 181, 206, 
	180, 181, 207, 180, 181, 208, 180, 181, 
	209, 180, 181, 210, 180, 181, 211, 180, 
	181, 212, 180, 181, 213, 63, 180, 181, 
	214, 180, 181, 215, 180, 181, 216, 180, 
	181, 217, 180, 181, 218, 180, 181, 219, 
	180, 181, 220, 180, 181, 63, 180, 181, 
	203, 180, 126, 0, 223, 224, 223, 0, 
	227, 226, 224, 226, 225, 224, 225, 227, 
	226, 224, 226, 225, 227, 227, 2, 11, 
	13, 27, 30, 33, 35, 64, 75, 124, 
	128, 222, 222, 223, 227, 0, 47, 229, 
	46, 47, 62, 46, 47, 231, 46, 47, 
	62, 46, 47, 233, 46, 47, 234, 46, 
	47, 235, 46, 47, 62, 46, 47, 237, 
	46, 47, 238, 46, 47, 239, 46, 47, 
	240, 46, 47, 241, 46, 47, 242, 46, 
	47, 243, 46, 47, 244, 63, 46, 47, 
	245, 46, 47, 246, 46, 47, 247, 46, 
	47, 248, 46, 47, 249, 46, 47, 250, 
	46, 47, 251, 46, 47, 63, 46, 47, 
	234, 46, 27, 0, 0, 0
};

static const char _lexer_trans_actions[] = {
	45, 0, 5, 1, 0, 23, 1, 23, 
	23, 23, 23, 23, 23, 23, 23, 29, 
	0, 37, 0, 37, 0, 37, 45, 0, 
	0, 37, 117, 39, 39, 39, 3, 109, 
	27, 27, 27, 0, 109, 27, 27, 27, 
	0, 109, 27, 0, 27, 0, 93, 7, 
	7, 37, 45, 0, 0, 37, 101, 19, 
	0, 45, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 37, 48, 97, 17, 0, 37, 37, 
	37, 37, 0, 21, 105, 21, 21, 42, 
	21, 0, 45, 0, 1, 0, 37, 0, 
	37, 0, 37, 0, 0, 37, 0, 37, 
	0, 37, 0, 37, 0, 37, 0, 37, 
	0, 37, 0, 37, 0, 37, 0, 37, 
	122, 48, 45, 0, 45, 0, 63, 27, 
	75, 63, 75, 75, 75, 75, 75, 75, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 11, 0, 45, 11, 0, 113, 
	25, 51, 48, 25, 54, 48, 54, 54, 
	54, 54, 54, 54, 54, 54, 57, 25, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 122, 48, 45, 0, 45, 0, 72, 
	0, 0, 0, 37, 0, 37, 0, 37, 
	0, 37, 0, 37, 0, 37, 0, 37, 
	122, 48, 45, 0, 45, 0, 60, 27, 
	60, 75, 75, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 9, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 9, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 9, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 0, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 0, 37, 0, 
	37, 0, 37, 0, 37, 122, 48, 45, 
	0, 45, 0, 69, 27, 75, 69, 75, 
	75, 75, 75, 75, 75, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 15, 
	0, 45, 15, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 15, 0, 45, 0, 0, 122, 
	48, 45, 0, 45, 0, 66, 27, 75, 
	66, 75, 75, 75, 75, 75, 75, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 13, 0, 45, 13, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 13, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 13, 0, 45, 
	0, 0, 0, 37, 0, 0, 0, 37, 
	45, 31, 78, 31, 31, 33, 0, 45, 
	0, 33, 0, 0, 45, 0, 84, 81, 
	35, 87, 81, 87, 87, 87, 87, 87, 
	87, 87, 87, 90, 0, 37, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 0, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 11, 0, 45, 
	0, 0, 45, 0, 0, 45, 0, 0, 
	45, 0, 0, 45, 0, 0, 45, 0, 
	0, 45, 0, 0, 45, 11, 0, 45, 
	0, 0, 0, 37, 0, 0
};

static const char _lexer_eof_actions[] = {
	0, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37, 37, 
	37, 37, 37, 37, 37, 37, 37
};

static const int lexer_start = 1;
static const int lexer_first_final = 254;
static const int lexer_error = 0;

static const int lexer_en_main = 1;


#line 239 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"

static VALUE 
strip_i(VALUE str, VALUE ary)
{
  rb_funcall(str, rb_intern("strip!"), 0);
  rb_ary_push(ary, str);
  
  return Qnil;
}

static VALUE 
multiline_strip(VALUE text, int eol)
{
  VALUE map = rb_ary_new();
  VALUE split = rb_str_split(text, "\n");
  
  rb_iterate(rb_each, split, strip_i, map);
  
  return rb_ary_join(split, rb_str_new2( \
          eol == CRLF_FLAG ? CRLF : LF ));
}

static void 
store_kw_con(VALUE listener, const char * event_name, 
             const char * keyword_at, size_t keyword_length, 
             const char * at,         size_t length, 
             int current_line, int eol)
{
  VALUE con = Qnil, kw = Qnil;
  kw = ENCODED_STR_NEW(keyword_at, keyword_length);
  con = ENCODED_STR_NEW(at, length);
  con = multiline_strip(con, eol);
  rb_funcall(con, rb_intern("strip!"), 0);
  rb_funcall(listener, rb_intern(event_name), 3, kw, con, INT2FIX(current_line)); 
}

static void 
store_attr(VALUE listener, const char * attr_type,
           const char * at, size_t length, 
           int line)
{
  VALUE val = ENCODED_STR_NEW(at, length);
  rb_funcall(listener, rb_intern(attr_type), 2, val, INT2FIX(line));
}

static void 
store_pystring_content(VALUE listener, 
          int start_col, 
          const char *at, size_t length, 
          int current_line)
{
  VALUE con = ENCODED_STR_NEW(at, length);
  // Gherkin will crash gracefully if the string representation of start_col pushes the pattern past 32 characters
  char pat[32]; 
  snprintf(pat, 32, "^ {0,%d}", start_col); 
  VALUE re = rb_reg_regcomp(rb_str_new2(pat));
  VALUE re2 = rb_reg_regcomp(rb_str_new2("\r\\Z"));
  rb_funcall(con, rb_intern("gsub!"), 2, re, rb_str_new2(""));
  rb_funcall(con, rb_intern("sub!"), 2, re2, rb_str_new2(""));
  rb_funcall(listener, rb_intern("py_string"), 2, con, INT2FIX(current_line));
}

static void 
raise_lexer_error(const char * at, int line)
{ 
  rb_raise(rb_eGherkinLexingError, "Lexing error on line %d: '%s'.", line, at);
}

static int 
count_char(char char_to_count, char *str) {

  int count = 0;
  int i = 0;
  while(str[i] != '\0') {
    if(str[i] == char_to_count) {
      count++;
    }
    i++;
  }
  return count;
}

static void lexer_init(lexer_state *lexer) {
  lexer->content_start = 0;
  lexer->content_end = 0;
  lexer->content_len = 0;
  lexer->mark = 0;
  lexer->keyword_start = 0;
  lexer->keyword_end = 0;
  lexer->next_keyword_start = 0;
  lexer->line_number = 1;
  lexer->last_newline = 0;
  lexer->final_newline = 0;
  lexer->start_col = 0;
  lexer->eol = LF_FLAG;
}

static VALUE CLexer_alloc(VALUE klass)
{
  VALUE obj;
  lexer_state *lxr = ALLOC(lexer_state);
  lexer_init(lxr);

  obj = Data_Wrap_Struct(klass, NULL, -1, lxr);

  return obj;
}

static VALUE CLexer_init(VALUE self, VALUE listener)
{
  rb_iv_set(self, "@listener", listener);
  
  lexer_state *lxr = NULL;
  DATA_GET(self, lexer_state, lxr);
  lexer_init(lxr);
  
  return self;
}

static VALUE CLexer_scan(VALUE self, VALUE input)
{
  lexer_state *lexer = NULL;
  DATA_GET(self, lexer_state, lexer);


  VALUE input_copy = rb_str_dup(input);

  rb_str_append(input_copy, rb_str_new2("\n%_FEATURE_END_%"));
  char *data = RSTRING_PTR(input_copy);
  size_t len = RSTRING_LEN(input_copy);
  
  if (count_char('\r', data) > (count_char('\n', data) / 2)) {
    lexer->eol = CRLF_FLAG;
  }
  
  if (len == 0) { 
    rb_raise(rb_eGherkinLexingError, "No content to lex.");
  } else {

    const char *p, *pe, *eof;
    int cs = 0;
    
    VALUE listener = rb_iv_get(self, "@listener");
    VALUE current_row = Qnil;

    p = data;
    pe = data + len;
    eof = pe;
    
    assert(*pe == '\0' && "pointer does not end on NULL");
    
    
#line 727 "ext/gherkin_lexer_en/gherkin_lexer_en.c"
	{
	cs = lexer_start;
	}

#line 391 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
    
#line 734 "ext/gherkin_lexer_en/gherkin_lexer_en.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 86 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
		MARK(content_start, p);
    lexer->current_line = lexer->line_number;
  }
	break;
	case 1:
#line 91 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    MARK(content_start, p);
  }
	break;
	case 2:
#line 95 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    lexer->current_line = lexer->line_number;
    lexer->start_col = p - data - lexer->last_newline;
  }
	break;
	case 3:
#line 100 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.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 108 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_KW_END_CON(feature);
  }
	break;
	case 5:
#line 112 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_KW_END_CON(background);
  }
	break;
	case 6:
#line 116 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_KW_END_CON(scenario);
  }
	break;
	case 7:
#line 120 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_KW_END_CON(scenario_outline);
  }
	break;
	case 8:
#line 124 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_KW_END_CON(examples);
  }
	break;
	case 9:
#line 128 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.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, lexer->eol);
  }
	break;
	case 10:
#line 135 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_ATTR(comment);
    lexer->mark = 0;
  }
	break;
	case 11:
#line 140 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    STORE_ATTR(tag);
    lexer->mark = 0;
  }
	break;
	case 12:
#line 145 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    lexer->line_number += 1;
    MARK(final_newline, p);
  }
	break;
	case 13:
#line 150 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    MARK(last_newline, p + 1);
  }
	break;
	case 14:
#line 154 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    if (lexer->mark == 0) {
      MARK(mark, p);
    }
  }
	break;
	case 15:
#line 160 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    MARK(keyword_end, p);
    MARK(keyword_start, PTR_TO(mark));
    MARK(content_start, p + 1);
    lexer->mark = 0;
  }
	break;
	case 16:
#line 167 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    MARK(content_end, p);
  }
	break;
	case 17:
#line 171 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    p = p - 1;
    lexer->current_line = lexer->line_number;
    current_row = rb_ary_new();
  }
	break;
	case 18:
#line 177 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
		MARK(content_start, p);
  }
	break;
	case 19:
#line 181 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    VALUE con = ENCODED_STR_NEW(PTR_TO(content_start), LEN(content_start, p));
    rb_funcall(con, rb_intern("strip!"), 0);

    rb_ary_push(current_row, con);
  }
	break;
	case 20:
#line 188 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    rb_funcall(listener, rb_intern("row"), 2, current_row, INT2FIX(lexer->current_line));
  }
	break;
	case 21:
#line 192 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    if (cs < lexer_first_final) {
      if (raise_lexer_error != NULL) {
        size_t count = 0;
        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;
        }

        char newstr[len]; 

        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++;
        }

        int 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 998 "ext/gherkin_lexer_en/gherkin_lexer_en.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 192 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.c.rl"
	{
    if (cs < lexer_first_final) {
      if (raise_lexer_error != NULL) {
        size_t count = 0;
        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;
        }

        char newstr[len]; 

        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++;
        }

        int 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 1057 "ext/gherkin_lexer_en/gherkin_lexer_en.c"
		}
	}
	}

	_out: {}
	}

#line 392 "/Users/aslakhellesoy/scm/gherkin/tasks/../ragel/i18n/en.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;
    }
  }
}

void Init_gherkin_lexer_en()
{
  mGherkin = rb_define_module("Gherkin");
  rb_eGherkinLexingError = rb_const_get(mGherkin, rb_intern("LexingError"));

  mCLexer = rb_define_module_under(mGherkin, "CLexer");
  cI18nLexer = rb_define_class_under(mCLexer, "En", rb_cObject);
  rb_define_alloc_func(cI18nLexer, CLexer_alloc);
  rb_define_method(cI18nLexer, "initialize", CLexer_init, 1);
  rb_define_method(cI18nLexer, "scan", CLexer_scan, 1);
}