Update SMARTS parsing syntax error to include bad token position (#8610)

This commit is contained in:
Hussein Faara
2025-07-15 18:06:59 -07:00
committed by GitHub
parent 768a71a638
commit 82586a0114
12 changed files with 393 additions and 773 deletions

View File

@@ -23,7 +23,7 @@ if(FLEX_EXECUTABLE)
COMPILE_FLAGS "-Pyysmiles_ --noline" )
FLEX_TARGET(SmartsL smarts.ll
${CMAKE_CURRENT_SOURCE_DIR}/lex.yysmarts.cpp
COMPILE_FLAGS "-Pyysmarts_" )
COMPILE_FLAGS "-Pyysmarts_ --noline" )
SET(FLEX_OUTPUT_FILES ${FLEX_SmilesL_OUTPUTS} ${FLEX_SmartsL_OUTPUTS})
else(FLEX_EXECUTABLE)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/lex.yysmiles.cpp.cmake
@@ -39,7 +39,7 @@ if(BISON_EXECUTABLE)
COMPILE_FLAGS "-pyysmiles_ --no-lines" )
BISON_TARGET(SmartsY smarts.yy
${CMAKE_CURRENT_SOURCE_DIR}/smarts.tab.cpp
COMPILE_FLAGS "-pyysmarts_" )
COMPILE_FLAGS "-pyysmarts_ --no-lines" )
SET(BISON_OUTPUT_FILES ${BISON_SmilesY_OUTPUTS} ${BISON_SmartsY_OUTPUTS})
if(FLEX_EXECUTABLE)
ADD_FLEX_BISON_DEPENDENCY(SmilesL SmilesY)
@@ -70,10 +70,10 @@ target_compile_definitions(SmilesParse PRIVATE RDKIT_SMILESPARSE_BUILD)
rdkit_headers(SmartsWrite.h
SmilesParse.h
SmilesParseOps.h
SmilesWrite.h
SmilesWrite.h
CanonicalizeStereoGroups.h
SmilesJSONParsers.h DEST GraphMol/SmilesParse)
rdkit_test(smiTest1 test.cpp LINK_LIBRARIES CIPLabeler FileParsers SmilesParse )
rdkit_test(smiTest2 test2.cpp LINK_LIBRARIES SmilesParse )
rdkit_catch_test(cxsmilesTest cxsmiles_test.cpp LINK_LIBRARIES FileParsers SmilesParse MarvinParser )

View File

