From: Teemu Murtola Date: Mon, 29 Jun 2015 17:48:33 +0000 (+0300) Subject: Only accept exact matches for selection keywords X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=b8f5c7326fe28aeeca51e3c602dbabe3e9da3506;p=alexxy%2Fgromacs.git Only accept exact matches for selection keywords 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 --- diff --git a/src/gromacs/selection/scanner_internal.cpp b/src/gromacs/selection/scanner_internal.cpp index fc20e46890..1f3be505e5 100644 --- a/src/gromacs/selection/scanner_internal.cpp +++ b/src/gromacs/selection/scanner_internal.cpp @@ -281,7 +281,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, YYLTYPE *yylloc, /* 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) { diff --git a/src/gromacs/selection/selmethod.cpp b/src/gromacs/selection/selmethod.cpp index 6524f2fec9..9c22df9e32 100644 --- a/src/gromacs/selection/selmethod.cpp +++ b/src/gromacs/selection/selmethod.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -154,12 +154,15 @@ static const t_register_method smtable_def[] = { {NULL, &sm_altloc}, {NULL, &sm_occupancy}, {NULL, &sm_betafactor}, + {"beta", &sm_betafactor}, {NULL, &sm_x}, {NULL, &sm_y}, {NULL, &sm_z}, {NULL, &sm_distance}, + {"dist", &sm_distance}, {NULL, &sm_mindistance}, + {"mindist", &sm_mindistance}, {NULL, &sm_within}, {NULL, &sm_insolidangle}, {NULL, &sm_same}, @@ -386,7 +389,7 @@ check_params(FILE *fp, const char *name, int nparams, gmx_ana_selparam_t param[] 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; diff --git a/src/gromacs/selection/symrec.cpp b/src/gromacs/selection/symrec.cpp index cd648f60ef..5c45cc33cc 100644 --- a/src/gromacs/selection/symrec.cpp +++ b/src/gromacs/selection/symrec.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -315,8 +315,7 @@ SelectionParserSymbolTable::~SelectionParserSymbolTable() } 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()) @@ -327,20 +326,6 @@ SelectionParserSymbolTable::findSymbol(const std::string &name, { 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(); - } - } return NULL; } diff --git a/src/gromacs/selection/symrec.h b/src/gromacs/selection/symrec.h index d544bddad4..9c29aae6ba 100644 --- a/src/gromacs/selection/symrec.h +++ b/src/gromacs/selection/symrec.h @@ -1,7 +1,7 @@ /* * 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. @@ -217,19 +217,13 @@ class SelectionParserSymbolTable * 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. - * \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. + * Does not throw. */ 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. diff --git a/src/gromacs/selection/tests/refdata/SelectionCollectionDataTest_HandlesBeta.xml b/src/gromacs/selection/tests/refdata/SelectionCollectionDataTest_HandlesBeta.xml index a03266b272..d670e98d8c 100644 --- a/src/gromacs/selection/tests/refdata/SelectionCollectionDataTest_HandlesBeta.xml +++ b/src/gromacs/selection/tests/refdata/SelectionCollectionDataTest_HandlesBeta.xml @@ -4,12 +4,12 @@ beta 0 - betafactor 0 + beta 0 false beta >= 0.3 - betafactor >= 0.3 + beta >= 0.3 false