MCPcopy Create free account
hub / github.com/Genivia/RE-flex / get_code

Method get_code

src/reflex.cpp:1184–1307  ·  view source on GitHub ↗

Get line(s) of code, %{ %}, %%top, %%class, %%init, and %%begin

Source from the content-addressed store, hash-verified

1182
1183/// Get line(s) of code, %{ %}, %%top, %%class, %%init, and %%begin
1184std::string Reflex::get_code(size_t& pos)
1185{
1186 std::string code;
1187 size_t at_lineno = lineno;
1188 size_t blk = 0, lev = 0;
1189 enum { CODE, STRING, CHAR, COMMENT } tok = CODE;
1190 bool is_user_code = pos == 0 && is("%{");
1191 if (pos == 0 && (is_user_code || is_top_code() || is_class_code() || is_init_code() || is_begin_code()))
1192 {
1193 ++blk;
1194 pos = linelen;
1195 }
1196 else
1197 {
1198 (void)ws(pos);
1199 if (pos < linelen)
1200 code.append(line.substr(pos));
1201 }
1202 while (true)
1203 {
1204 while (pos >= linelen)
1205 {
1206 if (!get_line())
1207 {
1208 if (tok == STRING)
1209 error("EOF encountered inside an action where a closing \" is expected", NULL, at_lineno);
1210 if (tok == CHAR)
1211 error("EOF encountered inside an action where a closing ' is expected", NULL, at_lineno);
1212 if (tok == COMMENT)
1213 error("EOF encountered inside an action where a closing */ is expected", NULL, at_lineno);
1214 line = "%%"; // end of input: pretend we're at the end of the section
1215 linelen = 2;
1216 }
1217 pos = 0;
1218 if (tok == CODE)
1219 {
1220 if (is("%%"))
1221 {
1222 if (lev > 0 || (!is_user_code && blk > 0))
1223 error("%% section ending encountered inside an action where a closing } is expected", NULL, at_lineno);
1224 else if (blk > 0)
1225 error("%% section ending encountered inside an action where a closing %} is expected", NULL, at_lineno);
1226 }
1227 if (is("%{"))
1228 {
1229 if (blk == 0)
1230 {
1231 at_lineno = lineno;
1232 is_user_code = true;
1233 }
1234 code.push_back('\n');
1235 ++blk;
1236 pos = linelen;
1237 }
1238 else if (is("%}") || (!is_user_code && is("}") && blk == 1 && lev == 0))
1239 {
1240 code.push_back('\n');
1241 if (blk > 0)

Callers

nothing calls this directly

Calls 3

atMethod · 0.80
errorFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected