Fix minor annoyance with previous commit.

When validating local layout, in particular, we create a dummy text TextClass
and so are not necessarily modifying previously declared material. Hence, we
get a spurious (but harmless) "Incomplete argument definition!" warning. This
suppresses it, but to do that we need to propogate the ReadType.
This commit is contained in:
Richard Kimberly Heck 2020-09-28 22:07:08 -04:00
parent 6f643e52d4
commit 594401912b
4 changed files with 18 additions and 17 deletions

View File

@ -194,15 +194,15 @@ Layout::Layout()
} }
bool Layout::read(Lexer & lex, TextClass const & tclass) bool Layout::read(Lexer & lex, TextClass const & tclass, bool validating)
{ {
// If this is an empty layout, or if no force local version is set, // If this is an empty layout, or if no force local version is set,
// we know that we will not discard the stuff to read // we know that we will not discard the stuff to read
if (forcelocal == 0) if (forcelocal == 0)
return readIgnoreForcelocal(lex, tclass); return readIgnoreForcelocal(lex, tclass, validating);
Layout tmp(*this); Layout tmp(*this);
tmp.forcelocal = 0; tmp.forcelocal = 0;
bool const ret = tmp.readIgnoreForcelocal(lex, tclass); bool const ret = tmp.readIgnoreForcelocal(lex, tclass, validating);
// Keep the stuff if // Keep the stuff if
// - the read version is higher // - the read version is higher
// - both versions are infinity (arbitrary decision) // - both versions are infinity (arbitrary decision)
@ -214,7 +214,8 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
} }
bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass) bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
bool validating)
{ {
// This table is sorted alphabetically [asierra 30March96] // This table is sorted alphabetically [asierra 30March96]
LexerKeyword layoutTags[] = { LexerKeyword layoutTags[] = {
@ -441,7 +442,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
break; break;
case LT_ARGUMENT: case LT_ARGUMENT:
readArgument(lex); readArgument(lex, validating);
break; break;
case LT_NEED_PROTECT: case LT_NEED_PROTECT:
@ -1242,7 +1243,7 @@ void Layout::readArgument(Lexer & lex, bool validating)
error = true; error = true;
} }
} }
if (arg.labelstring.empty()) if (!validating && arg.labelstring.empty()) {
LYXERR0("Incomplete Argument definition!"); LYXERR0("Incomplete Argument definition!");
// remove invalid definition // remove invalid definition
lam.erase(id); lam.erase(id);

View File

@ -58,7 +58,7 @@ public:
void setUnknown(bool unknown) { unknown_ = unknown; } void setUnknown(bool unknown) { unknown_ = unknown; }
/// Reads a layout definition from file /// Reads a layout definition from file
/// \return true on success. /// \return true on success.
bool read(Lexer &, TextClass const &); bool read(Lexer &, TextClass const &, bool validating = false);
/// ///
void readAlign(Lexer &); void readAlign(Lexer &);
/// ///
@ -74,7 +74,7 @@ public:
/// ///
void readSpacing(Lexer &); void readSpacing(Lexer &);
/// ///
void readArgument(Lexer &); void readArgument(Lexer &, bool);
/// Write a layout definition in utf8 encoding /// Write a layout definition in utf8 encoding
void write(std::ostream &) const; void write(std::ostream &) const;
/// ///
@ -411,7 +411,7 @@ public:
private: private:
/// Reads a layout definition from file /// Reads a layout definition from file
/// \return true on success. /// \return true on success.
bool readIgnoreForcelocal(Lexer &, TextClass const &); bool readIgnoreForcelocal(Lexer &, TextClass const &, bool validating);
/// generates the default CSS for this layout /// generates the default CSS for this layout
void makeDefaultCSS() const; void makeDefaultCSS() const;
/// ///

View File

@ -148,10 +148,10 @@ TextClass::TextClass()
} }
bool TextClass::readStyle(Lexer & lexrc, Layout & lay) const bool TextClass::readStyle(Lexer & lexrc, Layout & lay, ReadType rt) const
{ {
LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name())); LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
if (!lay.read(lexrc, *this)) { if (!lay.read(lexrc, *this, rt == VALIDATION)) {
LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\''); LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\'');
return false; return false;
} }
@ -515,7 +515,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
Layout lay; Layout lay;
// Since we couldn't read the name, we just scan the rest // Since we couldn't read the name, we just scan the rest
// of the style and discard it. // of the style and discard it.
error = !readStyle(lexrc, lay); error = !readStyle(lexrc, lay, rt);
break; break;
} }
@ -526,14 +526,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
// block. // block.
if (have_layout && !providestyle) { if (have_layout && !providestyle) {
Layout & lay = operator[](name); Layout & lay = operator[](name);
error = !readStyle(lexrc, lay); error = !readStyle(lexrc, lay, rt);
} }
// If the layout does not exist, then we want to create a new // If the layout does not exist, then we want to create a new
// one, but not if we are in a ModifyStyle block. // one, but not if we are in a ModifyStyle block.
else if (!have_layout && !modifystyle) { else if (!have_layout && !modifystyle) {
Layout layout; Layout layout;
layout.setName(name); layout.setName(name);
error = !readStyle(lexrc, layout); error = !readStyle(lexrc, layout, rt);
if (!error) if (!error)
layoutlist_.push_back(layout); layoutlist_.push_back(layout);
@ -551,7 +551,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
else { else {
Layout lay; Layout lay;
// signal to coverity that we do not care about the result // signal to coverity that we do not care about the result
(void)readStyle(lexrc, lay); (void)readStyle(lexrc, lay, rt);
} }
break; break;
} }
@ -1862,7 +1862,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
defaultLayout = new Layout; defaultLayout = new Layout;
defaultLayout->setUnknown(unknown); defaultLayout->setUnknown(unknown);
defaultLayout->setName(name); defaultLayout->setName(name);
if (!readStyle(lex, *defaultLayout)) { if (!readStyle(lex, *defaultLayout, BASECLASS)) {
// The only way this happens is because the hardcoded layout above // The only way this happens is because the hardcoded layout above
// is wrong. // is wrong.
LATTEST(false); LATTEST(false);

View File

@ -389,7 +389,7 @@ private:
/// Reads the layout file without running layout2layout. /// Reads the layout file without running layout2layout.
ReturnValues readWithoutConv(support::FileName const & filename, ReadType rt); ReturnValues readWithoutConv(support::FileName const & filename, ReadType rt);
/// \return true for success. /// \return true for success.
bool readStyle(Lexer &, Layout &) const; bool readStyle(Lexer &, Layout &, ReadType) const;
/// ///
void readOutputType(Lexer &); void readOutputType(Lexer &);
/// ///