Can anybody see anything wrogn with this? [It works, just asking...] Counting the unknown tokes seems to be broken (before and after applying this patch)
Andre'
Index: buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.547 diff -u -p -r1.547 buffer.C --- buffer.C 2 Dec 2003 12:39:10 -0000 1.547 +++ buffer.C 2 Dec 2003 14:00:04 -0000 @@ -390,6 +390,7 @@ void unknownClass(string const & unknown } // anon + int Buffer::readHeader(LyXLex & lex) { int unknown_tokens = 0; @@ -435,9 +436,8 @@ int Buffer::readHeader(LyXLex & lex) // if par = 0 normal behavior // else insert behavior // Returns false if "\end_document" is not read (Asger) -bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit) +bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator) { - Paragraph::depth_type depth = 0; bool the_end_read = false; if (paragraphs().empty()) { @@ -458,67 +458,10 @@ bool Buffer::readBody(LyXLex & lex, Para tmpbuf.readHeader(lex); } - while (lex.isOK()) { - lex.nextToken(); - string const token = lex.getString(); - - if (token.empty()) - continue; - - lyxerr[Debug::PARSER] << "Handling token: `" - << token << '\'' << endl; - - if (token == "\\end_document") { - the_end_read = true; - continue; - } - - readParagraph(lex, token, paragraphs(), pit, depth); - } + if (text().read(*this, lex)) + the_end_read = true; return the_end_read; -} - - -int Buffer::readParagraph(LyXLex & lex, string const & token, - ParagraphList & pars, ParagraphList::iterator & pit, - lyx::depth_type & depth) -{ - static Change current_change; - int unknown = 0; - - if (token == "\\begin_layout") { - lex.pushToken(token); - - Paragraph par; - par.params().depth(depth); - if (params().tracking_changes) - par.trackChanges(); - LyXFont f(LyXFont::ALL_INHERIT, params().language); - par.setFont(0, f); - - // insert after - if (pit != pars.end()) - ++pit; - - pit = pars.insert(pit, par); - - // FIXME: goddamn InsetTabular makes us pass a Buffer - // not BufferParams - ::readParagraph(*this, *pit, lex); - - } else if (token == "\\begin_deeper") { - ++depth; - } else if (token == "\\end_deeper") { - if (!depth) { - lex.printError("\\end_deeper: " "depth is already null"); - } else { - --depth; - } - } else { - ++unknown; - } - return unknown; } Index: buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.174 diff -u -p -r1.174 buffer.h --- buffer.h 28 Nov 2003 15:08:38 -0000 1.174 +++ buffer.h 2 Dec 2003 14:00:04 -0000 @@ -96,12 +96,6 @@ public: */ bool readBody(LyXLex &, ParagraphList::iterator pit); - /// This parses a single token - int readParagraph(LyXLex &, std::string const & token, - ParagraphList & pars, - ParagraphList::iterator & pit, - lyx::depth_type & depth); - /// void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &, LyXFont const &, std::string const &); Index: lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.266 diff -u -p -r1.266 lyxtext.h --- lyxtext.h 2 Dec 2003 12:39:11 -0000 1.266 +++ lyxtext.h 2 Dec 2003 14:00:04 -0000 @@ -393,6 +393,8 @@ public: /// void write(Buffer const & buf, std::ostream & os) const; + /// returns whether we've seen our usual 'end' marker + bool read(Buffer const & buf, LyXLex & lex); public: /// Index: paragraph_funcs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v retrieving revision 1.90 diff -u -p -r1.90 paragraph_funcs.C --- paragraph_funcs.C 28 Nov 2003 15:53:25 -0000 1.90 +++ paragraph_funcs.C 2 Dec 2003 14:00:04 -0000 @@ -303,7 +303,8 @@ int getEndLabel(ParagraphList::iterator namespace { -int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & token) +int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex, + string const & token) { static LyXFont font; static Change change; @@ -499,7 +500,7 @@ int readParToken(Buffer & buf, Paragraph } -int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex) +int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex) { int unknown = 0; Index: paragraph_funcs.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.h,v retrieving revision 1.37 diff -u -p -r1.37 paragraph_funcs.h --- paragraph_funcs.h 17 Nov 2003 20:28:09 -0000 1.37 +++ paragraph_funcs.h 2 Dec 2003 14:00:04 -0000 @@ -64,7 +64,7 @@ int getEndLabel(ParagraphList::iterator ParagraphList const & plist); /// read a paragraph from a .lyx file. Returns number of unrecognised tokens -int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex); +int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex); LyXFont const outerFont(ParagraphList::iterator pit, ParagraphList const & plist); Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.506 diff -u -p -r1.506 text.C --- text.C 2 Dec 2003 12:39:11 -0000 1.506 +++ text.C 2 Dec 2003 14:00:04 -0000 @@ -29,6 +29,7 @@ #include "language.h" #include "LColor.h" #include "lyxlength.h" +#include "lyxlex.h" #include "lyxrc.h" #include "lyxrow.h" #include "lyxrow_funcs.h" @@ -1629,7 +1630,7 @@ void LyXText::metrics(MetricsInfo & mi, // only used for inset right now. should also be used for main text -void LyXText::draw(PainterInfo & pi, int x, int y) const +void LyXText::draw(PainterInfo &, int x, int y) const { xo_ = x; yo_ = y; @@ -1766,4 +1767,80 @@ void LyXText::write(Buffer const & buf, Paragraph::depth_type dth = 0; for (; pit != end; ++pit) pit->write(buf, os, buf.params(), dth); +} + + +bool LyXText::read(Buffer const & buf, LyXLex & lex) +{ + static Change current_change; + + bool the_end_read = false; + ParagraphList::iterator pit = paragraphs().begin(); + Paragraph::depth_type depth = 0; + + while (lex.isOK()) { + lex.nextToken(); + string token = lex.getString(); + + if (token.empty()) + continue; + + if (in_inset_) { + + if (token == "\\end_inset") { + the_end_read = true; + break; + } + + if (token == "\\end_document") { + lex.printError("\\end_document read in inset! Error in document!"); + return false; + } + + } else { + + if (token == "\\end_document") { + the_end_read = true; + continue; + } + + } + + // FIXME: ugly. + int unknown = 0; + + if (token == "\\begin_layout") { + lex.pushToken(token); + + Paragraph par; + par.params().depth(depth); + if (buf.params().tracking_changes) + par.trackChanges(); + LyXFont f(LyXFont::ALL_INHERIT, buf.params().language); + par.setFont(0, f); + + // insert after + if (pit != paragraphs().end()) + ++pit; + + pit = paragraphs().insert(pit, par); + + // FIXME: goddamn InsetTabular makes us pass a Buffer + // not BufferParams + ::readParagraph(buf, *pit, lex); + + } else if (token == "\\begin_deeper") { + ++depth; + } else if (token == "\\end_deeper") { + if (!depth) { + lex.printError("\\end_deeper: " "depth is already null"); + } else { + --depth; + } + } else { + ++unknown; + } + + } + return the_end_read; } Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.558 diff -u -p -r1.558 insettext.C --- insets/insettext.C 2 Dec 2003 12:39:14 -0000 1.558 +++ insets/insettext.C 2 Dec 2003 14:00:04 -0000 @@ -149,9 +149,6 @@ void InsetText::write(Buffer const & buf void InsetText::read(Buffer const & buf, LyXLex & lex) { - string token; - Paragraph::depth_type depth = 0; - clear(false); #warning John, look here. Doesnt make much sense. @@ -161,32 +158,10 @@ void InsetText::read(Buffer const & buf, // delete the initial paragraph Paragraph oldpar = *paragraphs().begin(); paragraphs().clear(); - ParagraphList::iterator pit = paragraphs().begin(); - - while (lex.isOK()) { - lex.nextToken(); - token = lex.getString(); - if (token.empty()) - continue; - if (token == "\\end_inset") { - break; - } - - if (token == "\\end_document") { - lex.printError("\\end_document read in inset! Error in document!"); - return; - } - - // FIXME: ugly. - const_cast<Buffer&>(buf).readParagraph(lex, token, paragraphs(), pit, depth); - } - - pit = paragraphs().begin(); - ParagraphList::iterator const end = paragraphs().end(); - for (; pit != end; ++pit) - pit->setInsetOwner(this); + bool res = text_.read(buf, lex); + init(); - if (token != "\\end_inset") { + if (!res) { lex.printError("Missing \\end_inset at this point. " "Read: `$$Token'"); }