Example #1
0
void bingoGetName (Scanner &scanner, Array<char> &result)
{
   QS_DEF(Array<char>, str);
   bool single_line = Scanner::isSingleLine(scanner);

   result.clear();

   if (single_line)
   {
      scanner.readLine(str, true);
      int idx = str.find('|');
      int idx2 = 0;

      if (idx >= 0)
      {
         int tmp = str.find(idx + 1, str.size(), '|');

         if (tmp > 0)
            idx2 = tmp + 1;
      }

      BufferScanner scan2(str.ptr() + idx2);

      while (!scan2.isEOF())
      {
         if (isspace(scan2.readChar()))
            break;
      }
      scan2.skipSpace();
      if (!scan2.isEOF())
         scan2.readLine(result, false);
   }
   else
   {
      scanner.readLine(result, false);
      if (result.size() >= 4 && strncmp(result.ptr(), "$RXN", 4) == 0)
         scanner.readLine(result, false);
   }
}
Example #2
0
/**
 * Initialize Table
 * ================================
 *
 * The following reads in the PEG in the passed filename and converts the
 * grammar specification into a set of tokens for traversal when parsing other files
 * according to said grammar.
 */
void Parser::initializeTable(Scanner& input)
{
    // These regexes are used to read in a custom PEG grammar.
    // Refer to /grammars/arithmetic.peg for a more thorough explanation
    // on the grammar. Note all other terms can be manipulated just
    // by reading in the remainder of a line or reading in words.
    Regex arrowOperator = Regex::fromPool("pparser-arrow", "\\->");
    Regex markedWord = Regex::fromPool("pparser-marked-word", "\\A+'?");

    // On any given line, the first two terminals should be the nonterminal
    // being defined and the arrow operator or we've encountered a comment.
    while(input.peek() != EOF) {

        if(input.peek() == PPARSER_COMMENT) {
            input.readLine();
        } else {

            // First read in nonterminal and find start if possible
            std::string nonterminal = input.next(markedWord);
            if(nonterminal.back() == PPARSER_START) {
                nonterminal.pop_back();
                if(start.empty()) {
                    start = nonterminal;
                } else {
                    throw InvalidGrammar("Multiple starting nonterminals", input.getCurrentState());
                }
            }

            // Can now read in the arrow operator
            input.next(arrowOperator);

            // Rest of line is dedicated to definition
            table[nonterminal] = std::make_shared<Choices>(input);
        }
    }

    // Must have at least one starting nonterminal
    if(start.empty()) {
        throw InvalidGrammar("No starting nonterminal specified");
    }

}
Example #3
0
void _importSMILES (OracleEnv &env, const char *table, const char *smiles_col,
                    const char *id_col, const char *file_name)
{
   FileScanner fscanner(file_name);
   AutoPtr<GZipScanner> gzscanner;
   Scanner *scanner;

   int nwritten = 0;
   QS_DEF(Array<char>, id);
   QS_DEF(Array<char>, str);

   env.dbgPrintfTS("importing into table %s\n", table);

   // detect if input is gzipped
   byte magic[2];
   int pos = fscanner.tell();

   fscanner.readCharsFix(2, (char *)magic);
   fscanner.seek(pos, SEEK_SET);

   if (magic[0] == 0x1f && magic[1] == 0x8b)
   {
      gzscanner.reset(new GZipScanner(fscanner));
      scanner = gzscanner.get();
   }
   else
      scanner = &fscanner;

   while (!scanner->isEOF())
   {
      id.clear();
      scanner->readLine(str, false);
      BufferScanner strscan(str);

      strscan.skipSpace();
      while (!strscan.isEOF() && !isspace(strscan.readChar()))
         ;
      strscan.skipSpace();
      if (strscan.lookNext() == '|')
      {
         strscan.readChar();
         while (!strscan.isEOF() && strscan.readChar() != '|')
            ;
         strscan.skipSpace();
      }

      if (!strscan.isEOF() && id_col != 0)
         strscan.readLine(id, true);

      OracleStatement statement(env);

      statement.append("INSERT INTO %s(%s", table, smiles_col);

      if (id_col != 0)
         statement.append(", %s", id_col);

      statement.append(") VALUES(:smiles");

      if (id_col != 0)
      {
         if (id.size() > 1)
            statement.append(", :id");
         else
            statement.append(", NULL");
      }
      statement.append(")");
      statement.prepare();

      str.push(0);
      statement.bindStringByName(":smiles", str.ptr(), str.size());
      if (id.size() > 1)
         statement.bindStringByName(":id", id.ptr(), id.size());

      statement.execute();
      nwritten++;
      if (nwritten % 1000 == 0)
      {
         env.dbgPrintfTS("imported %d items, commiting\n", nwritten);
         OracleStatement::executeSingle(env, "COMMIT");
      }
   }
   if (nwritten % 1000 != 0)
   {
      env.dbgPrintfTS("imported %d items, commiting\n", nwritten);
      OracleStatement::executeSingle(env, "COMMIT");
   }
}