bool LparseParser::parseRule(int rt) { if (knownRuleType(rt)) { int bound = -1; bool weights = false; active_->setType(static_cast<Asp::RuleType>(rt)); if (rt == Asp::CHOICERULE || rt == Asp::DISJUNCTIVERULE) { int heads = input()->parseInt(1, INT_MAX, "Rule has too few heads"); for (int i = 0; i < heads; ++i) { active_->addHead(parseAtom()); } } else if (rt == Asp::OPTIMIZERULE) { weights = input()->parseInt(0, 0, "Minimize rule: 0 expected!") == 0; } else { active_->addHead(parseAtom()); weights = rt == Asp::WEIGHTRULE && check(input()->parseInt(bound, 0, INT_MAX), "Weightrule: Positive weight expected!"); } int lits = input()->parseInt(0, INT_MAX, "Number of body literals expected!"); int neg = input()->parseInt(0, lits, "Illegal negative body size!"); check(rt != Asp::CONSTRAINTRULE || input()->parseInt(bound, 0, INT_MAX), "Constraint rule: Positive bound expected!"); if (bound >= 0) { active_->setBound(bound); } return parseBody(static_cast<uint32>(lits), static_cast<uint32>(neg), weights) && addRule(*active_); } else if (rt >= 90 && rt < 93) { if (rt == 90) { return input()->parseInt(0, 0, "0 expected") == 0; } int a = input()->parseInt(1, INT_MAX, "atom id expected"); if (rt == 91) { builder_->freeze(a, input()->parseInt(0, 1, "0 or 1 expected") ? value_true : value_false); } else { builder_->unfreeze(a); } return true; } else { return parseRuleExtension(rt); } }
lcpp::Ptr<lcpp::LispObject> lcpp::Reader::read(ezStringIterator& input, bool resetSyntaxChecker) { if(resetSyntaxChecker) { m_pSyntaxCheckResult->reset(); } skipSeparators(input); if(!input.IsValid()) { return LCPP_VOID; } switch(input.GetCharacter()) { case ')': throw exceptions::InvalidInput("Unexpected character ')'."); case '\'': // TODO read quote throw exceptions::NotImplemented("Not supporting quote yet."); break; case '"': return parseString(input); break; case '(': return parseList(input); break; } return parseAtom(input); }
void LaconicaSearch::searchResultsReturned(KJob* job) { kDebug(); if( job == 0 ) { kDebug() << "job is a null pointer"; emit error( i18n( "Unable to fetch search results." ) ); return; } SearchInfo info = mSearchJobs.take(job); if( job->error() ) { kError() << "Error: " << job->errorString(); emit error( i18n( "Unable to fetch search results: %1", job->errorString() ) ); return; } KIO::StoredTransferJob *jj = qobject_cast<KIO::StoredTransferJob *>( job ); QList<Choqok::Post*> postsList; if(info.option == ReferenceHashtag) postsList = parseAtom( jj->data() ); else postsList = parseRss( jj->data() ); kDebug()<<"Emiting searchResultsReceived()"; emit searchResultsReceived( info, postsList ); }
NFA RE2NFA::parsePiece() { NFA atom = parseAtom(); if (atom.isEmpty() || !hasNext()) return atom; return parseMaybeQuantifier(atom); }
std::vector<std::string> Tokenizer::tokenize() { m_tokens.clear(); m_currentIndex = 0; m_currentToken.clear(); while (!atEnd()) { char c = get(); if (c == '\"') { parseString(); flush(); } else if (!std::isspace(c)) { parseAtom(); flush(); } advance(); } return m_tokens; }
SExpr SExpr::parseListOfAtoms(const std::vector<std::string>& atoms) { std::vector<SExpr> parsedAtoms; typedef std::vector<std::string>::const_iterator const_iterator; for(const_iterator i = atoms.begin(), i_end=atoms.end(); i != i_end; ++i){ parsedAtoms.push_back(parseAtom(*i)); } return SExpr(parsedAtoms); }
std::unique_ptr<ParseNode> parseAndExpr() // Parses AND expressions { auto left = parseAtom(); std::string str = getToken(false); if(str != "AND") // Parse the rest of the AND expression optionally return std::move(left); getToken(true); return mu<BinaryNode<std::logical_and<bool>>>(std::move(left), std::move(parseAndExpr())); }
/** * FnApp = { Atom | ( "`" Atom "`" ) } * * A series of at least one expr-atom. If multiple, then the last is a * function to which the others are applied. Instead, one of them may * be explicitly marked in backticks as the function. */ static ast* parseFnApp (parserCtx* ctx) { /*Filled iff there is a backtick function*/ ast* fn = 0; vector(ast*) nodes = vectorInit(3, malloc); /*Require at least one expr*/ if (!see(ctx, "!")) vectorPush(&nodes, parseAtom(ctx)); while (waiting_for_delim(ctx)) { if (try_match(ctx, "!")) { if (fn) { error(ctx)("Multiple explicit functions: '%s'\n", ctx->current.buffer); vectorPush(&nodes, fn); } fn = parseAtom(ctx); } else vectorPush(&nodes, parseAtom(ctx)); } if (fn) return astCreateFnApp(nodes, fn); else if (nodes.length == 0) { /*Shouldn't happen due to the way it parses*/ errprintf("FnApp took no AST nodes"); return astCreateInvalid(); } else if (nodes.length == 1) { /*No application*/ ast* node = vectorPop(&nodes); vectorFree(&nodes); return node; } else { /*The last node is the fn*/ fn = vectorPop(&nodes); return astCreateFnApp(nodes, fn); } }
bool LparseParser::parseBody(uint32 lits, uint32 neg, bool readWeights) { for (uint32 i = 0; i != lits; ++i) { active_->addToBody(parseAtom(), i >= neg, 1); } if (readWeights) { for (uint32 i = 0; i < lits; ++i) { active_->body[i].second = input()->parseInt(0, INT_MAX, "Weight Rule: bad or missing weight!"); } } return check(matchEol(*input(), true), "Illformed rule body!"); }
ParseStatus Parser::parseTuple() { skipExpected(TT_DELIMITER, DL_LPAREN); while(lex[0].type != TT_DELIMITER || lex[0].value != DL_LPAREN) { parseAtom(); // Every atom should be followed by a delimiter. if (lex[0].type != TT_DELIMITER) { assert(false); return PARSE_ERROR; } skipOptional(TT_DELIMITER, DL_COMMA); } return PARSE_OK; }
ParseStatus Parser::parseLhs() { Token t = lex[0]; if (t.type == TT_IDENTIFIER) { return parseAtom(); } /* if (t.type != TT_IDENTIFIER) { printf("X!"); return PARSE_OK; } */ return PARSE_OK; }
Expression parseTerm() { if (curchar == '!') { Expression e; match("!"); e = parseTerm(); return makeNegation(e); } if (curchar == '(') { Expression e; match("("); e = parseEquivalence(); match(")"); return e; } return parseAtom(); }
std::unique_ptr<ParseNode> parseAtom() // Parses the tightest bound stuff (NOT, ()'s and registers) { std::string token = getToken(true); if(token == "(") { auto ptr = parseExpr(); getToken(true); return ptr; } else if(token == "NOT") return mu<UnaryNode<std::logical_not<bool>>>(parseAtom()); else if(token == "TRUE") return mu<ConstNode>(true); else if(token == "FALSE") return mu<ConstNode>(false); else return mu<RegisterNode>(token[0]); }
QVariantList parseList(ParserState &st) { skipSpaces(st); checkEndOfFile(st); if (*st.ptr != '(') { throw ParserError("list must be started with '('"); } st.ptr++; QVariantList list; QString i = parseIdentifier(st); list.append(i); while (st.ptr < st.end) { if (*st.ptr == ')') { st.ptr++; return list; } parseSpace(st); if (*st.ptr == ')') { st.ptr++; return list; } if (*st.ptr == '(') { QVariant v = parseList(st); list.append(v); } else { list.append(parseAtom(st)); } } throw ParserError("unexpected end of file"); }
Token* RegxParser::parseFactor() { Token* tok = parseAtom(); switch(fState) { case REGX_T_STAR: return processStar(tok); case REGX_T_PLUS: return processPlus(tok); case REGX_T_QUESTION: return processQuestion(tok); case REGX_T_CHAR: if (fCharData == chOpenCurly && fOffset < fStringLen) { int min = 0; int max = -1; XMLInt32 ch = fString[fOffset++]; if (ch >= chDigit_0 && ch <= chDigit_9) { min = ch - chDigit_0; while (fOffset < fStringLen && (ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { min = min*10 + ch - chDigit_0; } if (min < 0) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager); } else { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier1, fString, fMemoryManager); } max = min; if (ch == chComma) { if (fOffset >= fStringLen) { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier3, fString, fMemoryManager); } else if ((ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { max = ch - chDigit_0; while (fOffset < fStringLen && (ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) { max = max*10 + ch - chDigit_0; } if (max < 0) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager); else if (min > max) ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier4, fString, fMemoryManager); } else { max = -1; } } if (ch != chCloseCurly) { ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier2, fString, fMemoryManager); } if (checkQuestion(fOffset)) { tok = fTokenFactory->createClosure(tok, true); fOffset++; } else { tok = fTokenFactory->createClosure(tok); } tok->setMin(min); tok->setMax(max); processNext(); } break; default: break; } return tok; }
void PDBFormat::PDBParser::parseBioStruct3D(BioStruct3D& biostruct, U2OpStatus& ti) { QByteArray readBuff(DocumentFormat::READ_BUFF_SIZE + 1, 0); char* buf = readBuff.data(); qint64 len = 0; bool firstCompndLine = true; while (!ti.isCoR()) { bool lineOk = true; len = io->readUntil(buf, DocumentFormat::READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include, &lineOk); if (len == 0) { break; } // there could be no terminator if this is end of file, so we have to check for this if (!lineOk && !io->isEof()) { ti.setError(U2::PDBFormat::tr("Line is too long")); return; } currentPDBLine = QString(QByteArray(buf, len)); ti.setProgress(io->getProgress() * 0.8); if (currentPDBLine.startsWith("HEADER")) { parseHeader(biostruct, ti); continue; } if (currentPDBLine.startsWith("COMPND")) { parseMacromolecularContent(firstCompndLine, ti); firstCompndLine = false; continue; } if (currentPDBLine.startsWith("SEQRES")) { parseSequence(biostruct, ti); continue; } if (currentPDBLine.startsWith("HELIX ") || currentPDBLine.startsWith("SHEET ") || currentPDBLine.startsWith("TURN ")) { parseSecondaryStructure(biostruct, ti); continue; } if (currentPDBLine.startsWith("ATOM ") || currentPDBLine.startsWith("HETATM")) { parseAtom(biostruct, ti); continue; } if (currentPDBLine.startsWith("TER")) { ++currentChainIndex; continue; } if (currentPDBLine.startsWith("SPLIT ")) { parseSplitSection(ti); continue; } if (currentPDBLine.startsWith("MODEL")) { currentChainIndex = 1; parseModel(biostruct, ti); continue; } if (currentPDBLine.startsWith("ENDMDL")) { flagMultipleModels = true; ++currentModelIndex; continue; } } CHECK_OP(ti,); if (!flagAtomRecordPresent) { ti.setError(U2::PDBFormat::tr("Some mandatory records are absent")); } updateSecStructChainIndexes(biostruct); }
int parseConfigLine(char *line, char *filename, int lineno, int set) { int x0, x1; int i, from, to; AtomPtr name, value; ConfigVariablePtr var; int iv; float fv; AtomPtr av; AtomListPtr alv; IntListPtr ilv; i = skipWhitespace(line, 0); if(line[i] == '\n' || line[i] == '\0' || line[i] == '#') return 0; x0 = i; while(letter(line[i]) || digit(line[i])) i++; x1 = i; i = skipWhitespace(line, i); if(line[i] != '=') { goto syntax; } i++; i = skipWhitespace(line, i); name = internAtomN(line + x0, x1 - x0); var = findConfigVariable(name); releaseAtom(name); if(set && var->setter == NULL) return -2; if(var == NULL) { if(!set) { do_log(L_ERROR, "%s:%d: unknown config variable ", filename, lineno); do_log_n(L_ERROR, line + x0, x1 - x0); do_log(L_ERROR, "\n"); } return -1; } i = skipWhitespace(line, i); switch(var->type) { case CONFIG_INT: case CONFIG_OCTAL: case CONFIG_HEX: i = parseInt(line, i, &iv); if(i < 0) goto syntax; if(set) var->setter(var, &iv); else *var->value.i = iv; break; case CONFIG_TIME: i = parseTime(line, i, &iv); if(i < 0) goto syntax; i = skipWhitespace(line, i); if(line[i] != '\n' && line[i] != '\0' && line[i] != '#') goto syntax; if(set) var->setter(var, &iv); else *var->value.i = iv; break; case CONFIG_BOOLEAN: case CONFIG_TRISTATE: case CONFIG_TETRASTATE: case CONFIG_PENTASTATE: iv = parseState(line, i, var->type); if(iv < 0) goto syntax; if(set) var->setter(var, &iv); else *var->value.i = iv; break; case CONFIG_FLOAT: if(!digit(line[i]) && line[i] != '.') goto syntax; fv = atof(line + i); if(set) var->setter(var, &fv); else *var->value.f = fv; break; case CONFIG_ATOM: case CONFIG_ATOM_LOWER: case CONFIG_PASSWORD: i = parseAtom(line, i, &av, (var->type == CONFIG_ATOM_LOWER)); if(i < 0) goto syntax; if(!av) { if(!set) do_log(L_ERROR, "%s:%d: couldn't allocate atom.\n", filename, lineno); return -1; } i = skipWhitespace(line, i); if(line[i] != '\n' && line[i] != '\0' && line[i] != '#') { releaseAtom(av); goto syntax; } if(set) var->setter(var, &av); else { if(*var->value.a) releaseAtom(*var->value.a); *var->value.a = av; } break; case CONFIG_INT_LIST: ilv = makeIntList(0); if(ilv == NULL) { if(!set) do_log(L_ERROR, "%s:%d: couldn't allocate int list.\n", filename, lineno); return -1; } while(1) { i = parseInt(line, i, &from); if(i < 0) goto syntax; to = from; i = skipWhitespace(line, i); if(line[i] == '-') { i = skipWhitespace(line, i + 1); i = parseInt(line, i, &to); if(i < 0) { destroyIntList(ilv); goto syntax; } i = skipWhitespace(line, i); } intListCons(from, to, ilv); if(line[i] == '\n' || line[i] == '\0' || line[i] == '#') break; if(line[i] != ',') { destroyIntList(ilv); goto syntax; } i = skipWhitespace(line, i + 1); } if(set) var->setter(var, &ilv); else { if(*var->value.il) destroyIntList(*var->value.il); *var->value.il = ilv; } break; case CONFIG_ATOM_LIST: case CONFIG_ATOM_LIST_LOWER: alv = makeAtomList(NULL, 0); if(alv == NULL) { if(!set) do_log(L_ERROR, "%s:%d: couldn't allocate atom list.\n", filename, lineno); return -1; } while(1) { i = parseAtom(line, i, &value, (var->type == CONFIG_ATOM_LIST_LOWER)); if(i < 0) goto syntax; if(!value) { if(!set) do_log(L_ERROR, "%s:%d: couldn't allocate atom.\n", filename, lineno); return -1; } atomListCons(value, alv); i = skipWhitespace(line, i); if(line[i] == '\n' || line[i] == '\0' || line[i] == '#') break; if(line[i] != ',') { destroyAtomList(alv); goto syntax; } i = skipWhitespace(line, i + 1); } if(set) var->setter(var, &alv); else { if(*var->value.al) destroyAtomList(*var->value.al); *var->value.al = alv; } break; default: abort(); } return 1; syntax: if(!set) do_log(L_ERROR, "%s:%d: parse error.\n", filename, lineno); return -1; }
void NewsSite::process(void) { QMutexLocker locker(&m_lock); m_articleList.clear(); m_errorString = ""; if (RetrieveFailed == m_state) m_errorString = tr("Retrieve Failed. ")+"\n"; QDomDocument domDoc; QFile xmlFile(m_destDir+QString("/")+m_name); if (!xmlFile.exists()) { insertNewsArticle(NewsArticle(tr("Failed to retrieve news"))); m_errorString += tr("No Cached News."); if (!m_updateErrorString.isEmpty()) m_errorString += "\n" + m_updateErrorString; return; } if (!xmlFile.open(QIODevice::ReadOnly)) { insertNewsArticle(NewsArticle(tr("Failed to retrieve news"))); LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to open xmlfile"); if (!m_updateErrorString.isEmpty()) m_errorString += "\n" + m_updateErrorString; return; } if (!domDoc.setContent(&xmlFile)) { insertNewsArticle(NewsArticle(tr("Failed to retrieve news"))); LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to set content from xmlfile"); m_errorString += tr("Failed to read downloaded file."); if (!m_updateErrorString.isEmpty()) m_errorString += "\n" + m_updateErrorString; return; } if (RetrieveFailed == m_state) { m_errorString += tr("Showing Cached News."); if (!m_updateErrorString.isEmpty()) m_errorString += "\n" + m_updateErrorString; } //Check the type of the feed QString rootName = domDoc.documentElement().nodeName(); if (rootName == "rss" || rootName == "rdf:RDF") { parseRSS(domDoc); xmlFile.close(); return; } else if (rootName == "feed") { parseAtom(domDoc); xmlFile.close(); return; } else { LOG(VB_GENERAL, LOG_ERR, LOC + "XML-file is not valid RSS-feed"); m_errorString += tr("XML-file is not valid RSS-feed"); return; } }