The selection parser tried to be nice to the user and also accept
unambiguous prefixes of keywords, but this also has a lot of side
effects that can be confusing (e.g., it was impossible to create
variables that had names that were prefixes to keywords or to other
variable names). Additionally, this was the only case where user input
could cause an exception during tokenization of the input string, and
that wasn't handled very well during interactive input, either (it
caused the whole program to stop, instead of just reporting the error
like is done for other parsing errors).
Remove the logic, and only make the parser accept exact matches.
Add a few synonyms for keywords where there is a natural abbreviation.
Change-Id: I6041baa2f5a3b7dab87c3d5991e883d2d74ace66
/* Check if the identifier matches with a symbol */
const gmx::SelectionParserSymbol *symbol
/* Check if the identifier matches with a symbol */
const gmx::SelectionParserSymbol *symbol
- = state->sc->symtab->findSymbol(std::string(yytext, yyleng), false);
+ = state->sc->symtab->findSymbol(std::string(yytext, yyleng));
/* If there is no match, return the token as a string */
if (!symbol)
{
/* If there is no match, return the token as a string */
if (!symbol)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{NULL, &sm_altloc},
{NULL, &sm_occupancy},
{NULL, &sm_betafactor},
{NULL, &sm_altloc},
{NULL, &sm_occupancy},
{NULL, &sm_betafactor},
+ {"beta", &sm_betafactor},
{NULL, &sm_x},
{NULL, &sm_y},
{NULL, &sm_z},
{NULL, &sm_distance},
{NULL, &sm_x},
{NULL, &sm_y},
{NULL, &sm_z},
{NULL, &sm_distance},
+ {"dist", &sm_distance},
+ {"mindist", &sm_mindistance},
{NULL, &sm_within},
{NULL, &sm_insolidangle},
{NULL, &sm_same},
{NULL, &sm_within},
{NULL, &sm_insolidangle},
{NULL, &sm_same},
continue;
}
/* Check that the name does not conflict with a method */
continue;
}
/* Check that the name does not conflict with a method */
- if (symtab.findSymbol(param[i].name, true))
+ if (symtab.findSymbol(param[i].name))
{
report_param_error(fp, name, param[i].name, "error: name conflicts with another method or a keyword");
bOk = false;
{
report_param_error(fp, name, param[i].name, "error: name conflicts with another method or a keyword");
bOk = false;
/*
* This file is part of the GROMACS molecular simulation package.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
const SelectionParserSymbol *
}
const SelectionParserSymbol *
-SelectionParserSymbolTable::findSymbol(const std::string &name,
- bool bExact) const
+SelectionParserSymbolTable::findSymbol(const std::string &name) const
{
Impl::SymbolMap::const_iterator sym = impl_->symbols_.lower_bound(name);
if (sym == impl_->symbols_.end())
{
Impl::SymbolMap::const_iterator sym = impl_->symbols_.lower_bound(name);
if (sym == impl_->symbols_.end())
{
return sym->second.get();
}
{
return sym->second.get();
}
- if (!bExact && startsWith(sym->second->name(), name))
- {
- Impl::SymbolMap::const_iterator next = sym;
- ++next;
- if (next != impl_->symbols_.end()
- && startsWith(next->second->name(), name))
- {
- GMX_THROW(InvalidInputError("'" + name + "' is ambiguous"));
- }
- if (sym->second->type() == SelectionParserSymbol::MethodSymbol)
- {
- return sym->second.get();
- }
- }
/*
* This file is part of the GROMACS molecular simulation package.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* Finds a symbol by name.
*
* \param[in] name Symbol name to find.
* Finds a symbol by name.
*
* \param[in] name Symbol name to find.
- * \param[in] bExact If false, symbols that begin with \p name are also
- * considered.
* \returns Pointer to the symbol with name \p name, or
* NULL if not found.
* \returns Pointer to the symbol with name \p name, or
* NULL if not found.
- * \throws InvalidInputError if \p bExact is false and an ambiguous
- * symbol is provided.
- * If no exact match is found and \p bExact is false, returns a symbol
- * that begins with \p name if a unique matching symbol is found.
- * Only selection methods are considered for this inexact match.
*/
const SelectionParserSymbol *
*/
const SelectionParserSymbol *
- findSymbol(const std::string &name, bool bExact) const;
+ findSymbol(const std::string &name) const;
/*! \brief
* Returns the start iterator for iterating symbols of a given type.
/*! \brief
* Returns the start iterator for iterating symbols of a given type.
<ParsedSelections Name="Parsed">
<ParsedSelection Name="Selection1">
<String Name="Input">beta 0</String>
<ParsedSelections Name="Parsed">
<ParsedSelection Name="Selection1">
<String Name="Input">beta 0</String>
- <String Name="Text">betafactor 0</String>
+ <String Name="Text">beta 0</String>
<Bool Name="Dynamic">false</Bool>
</ParsedSelection>
<ParsedSelection Name="Selection2">
<String Name="Input">beta >= 0.3</String>
<Bool Name="Dynamic">false</Bool>
</ParsedSelection>
<ParsedSelection Name="Selection2">
<String Name="Input">beta >= 0.3</String>
- <String Name="Text">betafactor >= 0.3</String>
+ <String Name="Text">beta >= 0.3</String>
<Bool Name="Dynamic">false</Bool>
</ParsedSelection>
</ParsedSelections>
<Bool Name="Dynamic">false</Bool>
</ParsedSelection>
</ParsedSelections>