@@ -63,38 +63,69 @@ namespace v2 {
namespace SmilesParse {
namespace {
int smarts_parse_helper(const std::string &inp,
std::vector<RDKit::RWMol *> &molVect, Atom *&atom,
Bond *&bond, int start_tok) {
std::list<unsigned int> branchPoints;
template<int(*lex_init)(void**),
size_t(*string_setup)(const std::string &, void *),
int(*lex_destroy)(void*),
typename T>
int generic_parse_helper(T parser,
const std::string &inp,
std::vector<RDKit::RWMol *> &molVect,
Atom *&atom,
Bond *&bond,
int start_tok,
const std::string& input_type) {
std::vector<std::pair<unsigned int, unsigned int>> branchPoints;
void *scanner;
int res = 1; // initialize with fail code
TEST_ASSERT(!yysmarts_lex_init(&scanner));
TEST_ASSERT(!lex_init(&scanner));
size_t ltrim = 0;
try {
size_t ltrim = setup_smarts_string(inp, scanner);
ltrim = string_setup(inp, scanner);
unsigned numAtomsParsed = 0;
unsigned numBondsParsed = 0;
res = yysmarts_parse(inp.c_str() + ltrim, &molVect, atom, bond,
numAtomsParsed, numBondsParsed, &branchPoints, scanner,
start_tok);
// NOTE: This variable will be used to point to the location of the
// offending token if we encounter a syntax error
unsigned int current_token_position = 0;
res = parser(inp.c_str() + ltrim, &molVect, atom, bond,
numAtomsParsed, numBondsParsed, branchPoints, scanner,
start_tok, current_token_position);
} catch (...) {
yysmarts_lex_destroy(scanner);
lex_destroy(scanner);
throw;
}
yysmarts_lex_destroy(scanner);
lex_destroy(scanner);
if (res == 1) {
std::stringstream errout;
errout << "Failed parsing SMARTS '" << inp << "'";
throw SmilesParseException(errout.str());
}
if (!branchPoints.empty()) {
throw SmilesParseException("extra open parentheses");
auto input = inp.c_str() + ltrim;
// If there are multiple unclosed brackets, we want to report them all at
// once.
for (auto [_, open_bracket_position] : branchPoints) {
SmilesParseOps::detail::printSyntaxErrorMessage(
input, "extra open parentheses", open_bracket_position, input_type);
}
}
if (res == 1 || !branchPoints.empty()) {
throw SmilesParseException("Failed parsing " + input_type + " '" + inp + "'");
}
return res;
}
int smarts_parse_helper(const std::string &inp,
std::vector<RDKit::RWMol *> &molVect, Atom *&atom,
Bond *&bond, int start_tok) {
return generic_parse_helper<yysmarts_lex_init,
setup_smarts_string,
yysmarts_lex_destroy>(yysmarts_parse,
inp,
molVect,
atom,
bond,
start_tok,
"SMARTS");
}
int smarts_bond_parse(const std::string &inp, Bond *&bond) {
auto start_tok = static_cast<int>(START_BOND);
std::vector<RWMol *> molVect;
@@ -119,47 +150,15 @@ int smarts_parse(const std::string &inp, std::vector<RDKit::RWMol *> &molVect) {
int smiles_parse_helper(const std::string &inp,
std::vector<RDKit::RWMol *> &molVect, Atom *&atom,
Bond *&bond, int start_tok) {
std::vector<std::pair<unsigned int, unsigned int>> branchPoints;
void *scanner;
int res = 1; // initialize with fail code
unsigned numAtomsParsed = 0;
unsigned numBondsParsed = 0;
TEST_ASSERT(!yysmiles_lex_init(&scanner));
size_t ltrim = 0;
try {
ltrim = setup_smiles_string(inp, scanner);
// NOTE: This variable will be used to point to the location of the
// offending token if we encounter a syntax error
unsigned int current_token_position = 0;
res = yysmiles_parse(inp.c_str() + ltrim, &molVect, atom, bond,
numAtomsParsed, numBondsParsed, branchPoints, scanner,
start_tok, current_token_position);
} catch (...) {
yysmiles_lex_destroy(scanner);
throw;
}
yysmiles_lex_destroy(scanner);
if (res == 1) {
std::stringstream errout;
errout << "Failed parsing SMILES '" << inp << "'";
throw SmilesParseException(errout.str());
}
if (!branchPoints.empty()) {
auto input_smiles = inp.c_str() + ltrim;
// If there are multiple unclosed brackets, we want to report them all at
// once. e.g. CC(CC(CC
for (auto [_, open_bracket_position] : branchPoints) {
SmilesParseOps::detail::printSyntaxErrorMessage(
input_smiles, "extra open parentheses", open_bracket_position);
}
std::stringstream errout;
errout << "Failed parsing SMILES '" << inp << "'";
throw SmilesParseException(errout.str());
}
return res;
return generic_parse_helper<yysmiles_lex_init,
setup_smiles_string,
yysmiles_lex_destroy>(yysmiles_parse,
inp,
molVect,
atom,
bond,
start_tok,
"SMILES");
}
int smiles_bond_parse(const std::string &inp, Bond *&bond) {

View File

@@ -696,7 +696,8 @@ namespace detail {
void printSyntaxErrorMessage(std::string_view input,
std::string_view err_message,
unsigned int bad_token_position) {
unsigned int bad_token_position,
std::string_view input_type) {
// NOTE: If the input is very long, the pointer to the failed location
// becomes less useful. We should truncate the length of the error message
// to 41 chars.
@@ -717,10 +718,10 @@ void printSyntaxErrorMessage(std::string_view input,
(bad_token_position >= prefix_size ? prefix_size
: bad_token_position - 1);
BOOST_LOG(rdErrorLog) << "SMILES Parse Error: " << err_message
BOOST_LOG(rdErrorLog) << input_type << " Parse Error: " << err_message
<< " while parsing: " << input << std::endl;
BOOST_LOG(rdErrorLog)
<< "SMILES Parse Error: check for mistakes around position "
<< input_type << " Parse Error: check for mistakes around position "
<< bad_token_position << ":" << std::endl;
BOOST_LOG(rdErrorLog) << truncate_input(input, bad_token_position - 1)
<< std::endl;

View File

@@ -70,7 +70,8 @@ constexpr auto _needsDetectAtomStereo = "_needsDetectAtomStereo";
void printSyntaxErrorMessage(std::string_view input,
std::string_view err_message,
unsigned int bad_token_position);
unsigned int bad_token_position,
std::string_view input_type);
} // namespace detail
} // namespace SmilesParseOps

View File

@@ -1,6 +1,3 @@
#line 1 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
#line 3 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
#define YY_INT_ALIGNED short int
@@ -794,8 +791,6 @@ static const flex_int16_t yy_chk[363] =
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
#line 1 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
#line 9 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
//
// Copyright (C) 2003-2018 Greg Landrum and Rational Discovery LLC
@@ -820,7 +815,10 @@ extern "C" int fileno(FILE*);
using namespace RDKit;
//static PeriodicTable * gl_ptab = PeriodicTable::getTable();
// This will be called every time we construct a token an will allow us to track
// the position of the current token.
#undef YY_USER_ACTION
#define YY_USER_ACTION current_token_position += yyleng;
#define YY_FATAL_ERROR(msg) smarts_lexer_error(msg)
@@ -855,7 +853,6 @@ size_t setup_smarts_string(const std::string &text,yyscan_t yyscanner){
n = _yybytes_len + 2;
memcpy(buf, yybytes+start, _yybytes_len);
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
b = yysmarts__scan_buffer(buf,n ,yyscanner);
@@ -867,16 +864,11 @@ size_t setup_smarts_string(const std::string &text,yyscan_t yyscanner){
*/
b->yy_is_our_buffer = 1;
POSTCONDITION(b,"invalid buffer");
return start;
}
#line 876 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
#line 878 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
#define INITIAL 0
#define IN_ATOM_STATE 1
#define IN_BRANCH_STATE 2
@@ -1158,11 +1150,7 @@ YY_DECL
}
{
#line 91 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
#line 95 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
if (start_token)
{
int t = start_token;
@@ -1170,9 +1158,6 @@ YY_DECL
return t;
}
#line 1174 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
yy_cp = yyg->yy_c_buf_p;
@@ -1226,252 +1211,140 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 103 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->chiraltype = Atom::ChiralType::CHI_TETRAHEDRAL; return CHI_CLASS_TOKEN; }
YY_BREAK
case 2:
YY_RULE_SETUP
#line 104 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->chiraltype = Atom::ChiralType::CHI_ALLENE; return CHI_CLASS_TOKEN; }
YY_BREAK
case 3:
YY_RULE_SETUP
#line 105 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->chiraltype = Atom::ChiralType::CHI_SQUAREPLANAR; return CHI_CLASS_TOKEN; }
YY_BREAK
case 4:
YY_RULE_SETUP
#line 106 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->chiraltype = Atom::ChiralType::CHI_TRIGONALBIPYRAMIDAL; return CHI_CLASS_TOKEN; }
YY_BREAK
case 5:
YY_RULE_SETUP
#line 107 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->chiraltype = Atom::ChiralType::CHI_OCTAHEDRAL; return CHI_CLASS_TOKEN; }
YY_BREAK
case 6:
YY_RULE_SETUP
#line 109 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return AT_TOKEN; }
YY_BREAK
case 7:
#line 113 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 8:
#line 114 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 9:
#line 115 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 10:
#line 116 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 11:
#line 117 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 12:
#line 118 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 13:
#line 119 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 14:
#line 120 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 15:
#line 121 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 16:
#line 122 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 17:
#line 123 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 18:
#line 124 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 19:
#line 125 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 20:
#line 126 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 21:
#line 127 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 22:
#line 128 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 23:
#line 129 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 24:
#line 130 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 25:
#line 131 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 26:
#line 132 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 27:
#line 133 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 28:
#line 134 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 29:
#line 135 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 30:
#line 136 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 31:
#line 137 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 32:
#line 138 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 33:
#line 139 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 34:
#line 140 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 35:
#line 141 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 36:
#line 142 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 37:
#line 143 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 38:
#line 144 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 39:
#line 145 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 40:
#line 146 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 41:
#line 147 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 42:
#line 148 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 43:
#line 149 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 44:
#line 150 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 45:
#line 151 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 46:
#line 152 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 47:
#line 153 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 48:
#line 154 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 49:
#line 155 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 50:
#line 156 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 51:
#line 157 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 52:
#line 158 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 53:
#line 159 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 54:
#line 160 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 55:
#line 161 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 56:
#line 162 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 57:
#line 163 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 58:
#line 164 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 59:
#line 165 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 60:
#line 166 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 61:
#line 167 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 62:
#line 168 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 63:
#line 169 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 64:
#line 170 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 65:
#line 171 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 66:
#line 172 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 67:
#line 173 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 68:
#line 174 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 69:
#line 175 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 70:
#line 176 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 71:
#line 177 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 72:
#line 178 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 73:
#line 179 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 74:
#line 180 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 75:
#line 181 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 76:
#line 182 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 77:
#line 183 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 78:
#line 184 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 79:
#line 185 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 80:
#line 186 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 81:
#line 187 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 82:
#line 188 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 83:
#line 189 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 84:
#line 190 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 85:
#line 191 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 86:
#line 192 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 87:
#line 193 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 88:
#line 194 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 89:
#line 195 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 90:
#line 196 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 91:
#line 197 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 92:
#line 198 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 93:
#line 199 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 94:
#line 200 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 95:
#line 201 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 96:
#line 202 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 97:
#line 203 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 98:
#line 204 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 99:
#line 205 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 100:
#line 206 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 101:
#line 207 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 102:
#line 208 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 103:
#line 209 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 104:
#line 210 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 105:
#line 211 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 106:
#line 212 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 107:
#line 213 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 108:
#line 214 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 109:
#line 215 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 110:
#line 216 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
case 111:
YY_RULE_SETUP
#line 216 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->atom = new QueryAtom( PeriodicTable::getTable()->getAtomicNumber( yytext ) );
return ATOM_TOKEN;
}
YY_BREAK
case 112:
YY_RULE_SETUP
#line 219 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomExplicitDegreeQuery(1));
@@ -1480,7 +1353,6 @@ YY_RULE_SETUP
YY_BREAK
case 113:
YY_RULE_SETUP
#line 224 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomNonHydrogenDegreeQuery(1));
@@ -1489,7 +1361,6 @@ YY_RULE_SETUP
YY_BREAK
case 114:
YY_RULE_SETUP
#line 230 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomTotalDegreeQuery(1));
@@ -1498,7 +1369,6 @@ YY_RULE_SETUP
YY_BREAK
case 115:
YY_RULE_SETUP
#line 236 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHasRingBondQuery());
@@ -1507,7 +1377,6 @@ YY_RULE_SETUP
YY_BREAK
case 116:
YY_RULE_SETUP
#line 242 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomTotalValenceQuery(1));
@@ -1516,7 +1385,6 @@ YY_RULE_SETUP
YY_BREAK
case 117:
YY_RULE_SETUP
#line 248 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHasHeteroatomNbrsQuery());
@@ -1525,7 +1393,6 @@ YY_RULE_SETUP
YY_BREAK
case 118:
YY_RULE_SETUP
#line 254 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHasAliphaticHeteroatomNbrsQuery());
@@ -1534,7 +1401,6 @@ YY_RULE_SETUP
YY_BREAK
case 119:
YY_RULE_SETUP
#line 260 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHasImplicitHQuery());
@@ -1543,7 +1409,6 @@ YY_RULE_SETUP
YY_BREAK
case 120:
YY_RULE_SETUP
#line 266 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(new AtomRingQuery(-1));
@@ -1552,7 +1417,6 @@ YY_RULE_SETUP
YY_BREAK
case 121:
YY_RULE_SETUP
#line 272 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomInRingQuery());
@@ -1561,112 +1425,90 @@ YY_RULE_SETUP
YY_BREAK
case 122:
YY_RULE_SETUP
#line 278 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return H_TOKEN; }
YY_BREAK
case 123:
YY_RULE_SETUP
#line 281 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 5; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 124:
YY_RULE_SETUP
#line 283 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 6; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 125:
YY_RULE_SETUP
#line 285 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 7; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 126:
YY_RULE_SETUP
#line 287 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 8; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 127:
YY_RULE_SETUP
#line 289 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 9; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 128:
YY_RULE_SETUP
#line 291 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 15; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 129:
YY_RULE_SETUP
#line 293 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 16; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 130:
YY_RULE_SETUP
#line 295 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 17; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 131:
YY_RULE_SETUP
#line 297 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 35; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 132:
YY_RULE_SETUP
#line 299 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 53; return ORGANIC_ATOM_TOKEN; }
YY_BREAK
case 133:
YY_RULE_SETUP
#line 302 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 5; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 134:
YY_RULE_SETUP
#line 304 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 6; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 135:
YY_RULE_SETUP
#line 306 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 7; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 136:
YY_RULE_SETUP
#line 308 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 8; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 137:
YY_RULE_SETUP
#line 310 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 15; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 138:
YY_RULE_SETUP
#line 312 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 16; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 139:
YY_RULE_SETUP
#line 314 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 14; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 140:
YY_RULE_SETUP
#line 316 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 33; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 141:
YY_RULE_SETUP
#line 318 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 34; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 142:
YY_RULE_SETUP
#line 320 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 52; return AROMATIC_ATOM_TOKEN; }
YY_BREAK
case 143:
YY_RULE_SETUP
#line 324 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomNullQuery());
@@ -1675,7 +1517,6 @@ YY_RULE_SETUP
YY_BREAK
case 144:
YY_RULE_SETUP
#line 330 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomAromaticQuery());
@@ -1685,7 +1526,6 @@ YY_RULE_SETUP
YY_BREAK
case 145:
YY_RULE_SETUP
#line 337 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomAliphaticQuery());
@@ -1694,43 +1534,36 @@ YY_RULE_SETUP
YY_BREAK
case 146:
YY_RULE_SETUP
#line 344 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return COLON_TOKEN; }
YY_BREAK
case 147:
YY_RULE_SETUP
#line 346 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return UNDERSCORE_TOKEN; }
YY_BREAK
case 148:
YY_RULE_SETUP
#line 348 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return HASH_TOKEN; }
YY_BREAK
case 149:
YY_RULE_SETUP
#line 350 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->bond = new QueryBond(Bond::DOUBLE);
yylval->bond->setQuery(makeBondOrderEqualsQuery(Bond::DOUBLE));
return BOND_TOKEN; }
YY_BREAK
case 150:
YY_RULE_SETUP
#line 354 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->bond = new QueryBond();
yylval->bond->setQuery(makeBondNullQuery());
return BOND_TOKEN; }
YY_BREAK
case 151:
YY_RULE_SETUP
#line 358 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->bond = new QueryBond(Bond::QUADRUPLE);
yylval->bond->setQuery(makeBondOrderEqualsQuery(Bond::QUADRUPLE));
return BOND_TOKEN; }
YY_BREAK
case 152:
YY_RULE_SETUP
#line 362 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->bond = new QueryBond(Bond::SINGLE);
yylval->bond->setBondDir(Bond::ENDDOWNRIGHT);
yylval->bond->setQuery(makeSingleOrAromaticBondQuery());
@@ -1738,15 +1571,13 @@ YY_RULE_SETUP
YY_BREAK
case 153:
YY_RULE_SETUP
#line 367 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->bond = new QueryBond(Bond::SINGLE);
yylval->bond->setBondDir(Bond::ENDUPRIGHT);
yylval->bond->setQuery(makeSingleOrAromaticBondQuery());
yylval->bond->setQuery(makeSingleOrAromaticBondQuery());
return BOND_TOKEN; }
YY_BREAK
case 154:
YY_RULE_SETUP
#line 372 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->bond = new QueryBond(Bond::DATIVER);
return BOND_TOKEN;
@@ -1754,7 +1585,6 @@ YY_RULE_SETUP
YY_BREAK
case 155:
YY_RULE_SETUP
#line 376 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->bond = new QueryBond(Bond::DATIVEL);
return BOND_TOKEN;
@@ -1762,57 +1592,46 @@ YY_RULE_SETUP
YY_BREAK
case 156:
YY_RULE_SETUP
#line 381 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return MINUS_TOKEN; }
YY_BREAK
case 157:
YY_RULE_SETUP
#line 383 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return PLUS_TOKEN; }
YY_BREAK
case 158:
YY_RULE_SETUP
#line 385 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_push_state(IN_RECURSION_STATE,yyscanner); return BEGIN_RECURSE; }
YY_BREAK
case 159:
YY_RULE_SETUP
#line 387 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_push_state(IN_BRANCH_STATE,yyscanner); return GROUP_OPEN_TOKEN; }
YY_BREAK
case 160:
YY_RULE_SETUP
#line 388 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_pop_state(yyscanner); return GROUP_CLOSE_TOKEN; }
YY_BREAK
case 161:
YY_RULE_SETUP
#line 389 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_pop_state(yyscanner); return END_RECURSE; }
YY_BREAK
case 162:
YY_RULE_SETUP
#line 391 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return RANGE_OPEN_TOKEN; }
YY_BREAK
case 163:
YY_RULE_SETUP
#line 392 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return RANGE_CLOSE_TOKEN; }
YY_BREAK
case 164:
YY_RULE_SETUP
#line 396 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_push_state(IN_ATOM_STATE,yyscanner); return ATOM_OPEN_TOKEN; }
YY_BREAK
case 165:
YY_RULE_SETUP
#line 397 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yy_pop_state(yyscanner); return ATOM_CLOSE_TOKEN; }
YY_BREAK
case 166:
YY_RULE_SETUP
#line 398 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ /* FIX: ???
This rule is here because otherwise recursive SMARTS queries like:
[$(C(=O)[O,N])] lex improperly (no ATOM_CLOSE token is returned).
@@ -1824,47 +1643,38 @@ YY_RULE_SETUP
YY_BREAK
case 167:
YY_RULE_SETUP
#line 407 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return SEPARATOR_TOKEN; }
YY_BREAK
case 168:
YY_RULE_SETUP
#line 409 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return PERCENT_TOKEN; }
YY_BREAK
case 169:
YY_RULE_SETUP
#line 411 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = 0; return ZERO_TOKEN; }
YY_BREAK
case 170:
YY_RULE_SETUP
#line 412 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ yylval->ival = yytext[0]-'0'; return NONZERO_DIGIT_TOKEN; }
YY_BREAK
case 171:
YY_RULE_SETUP
#line 414 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return NOT_TOKEN; }
YY_BREAK
case 172:
YY_RULE_SETUP
#line 416 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return SEMI_TOKEN; }
YY_BREAK
case 173:
YY_RULE_SETUP
#line 418 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return AND_TOKEN; }
YY_BREAK
case 174:
YY_RULE_SETUP
#line 420 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return OR_TOKEN; }
YY_BREAK
case 175:
YY_RULE_SETUP
#line 422 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::S));
@@ -1873,7 +1683,6 @@ YY_RULE_SETUP
YY_BREAK
case 176:
YY_RULE_SETUP
#line 428 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::SP));
@@ -1882,7 +1691,6 @@ YY_RULE_SETUP
YY_BREAK
case 177:
YY_RULE_SETUP
#line 434 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::SP2));
@@ -1891,7 +1699,6 @@ YY_RULE_SETUP
YY_BREAK
case 178:
YY_RULE_SETUP
#line 440 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::SP3));
@@ -1900,7 +1707,6 @@ YY_RULE_SETUP
YY_BREAK
case 179:
YY_RULE_SETUP
#line 445 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::SP3D));
@@ -1909,7 +1715,6 @@ YY_RULE_SETUP
YY_BREAK
case 180:
YY_RULE_SETUP
#line 450 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{
yylval->atom = new QueryAtom();
yylval->atom->setQuery(makeAtomHybridizationQuery(Atom::SP3D2));
@@ -1919,27 +1724,22 @@ YY_RULE_SETUP
case 181:
/* rule 181 can match eol */
YY_RULE_SETUP
#line 455 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
return EOS_TOKEN;
YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(IN_ATOM_STATE):
case YY_STATE_EOF(IN_BRANCH_STATE):
case YY_STATE_EOF(IN_RECURSION_STATE):
#line 457 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
{ return EOS_TOKEN; }
YY_BREAK
case 182:
YY_RULE_SETUP
#line 458 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
return BAD_CHARACTER;
YY_BREAK
case 183:
YY_RULE_SETUP
#line 460 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
#line 1942 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/lex.yysmarts.cpp"
case YY_END_OF_BUFFER:
{
@@ -3160,9 +2960,6 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
#line 460 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.ll"
#undef yysmarts_wrap
int yysmarts_wrap( void ) { return 1; }

View File

@@ -30,7 +30,11 @@ extern "C" int fileno(FILE*);
using namespace RDKit;
//static PeriodicTable * gl_ptab = PeriodicTable::getTable();
// This will be called every time we construct a token an will allow us to track
// the position of the current token.
#undef YY_USER_ACTION
#define YY_USER_ACTION current_token_position += yyleng;
#define YY_FATAL_ERROR(msg) smarts_lexer_error(msg)
@@ -365,7 +369,7 @@ A {
[\/] { yylval->bond = new QueryBond(Bond::SINGLE);
yylval->bond->setBondDir(Bond::ENDUPRIGHT);
yylval->bond->setQuery(makeSingleOrAromaticBondQuery());
yylval->bond->setQuery(makeSingleOrAromaticBondQuery());
return BOND_TOKEN; }
\-\> {

File diff suppressed because it is too large Load Diff

View File

@@ -35,8 +35,8 @@
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YYSMARTS_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED
# define YY_YYSMARTS_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED
#ifndef YY_YYSMARTS_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED
# define YY_YYSMARTS_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -104,7 +104,6 @@ extern int yysmarts_debug;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 81 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.yy"
int moli;
RDKit::QueryAtom * atom;
@@ -112,7 +111,6 @@ union YYSTYPE
RDKit::Atom::ChiralType chiraltype;
int ival;
#line 116 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.tab.hpp"
};
typedef union YYSTYPE YYSTYPE;
@@ -123,16 +121,14 @@ typedef union YYSTYPE YYSTYPE;
int yysmarts_parse (const char *input, std::vector<RDKit::RWMol *> *molList, RDKit::Atom* &lastAtom, RDKit::Bond* &lastBond, unsigned &numAtomsParsed, unsigned &numBondsParsed, std::list<unsigned int> *branchPoints, void *scanner, int& start_token);
int yysmarts_parse (const char *input, std::vector<RDKit::RWMol *> *molList, RDKit::Atom* &lastAtom, RDKit::Bond* &lastBond, unsigned &numAtomsParsed, unsigned &numBondsParsed, std::vector<std::pair<unsigned int, unsigned int>>& branchPoints, void *scanner, int& start_token, unsigned int& current_token_position);
/* "%code provides" blocks. */
#line 74 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.yy"
#ifndef YY_DECL
#define YY_DECL int yylex \
(YYSTYPE * yylval_param , yyscan_t yyscanner, int& start_token)
(YYSTYPE * yylval_param , yyscan_t yyscanner, int& start_token, unsigned int& current_token_position)
#endif
#line 137 "/home/glandrum/RDKit_git/Code/GraphMol/SmilesParse/smarts.tab.hpp"
#endif /* !YY_YYSMARTS_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED */
#endif /* !YY_YYSMARTS_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMARTS_TAB_HPP_INCLUDED */

View File

@@ -7,6 +7,9 @@
//
#include <cstring>
#include <iostream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <GraphMol/RDKitBase.h>
@@ -18,7 +21,7 @@
#define YYDEBUG 1
#include "smarts.tab.hpp"
extern int yysmarts_lex(YYSTYPE *,void *, int &);
extern int yysmarts_lex(YYSTYPE *,void *, int &, unsigned int&);
using namespace RDKit;
namespace {
@@ -37,22 +40,35 @@ yysmarts_error( const char *input,
std::vector<RDKit::RWMol *> *ms,
RDKit::Atom* &,
RDKit::Bond* &,
unsigned int &,unsigned int &,
std::list<unsigned int> *,
void *,int , const char *msg )
unsigned int &,
unsigned int &,
std::vector<std::pair<unsigned int, unsigned int>>&,
void *,
int,
unsigned int bad_token_position,
const char *msg )
{
yyErrorCleanup(ms);
BOOST_LOG(rdErrorLog) << "SMARTS Parse Error: " << msg << " while parsing: " << input << std::endl;
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMARTS");
}
void
yysmarts_error( const char *input,
std::vector<RDKit::RWMol *> *ms,
std::list<unsigned int> *,
void *,int, const char * msg )
std::vector<std::pair<unsigned int, unsigned int>>&,
void *,
int,
unsigned int bad_token_position,
const char * msg )
{
yyErrorCleanup(ms);
BOOST_LOG(rdErrorLog) << "SMARTS Parse Error: " << msg << " while parsing: " << input << std::endl;
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMARTS");
}
@@ -61,20 +77,22 @@ yysmarts_error( const char *input,
%define api.pure full
%lex-param {yyscan_t *scanner}
%lex-param {int& start_token}
%lex-param {unsigned int& current_token_position}
%parse-param {const char *input}
%parse-param {std::vector<RDKit::RWMol *> *molList}
%parse-param {RDKit::Atom* &lastAtom}
%parse-param {RDKit::Bond* &lastBond}
%parse-param {unsigned &numAtomsParsed}
%parse-param {unsigned &numBondsParsed}
%parse-param {std::list<unsigned int> *branchPoints}
%parse-param {std::vector<std::pair<unsigned int, unsigned int>>& branchPoints}
%parse-param {void *scanner}
%parse-param {int& start_token}
%parse-param {unsigned int& current_token_position}
%code provides {
#ifndef YY_DECL
#define YY_DECL int yylex \
(YYSTYPE * yylval_param , yyscan_t yyscanner, int& start_token)
(YYSTYPE * yylval_param , yyscan_t yyscanner, int& start_token, unsigned int& current_token_position)
#endif
}
@@ -101,11 +119,11 @@ yysmarts_error( const char *input,
%token NOT_TOKEN AND_TOKEN OR_TOKEN SEMI_TOKEN BEGIN_RECURSE END_RECURSE
%token COLON_TOKEN UNDERSCORE_TOKEN
%token <bond> BOND_TOKEN
%token <chiraltype> CHI_CLASS_TOKEN
%token <chiraltype> CHI_CLASS_TOKEN
%type <moli> mol
%type <atom> atomd simple_atom hydrogen_atom
%type <atom> atom_expr point_query atom_query recursive_query possible_range_query
%type <ival> ring_number nonzero_number number charge_spec digit
%type <ival> ring_number nonzero_number number charge_spec digit branch_open_token
%type <bond> bondd bond_expr bond_query
%token BAD_CHARACTER
%token EOS_TOKEN
@@ -275,7 +293,7 @@ mol: atomd {
}
| mol GROUP_OPEN_TOKEN atomd {
| mol branch_open_token atomd {
RWMol *mp = (*molList)[$$];
Atom *a1 = mp->getActiveAtom();
int atomIdx1=a1->getIdx();
@@ -289,10 +307,10 @@ mol: atomd {
mp->addBond(newB);
delete newB;
branchPoints->push_back(atomIdx1);
branchPoints.push_back({atomIdx1, $2});
}
| mol GROUP_OPEN_TOKEN bond_expr atomd {
| mol branch_open_token bond_expr atomd {
RWMol *mp = (*molList)[$$];
int atomIdx1 = mp->getActiveAtom()->getIdx();
int atomIdx2 = mp->addAtom($4,true,true);
@@ -310,20 +328,20 @@ mol: atomd {
}
$3->setProp("_cxsmilesBondIdx",numBondsParsed++);
mp->addBond($3,true);
branchPoints->push_back(atomIdx1);
branchPoints.push_back({atomIdx1, $2});
}
| mol GROUP_CLOSE_TOKEN {
if(branchPoints->empty()){
yyerror(input,molList,branchPoints,scanner,start_token,"extra close parentheses");
if(branchPoints.empty()){
yyerror(input,molList,branchPoints,scanner,start_token, current_token_position, "extra close parentheses");
yyErrorCleanup(molList);
YYABORT;
}
RWMol *mp = (*molList)[$$];
mp->setActiveAtom(branchPoints->back());
branchPoints->pop_back();
mp->setActiveAtom(branchPoints.back().first);
branchPoints.pop_back();
}
;
@@ -774,10 +792,10 @@ number: ZERO_TOKEN
/* --------------------------------------------------------------- */
nonzero_number: NONZERO_DIGIT_TOKEN
| nonzero_number digit {
if($1 >= std::numeric_limits<std::int32_t>::max()/10 ||
| nonzero_number digit {
if($1 >= std::numeric_limits<std::int32_t>::max()/10 ||
$1*10 >= std::numeric_limits<std::int32_t>::max()-$2 ){
yysmarts_error(input,molList,lastAtom,lastBond,numAtomsParsed,numBondsParsed,branchPoints,scanner,start_token,"number too large");
yysmarts_error(input,molList,lastAtom,lastBond,numAtomsParsed,numBondsParsed,branchPoints,scanner,start_token, current_token_position, "number too large");
YYABORT;
}
$$ = $1*10 + $2; }
@@ -787,4 +805,7 @@ digit: NONZERO_DIGIT_TOKEN
| ZERO_TOKEN
;
// We'll use the token position for unclosed branch syntax error messages
branch_open_token: GROUP_OPEN_TOKEN { $$ = current_token_position; };
%%

View File

@@ -123,7 +123,10 @@ yysmiles_error( const char *input,
void *,int, unsigned int bad_token_position, const char * msg )
{
yyErrorCleanup(ms);
SmilesParseOps::detail::printSyntaxErrorMessage(input, msg, bad_token_position);
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMILES");
}
void
@@ -133,7 +136,10 @@ yysmiles_error( const char *input,
void *,int, unsigned int bad_token_position, const char * msg )
{
yyErrorCleanup(ms);
SmilesParseOps::detail::printSyntaxErrorMessage(input, msg, bad_token_position);
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMILES");
}
@@ -597,14 +603,14 @@ static const yytype_int8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_int16 yyrline[] =
{
0, 121, 121, 124, 128, 131, 135, 139, 142, 147,
152, 155, 163, 164, 165, 166, 174, 185, 196, 217,
226, 232, 253, 277, 296, 306, 327, 335, 349, 352,
353, 359, 360, 366, 374, 375, 376, 377, 378, 379,
380, 384, 385, 386, 387, 388, 389, 390, 391, 392,
396, 397, 398, 399, 400, 404, 405, 406, 407, 408,
409, 413, 414, 418, 419, 420, 421, 422, 423, 424,
428, 429, 433, 434, 445, 446
0, 127, 127, 130, 134, 137, 141, 145, 148, 153,
158, 161, 169, 170, 171, 172, 180, 191, 202, 223,
232, 238, 259, 283, 302, 312, 333, 341, 355, 358,
359, 365, 366, 372, 380, 381, 382, 383, 384, 385,
386, 390, 391, 392, 393, 394, 395, 396, 397, 398,
402, 403, 404, 405, 406, 410, 411, 412, 413, 414,
415, 419, 420, 424, 425, 426, 427, 428, 429, 430,
434, 435, 439, 440, 451, 452
};
#endif

View File

@@ -35,8 +35,8 @@
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YYSMILES_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED
# define YY_YYSMILES_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED
#ifndef YY_YYSMILES_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED
# define YY_YYSMILES_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -112,4 +112,4 @@ int yysmiles_parse (const char *input, std::vector<RDKit::RWMol *> *molList, RDK
(YYSTYPE * yylval_param , yyscan_t yyscanner, int& start_token, unsigned int& current_token_position)
#endif /* !YY_YYSMILES_HOME_GLANDRUM_RDKIT_GIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED */
#endif /* !YY_YYSMILES_USR_APP_RDKIT_CODE_GRAPHMOL_SMILESPARSE_SMILES_TAB_HPP_INCLUDED */

View File

@@ -49,7 +49,10 @@ yysmiles_error( const char *input,
void *,int, unsigned int bad_token_position, const char * msg )
{
yyErrorCleanup(ms);
SmilesParseOps::detail::printSyntaxErrorMessage(input, msg, bad_token_position);
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMILES");
}
void
@@ -59,7 +62,10 @@ yysmiles_error( const char *input,
void *,int, unsigned int bad_token_position, const char * msg )
{
yyErrorCleanup(ms);
SmilesParseOps::detail::printSyntaxErrorMessage(input, msg, bad_token_position);
SmilesParseOps::detail::printSyntaxErrorMessage(input,
msg,
bad_token_position,
"SMILES");
}