From: Ulya Trofimovich Date: Mon, 6 Apr 2015 19:40:43 +0000 (+0100) Subject: Continued adding "--skeleton" switch. X-Git-Tag: 0.15~311 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab2f22ebf847bfaecaaddaf7d46a89a62d9c27bf;p=re2c Continued adding "--skeleton" switch. Generate check for input position in final states: first check that input position equals to the expected one; second advance input position to the beginning of next DFA path (this may be necessary when the generated lexer rollbacks: it should resume with a new DFA path rather than some default characters remaining after rollback). --- diff --git a/re2c/code.cc b/re2c/code.cc index ce3cdf3f..629185f9 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -559,7 +559,7 @@ void Rule::emit(Output & output, uint ind, bool &, const std::string& condName) o << indent(ind); if (flag_skeleton) { - o << "{ printf (\"%u\\n\", cursor - data); continue; }"; + o << "{ if (cursor == &data[positions[2 * i]]) { cursor = &data[positions[2 * i + 1]]; continue; } else { printf (\"error\\n\"); return 1; } }"; } else if (rule->code->autogen) { @@ -1157,17 +1157,17 @@ void DFA::output_skeleton_prolog (OutputFile & o, uint ind) o << indent (ind) << "{\n"; for (uint i = 0; i < ys.size (); i += 2) { + o << indent (ind + 1) << pos + ys[i + 1] << "," << pos + ys[i] << ",\n"; pos += ys[i]; - o << indent (ind + 1) << pos << "," << ys[i + 1] << ",\n"; } o << indent (ind) << "};\n"; - o << indent (ind) << "const unsigned int positions_size = " << ys.size () << ";\n"; + o << indent (ind) << "const unsigned int positions_number = " << ys.size () / 2 << ";\n"; o << indent (ind) << "const YYCTYPE * cursor = data;\n"; o << indent (ind) << "const YYCTYPE * marker = data;\n"; o << indent (ind) << "const YYCTYPE * ctxmarker = data;\n"; o << indent (ind) << "const YYCTYPE * const limit = &data[data_size - 1];\n"; - o << indent (ind) << "for (;;)\n"; + o << indent (ind) << "for (unsigned int i = 0; i < positions_number; ++i)\n"; o << indent (ind) << "{\n"; }