1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
|
%option reentrant
%option bison-bridge
%option noyywrap
%{
// $Id$
//
// Copyright (c) 2008, Novartis Institutes for BioMedical Research Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Novartis Institutes for BioMedical Research Inc.
// nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Created by Greg Landrum, September 2006
//
#if defined(__CYGWIN__) && !defined(fileno)
// -std=c++11 turns off recent posix features
extern "C" int fileno(FILE*);
#endif
#include <cstdio>
#ifdef WIN32
#include <io.h>
#endif
#include <RDGeneral/Exceptions.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/RDKitQueries.h>
#include <GraphMol/SLNParse/SLNAttribs.h>
#include <string>
#include <cstring>
#include "sln.tab.hpp"
using namespace RDKit;
void setup_sln_string(const std::string &text,yyscan_t yyscanner){
YY_BUFFER_STATE buff=yysln__scan_string(text.c_str(),yyscanner);
POSTCONDITION(buff,"invalid buffer");
}
#define YY_FATAL_ERROR(msg) sln_lexer_error(msg)
void sln_lexer_error(const char *msg) {
BOOST_LOG(rdErrorLog) << msg<<std::endl;
throw ValueErrorException(msg);
}
%}
%option stack
%s IN_SLN_PARAM_STATE
%s IN_CTAB_PARAM_NAME_STATE
%s IN_CTAB_PARAM_VAL_STATE
%s IN_PROP_VAL_STATE
%s IN_RECURSE_STATE
%%
<IN_PROP_VAL_STATE>[^\;\]\>\&\|\!]* {
yylval->text_T=new std::string(yytext);
return TEXT_BLOCK;
}
<IN_SLN_PARAM_STATE>[a-zA-Z]+[a-zA-Z0-9_\-,]* {
yylval->text_T=new std::string(yytext);
return TEXT_BLOCK;
}
<IN_CTAB_PARAM_VAL_STATE>[\"]?[a-zA-Z0-9_\-,\ \.\(\)]+[\"]? {
yylval->text_T=new std::string(yytext);
return TEXT_BLOCK;
}
<IN_CTAB_PARAM_NAME_STATE>[a-zA-Z]+[a-zA-Z0-9_\.]* {
yylval->text_T=new std::string(yytext);
return TEXT_BLOCK;
}
<INITIAL,IN_RECURSE_STATE>He |
<INITIAL,IN_RECURSE_STATE>Li |
<INITIAL,IN_RECURSE_STATE>Be |
<INITIAL,IN_RECURSE_STATE>Ne |
<INITIAL,IN_RECURSE_STATE>Na |
<INITIAL,IN_RECURSE_STATE>Mg |
<INITIAL,IN_RECURSE_STATE>Al |
<INITIAL,IN_RECURSE_STATE>Si |
<INITIAL,IN_RECURSE_STATE>Ar |
<INITIAL,IN_RECURSE_STATE>K |
<INITIAL,IN_RECURSE_STATE>Ca |
<INITIAL,IN_RECURSE_STATE>Sc |
<INITIAL,IN_RECURSE_STATE>Ti |
<INITIAL,IN_RECURSE_STATE>V |
<INITIAL,IN_RECURSE_STATE>Cr |
<INITIAL,IN_RECURSE_STATE>Mn |
<INITIAL,IN_RECURSE_STATE>Co |
<INITIAL,IN_RECURSE_STATE>Fe |
<INITIAL,IN_RECURSE_STATE>Ni |
<INITIAL,IN_RECURSE_STATE>Cu |
<INITIAL,IN_RECURSE_STATE>Zn |
<INITIAL,IN_RECURSE_STATE>Ga |
<INITIAL,IN_RECURSE_STATE>Ge |
<INITIAL,IN_RECURSE_STATE>As |
<INITIAL,IN_RECURSE_STATE>Se |
<INITIAL,IN_RECURSE_STATE>Kr |
<INITIAL,IN_RECURSE_STATE>Rb |
<INITIAL,IN_RECURSE_STATE>Sr |
<INITIAL,IN_RECURSE_STATE>Y |
<INITIAL,IN_RECURSE_STATE>Zr |
<INITIAL,IN_RECURSE_STATE>Nb |
<INITIAL,IN_RECURSE_STATE>Mo |
<INITIAL,IN_RECURSE_STATE>Tc |
<INITIAL,IN_RECURSE_STATE>Ru |
<INITIAL,IN_RECURSE_STATE>Rh |
<INITIAL,IN_RECURSE_STATE>Pd |
<INITIAL,IN_RECURSE_STATE>Ag |
<INITIAL,IN_RECURSE_STATE>Cd |
<INITIAL,IN_RECURSE_STATE>In |
<INITIAL,IN_RECURSE_STATE>Sn |
<INITIAL,IN_RECURSE_STATE>Sb |
<INITIAL,IN_RECURSE_STATE>Te |
<INITIAL,IN_RECURSE_STATE>Xe |
<INITIAL,IN_RECURSE_STATE>Cs |
<INITIAL,IN_RECURSE_STATE>Ba |
<INITIAL,IN_RECURSE_STATE>La |
<INITIAL,IN_RECURSE_STATE>Ce |
<INITIAL,IN_RECURSE_STATE>Pr |
<INITIAL,IN_RECURSE_STATE>Nd |
<INITIAL,IN_RECURSE_STATE>Pm |
<INITIAL,IN_RECURSE_STATE>Sm |
<INITIAL,IN_RECURSE_STATE>Eu |
<INITIAL,IN_RECURSE_STATE>Gd |
<INITIAL,IN_RECURSE_STATE>Tb |
<INITIAL,IN_RECURSE_STATE>Dy |
<INITIAL,IN_RECURSE_STATE>Ho |
<INITIAL,IN_RECURSE_STATE>Er |
<INITIAL,IN_RECURSE_STATE>Tm |
<INITIAL,IN_RECURSE_STATE>Yb |
<INITIAL,IN_RECURSE_STATE>Lu |
<INITIAL,IN_RECURSE_STATE>Hf |
<INITIAL,IN_RECURSE_STATE>Ta |
<INITIAL,IN_RECURSE_STATE>W |
<INITIAL,IN_RECURSE_STATE>Re |
<INITIAL,IN_RECURSE_STATE>Os |
<INITIAL,IN_RECURSE_STATE>Ir |
<INITIAL,IN_RECURSE_STATE>Pt |
<INITIAL,IN_RECURSE_STATE>Au |
<INITIAL,IN_RECURSE_STATE>Hg |
<INITIAL,IN_RECURSE_STATE>Tl |
<INITIAL,IN_RECURSE_STATE>Pb |
<INITIAL,IN_RECURSE_STATE>Bi |
<INITIAL,IN_RECURSE_STATE>Po |
<INITIAL,IN_RECURSE_STATE>At |
<INITIAL,IN_RECURSE_STATE>Rn |
<INITIAL,IN_RECURSE_STATE>Fr |
<INITIAL,IN_RECURSE_STATE>Ra |
<INITIAL,IN_RECURSE_STATE>Ac |
<INITIAL,IN_RECURSE_STATE>Th |
<INITIAL,IN_RECURSE_STATE>Pa |
<INITIAL,IN_RECURSE_STATE>U |
<INITIAL,IN_RECURSE_STATE>Np |
<INITIAL,IN_RECURSE_STATE>Pu |
<INITIAL,IN_RECURSE_STATE>Am |
<INITIAL,IN_RECURSE_STATE>Cm |
<INITIAL,IN_RECURSE_STATE>Bk |
<INITIAL,IN_RECURSE_STATE>Cf |
<INITIAL,IN_RECURSE_STATE>Es |
<INITIAL,IN_RECURSE_STATE>Fm |
<INITIAL,IN_RECURSE_STATE>Md |
<INITIAL,IN_RECURSE_STATE>No |
<INITIAL,IN_RECURSE_STATE>Lr |
<INITIAL,IN_RECURSE_STATE>B |
<INITIAL,IN_RECURSE_STATE>C |
<INITIAL,IN_RECURSE_STATE>N |
<INITIAL,IN_RECURSE_STATE>O |
<INITIAL,IN_RECURSE_STATE>P |
<INITIAL,IN_RECURSE_STATE>S |
<INITIAL,IN_RECURSE_STATE>F |
<INITIAL,IN_RECURSE_STATE>Cl |
<INITIAL,IN_RECURSE_STATE>Br |
<INITIAL,IN_RECURSE_STATE>I {
if((bool)yyextra){
yylval->atom_T = new QueryAtom(PeriodicTable::getTable()->getAtomicNumber(yytext));
} else {
yylval->atom_T = new Atom(PeriodicTable::getTable()->getAtomicNumber(yytext));
}
// SLN has no concept of implicit Hs... they're either in the SLN or they don't exist:
yylval->atom_T->setNoImplicit(true);
return ATOM_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>Any {
yylval->atom_T = new QueryAtom();
yylval->atom_T->setQuery(makeAtomNullQuery());
// SLN has no concept of implicit Hs... they're either in the SLN or they don't exist:
yylval->atom_T->setNoImplicit(true);
return ATOM_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>Hev {
yylval->atom_T = new QueryAtom();
yylval->atom_T->setQuery(makeAtomNumQuery(1));
// FIX: are 2H or 3H heavy atoms or Hs?
yylval->atom_T->getQuery()->setNegation(true);
// SLN has no concept of implicit Hs... they're either in the SLN or they don't exist:
yylval->atom_T->setNoImplicit(true);
return ATOM_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>Hal {
yylval->atom_T = new QueryAtom();
yylval->atom_T->setQuery(makeAtomNumQuery(9));
yylval->atom_T->expandQuery(makeAtomNumQuery(17),Queries::COMPOSITE_OR,true);
yylval->atom_T->expandQuery(makeAtomNumQuery(35),Queries::COMPOSITE_OR,true);
yylval->atom_T->expandQuery(makeAtomNumQuery(53),Queries::COMPOSITE_OR,true);
// SLN has no concept of implicit Hs... they're either in the SLN or they don't exist:
yylval->atom_T->setNoImplicit(true);
return ATOM_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>Het {
yylval->atom_T = new QueryAtom();
yylval->atom_T->setQuery(makeAtomNumQuery(6));
yylval->atom_T->expandQuery(makeAtomNumQuery(1),Queries::COMPOSITE_OR,true);
yylval->atom_T->getQuery()->setNegation(true);
// SLN has no concept of implicit Hs... they're either in the SLN or they don't exist:
yylval->atom_T->setNoImplicit(true);
return ATOM_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>H\[ { yy_push_state(IN_SLN_PARAM_STATE,yyscanner); return H_BRACKET_TOKEN; }
<INITIAL,IN_RECURSE_STATE>H\* { return H_ASTERIX_TOKEN; }
<INITIAL,IN_RECURSE_STATE>H { return H_TOKEN; }
<IN_SLN_PARAM_STATE>is\= |
<IN_SLN_PARAM_STATE>Is\= |
<IN_SLN_PARAM_STATE>iS\= |
<IN_SLN_PARAM_STATE>IS\= { yy_push_state(IN_RECURSE_STATE,yyscanner); return RECURSE_TOKEN; }
<IN_SLN_PARAM_STATE>not\= |
<IN_SLN_PARAM_STATE>Not\= |
<IN_SLN_PARAM_STATE>nOt\= |
<IN_SLN_PARAM_STATE>noT\= |
<IN_SLN_PARAM_STATE>NOt\= |
<IN_SLN_PARAM_STATE>NoT\= |
<IN_SLN_PARAM_STATE>nOT\= |
<IN_SLN_PARAM_STATE>NOT\= { yy_push_state(IN_RECURSE_STATE,yyscanner); return NEG_RECURSE_TOKEN; }
\- { return MINUS_TOKEN; }
\+ { return PLUS_TOKEN; }
\# { return HASH_TOKEN; }
\~ { return TILDE_TOKEN; }
\: { return COLON_TOKEN; }
\( { return OPEN_PAREN_TOKEN; }
\) { return CLOSE_PAREN_TOKEN; }
<IN_SLN_PARAM_STATE>\!\= |
<IN_SLN_PARAM_STATE>\>\= |
<IN_SLN_PARAM_STATE>\<\= |
<IN_SLN_PARAM_STATE>\= |
<IN_SLN_PARAM_STATE>\> |
<IN_SLN_PARAM_STATE>\< {
yy_push_state(IN_PROP_VAL_STATE,yyscanner);
yylval->text_T=new std::string(yytext);
return COMPARE_TOKEN;
}
<IN_CTAB_PARAM_NAME_STATE>\= {
yy_pop_state(yyscanner);
yy_push_state(IN_CTAB_PARAM_VAL_STATE,yyscanner);
return EQUALS_TOKEN;
}
<IN_CTAB_PARAM_NAME_STATE>\:\= {
yy_pop_state(yyscanner);
yy_push_state(IN_CTAB_PARAM_VAL_STATE,yyscanner);
return COLON_EQUALS_TOKEN;
}
<IN_CTAB_PARAM_NAME_STATE>\^\= {
yy_pop_state(yyscanner);
yy_push_state(IN_CTAB_PARAM_VAL_STATE,yyscanner);
return CARET_EQUALS_TOKEN;
}
<INITIAL,IN_RECURSE_STATE>\= {
return EQUALS_TOKEN;
}
<IN_RECURSE_STATE>\; {
yy_pop_state(yyscanner);
return SEMI_TOKEN;
}
<IN_RECURSE_STATE>\& {
yy_pop_state(yyscanner);
return AND_TOKEN;
}
<IN_CTAB_PARAM_NAME_STATE>\; {
return SEMI_TOKEN;
}
<IN_CTAB_PARAM_NAME_STATE>\& {
return AND_TOKEN;
}
<IN_CTAB_PARAM_VAL_STATE>\; {
yy_pop_state(yyscanner);
yy_push_state(IN_CTAB_PARAM_NAME_STATE,yyscanner);
return SEMI_TOKEN;
}
<IN_CTAB_PARAM_VAL_STATE>\& {
yy_pop_state(yyscanner);
yy_push_state(IN_CTAB_PARAM_NAME_STATE,yyscanner);
return AND_TOKEN;
}
<IN_PROP_VAL_STATE>\; {
yy_pop_state(yyscanner);
return SEMI_TOKEN;
}
<IN_PROP_VAL_STATE>\& {
yy_pop_state(yyscanner);
return AND_TOKEN;
}
<IN_PROP_VAL_STATE>\| {
yy_pop_state(yyscanner);
return OR_TOKEN;
}
\; {
return SEMI_TOKEN;
}
\& {
return AND_TOKEN;
}
\! {
return NOT_TOKEN;
}
\[ { yy_push_state(IN_SLN_PARAM_STATE,yyscanner); return OPEN_BRACKET_TOKEN; }
<IN_RECURSE_STATE>\] {
// we're closing a recursive definition, which means we should also be
// closing a parameter block:
yy_pop_state(yyscanner);
if(YY_START!=IN_SLN_PARAM_STATE){
std::cerr << " after closing a recursion, we were not in the appropriate state." <<std::endl;
} else {
yy_pop_state(yyscanner);
}
return CLOSE_BRACKET_TOKEN;
}
<IN_PROP_VAL_STATE>\] {
// if we're currently in an SLN property block (e.g. in []'s), we need
// to pop both the prop_val state and the property block state:
yy_pop_state(yyscanner);
if(YY_START==IN_SLN_PARAM_STATE) {
yy_pop_state(yyscanner);
}
return CLOSE_BRACKET_TOKEN;
}
<IN_SLN_PARAM_STATE>\] { yy_pop_state(yyscanner); return CLOSE_BRACKET_TOKEN; }
\< { yy_push_state(IN_CTAB_PARAM_NAME_STATE,yyscanner); return OPEN_ANGLE_TOKEN; }
<IN_CTAB_PARAM_NAME_STATE>\> { yy_pop_state(yyscanner); return CLOSE_ANGLE_TOKEN; }
<IN_CTAB_PARAM_VAL_STATE>\> { yy_pop_state(yyscanner); return CLOSE_ANGLE_TOKEN; }
<IN_PROP_VAL_STATE>\> {
// if we're currently in a CTAB property block (e.g. in <>'s), we need
// to pop both the prop_val state and the property block state:
yy_pop_state(yyscanner);
if(YY_START==IN_CTAB_PARAM_VAL_STATE) {
yy_pop_state(yyscanner);
}
return CLOSE_ANGLE_TOKEN;
}
\. { return SEPARATOR_TOKEN; }
<IN_RECURSE_STATE>\, {
return COMMA_TOKEN;
}
\@ { return AT_TOKEN; }
\* { return ASTERIX_TOKEN; }
[0-9]+ { yylval->ival_T = atoi( yytext ); return DIGIT_TOKEN; }
\n return 0;
<<EOF>> { return EOS_TOKEN; }
. return yytext[0];
%%
#undef yysln_wrap
int yysln_wrap( void ) { return 1; }
|