785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
|
# File 'ext/gherkin_lexer_en_au/gherkin_lexer_en_au.c', line 785
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 819 "ext/gherkin_lexer_en_au/gherkin_lexer_en_au.c"
{
cs = lexer_start;
}
#line 410 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
#line 826 "ext/gherkin_lexer_en_au/gherkin_lexer_en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
MARK(content_start, p);
}
break;
case 2:
#line 91 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
lexer->current_line = lexer->line_number;
lexer->start_col = p - data - lexer->last_newline;
}
break;
case 3:
#line 96 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_KW_END_CON(feature);
}
break;
case 5:
#line 108 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_KW_END_CON(background);
}
break;
case 6:
#line 112 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_KW_END_CON(scenario);
}
break;
case 7:
#line 116 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_KW_END_CON(scenario_outline);
}
break;
case 8:
#line 120 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_KW_END_CON(examples);
}
break;
case 9:
#line 124 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_ATTR(comment);
lexer->mark = 0;
}
break;
case 11:
#line 136 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
STORE_ATTR(tag);
lexer->mark = 0;
}
break;
case 12:
#line 141 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
lexer->line_number += 1;
MARK(final_newline, p);
}
break;
case 13:
#line 146 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
MARK(last_newline, p + 1);
}
break;
case 14:
#line 150 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
if (lexer->mark == 0) {
MARK(mark, p);
}
}
break;
case 15:
#line 156 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
MARK(content_end, p);
}
break;
case 17:
#line 167 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
p = p - 1;
lexer->current_line = lexer->line_number;
current_row = rb_ary_new();
}
break;
case 18:
#line 173 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
MARK(content_start, p);
}
break;
case 19:
#line 177 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.c.rl"
{
rb_funcall(listener, rb_intern("row"), 2, current_row, INT2FIX(lexer->current_line));
}
break;
case 21:
#line 195 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 1102 "ext/gherkin_lexer_en_au/gherkin_lexer_en_au.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 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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 1165 "ext/gherkin_lexer_en_au/gherkin_lexer_en_au.c"
}
}
}
_out: {}
}
#line 411 "/home/ben/oib/gherkin/tasks/../ragel/i18n/en_au.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;
}
}
}
|