Word PresentationParser::parseRelator( const VectorOf<Chars>& names, Chars& errMesg ) { genNames = names; if ( curToken == INIT ) getToken(); if ( !atStartOfWord() ) { parseError("Expected a word here"); errMesg = parseErrorMessage; return Word(); } else { Word u = parseWord( names, errMesg ); if ( errMesg.length() > 0 ) { return Word(); } if ( curToken == EQUALS ) { getToken(); Word v = parseWord( names, errMesg ); if ( errMesg.length() > 0 ) { return Word(); } return ((Word)(u * v.inverse())).cyclicallyReduce(); } else return u.cyclicallyReduce(); } }
void ScriptPreprocessor::parseDirective(std::string & str, size_t & i) { size_t begin = i; // Skip the beginChar if (++i >= str.size()) return; std::string directive; parseWord(str, i, directive); if (directive == "if") { std::string expression; parseExpression(str, i, expression); if (!isDefined(expression)) { disableBlock(str, i); } } else { u32 lineNumber = retrieveLineNumber(str, i); SN_ERROR("Unrecognized preprocessor directive '" << directive << "' in file '" << m_fileName << "' near line " << (lineNumber + 1)); return; } }
void THtmlParser::parseCloseTag() { ++pos; skipWhiteSpace(); QString tag = parseWord(); skipUpTo(">"); // Finds corresponding open element int i = lastIndex(); while (i > 0) { if (!tag.isEmpty() && at(i).tag.toLower() == tag.toLower() && !isElementClosed(i)) { break; } i = at(i).parent; } if (i > 0) { at(i).tagClosed = true; } else { // Can't find a corresponding open element last().text += QLatin1String("</"); last().text += tag; last().text += QLatin1Char('>'); return; } // Append a empty element for next entry int p = at(i).parent; appendNewElement(p); }
SetOf<Word> PresentationParser::parseWordSet( const VectorOf<Chars>& names, Chars& errMesg ) { genNames = names; if ( curToken == INIT ) getToken(); SetOf<Word> result; if ( curToken == INIT ) getToken(); while ( atStartOfWord() ) { Word w = parseWord( names, errMesg ); if ( errMesg.length() > 0 ) { return result; } result.adjoinElement( w ); if ( curToken == COMMA ) { getToken(); if ( !atStartOfWord() ) { parseError("Expected a word here"); errMesg = parseErrorMessage; return result; } } } return result; }
static bool parseCFG(HashedSet<HashedPtr<cfg_node> > &roots, std::map<const cfg_node *, _getStoreCFGs::cfgflavour_store_t> &flavours, const char *buf, const char **suffix) { std::map<named_string, cfg_node *> nodes; while (1) { if (!parseNodeDecl(nodes, flavours, buf, &buf)) break; } if (!parseEdgeDecl(nodes, buf, &buf)) return false; if (!parseThisString("Roots:\n", buf, &buf)) return false; while (!parseThisString("End of roots\n", buf, suffix)) { if (!*buf) return false; named_string key; if (!parseWord(&key, buf, &buf) || !parseThisChar('\n', buf, &buf)) return false; if (!nodes.count(key)) return false; roots.insert(nodes[key]); } return true; }
static bool parseListEntry(ParseTreeNode* parentNode) { // Store current state for rolling back if we fail int curToken = said_token; int curTreePos = said_tree_pos; ParseTreeNode* curRightChild = parentNode->right; ParseTreeNode* newNode = said_branch_node(said_next_node(), 0, 0); bool found; if (said_tokens[said_token] == TOKEN_BRACKETO) { said_token++; found = parseExpr(newNode); if (found) { if (said_tokens[said_token] == TOKEN_BRACKETC) { said_token++; said_attach_subtree(parentNode, 0x152, 0x14c, newNode); return true; } } } else if (said_tokens[said_token] == TOKEN_PARENO) { said_token++; found = parseExpr(newNode); if (found) { if (said_tokens[said_token] == TOKEN_PARENC) { said_token++; said_attach_subtree(parentNode, 0x141, 0x14c, newNode); return true; } } } else if (parseWord(newNode)) { said_attach_subtree(parentNode, 0x141, 0x153, newNode); return true; } // Rollback said_token = curToken; said_tree_pos = curTreePos; parentNode->right = curRightChild; return false; }
SetOf<Word> PresentationParser::parseRelatorList(const VectorOf<Chars>& names,Chars& errMesg) { genNames = names; SetOf<Word> result; if ( curToken == INIT ) getToken(); while ( atStartOfWord() ) { Word u = parseWord( names, errMesg ); if ( errMesg.length() > 0 ) { return result; } if ( curToken != EQUALS ) result.adjoinElement( u.cyclicallyReduce() ); else { while ( curToken == EQUALS ) { getToken(); Word v = parseWord( names, errMesg ); if ( errMesg.length() > 0 ) { return result; } result.adjoinElement( ((Word)(u * v.inverse())).cyclicallyReduce() ); } } if ( curToken == COMMA ) { getToken(); if ( !atStartOfWord() ) { parseError("Expected a word here"); errMesg = parseErrorMessage; return result; } } } return result; }
QList<QPair<QString, QString>> THtmlParser::parseAttributes() { QList<QPair<QString, QString>> attrs; QString newline, key, value; while (pos < txt.length()) { int cr = 0, lf = 0; skipWhiteSpace(&cr, &lf); if (txt.at(pos) == QLatin1Char('>') || txt.at(pos) == QLatin1Char('/')) { break; } // Newline if (lf > 0) { newline = (lf == cr) ? QLatin1String("\r\n") : QLatin1String("\n"); attrs << qMakePair(newline, QString()); // Appends the newline as a attribute } // Appends the key-value key = parseWord(); if (key.isEmpty()) { break; } skipWhiteSpace(); if (pos < txt.length() && txt.at(pos) == QLatin1Char('=')) { pos++; skipWhiteSpace(); value = parseWord(); } else { value.clear(); } attrs << qMakePair(key, value); } return attrs; }
static bool parseEdgeDecl(std::map<named_string, cfg_node *> &nodes, const char *buf, const char **suffix) { while (1) { named_string start, end; const char *p; if (!parseWord(&start, buf, &p) || !parseThisString(" -> ", p, &p) || !parseWord(&end, p, &p) || !parseThisChar('\n', p, &buf)) break; cfg_node *s = nodes[start]; cfg_node *e = nodes[end]; if (!s || !e) return false; s->successors.push_back(cfg_node::successor_t::branch(e)); } *suffix = buf; return true; }
Text parseText(QString string, Text text) { QStringList lines = string.split("\n"); Word word; for(int j = 0; j < lines.length(); j++) { QString line = lines.at(j); if(line.length() == 0) { // ignore blank lines continue; } word = parseWord(line); if(word.getWord().length() != 0) text.addWord(word); } return text; }
void THtmlParser::parseTag() { // Close-tag if (txt.at(pos) == QLatin1Char('/')) { parseCloseTag(); return; } // p : parent index int p = lastIndex(); while (p > 0) { if (!at(p).tag.isEmpty() && !isElementClosed(p)) { break; } p = at(p).parent; } THtmlElement &he = appendNewElement(p); he.tag = parseWord(); // Parses the attributes he.attributes.clear(); if (pos < txt.length()) { he.attributes = parseAttributes(); } // Tag closed? if (txt.at(pos) == QLatin1Char('/')) { const QRegExp rx("(\\s*/[^>]*)>"); // "/>" or "//-->" int idx = rx.indexIn(txt, pos - 1); if (idx == pos || idx == pos - 1) { he.selfCloseMark = rx.cap(1); pos = idx + rx.cap(1).length(); } } if (txt.at(pos) == QLatin1Char('>')) { ++pos; } else { // coding error Q_ASSERT(0); } if (isElementClosed(lastIndex())) { appendNewElement(he.parent); } }
void engToInt() { char ch; while((ch = getchar()) != EOF) { switch (ch) { case ' ': break; default: if(isalpha(ch)) char word[20]; word[0] = ch; return parseWord(word); break; } } }
static bool parseNodeDecl(std::map<named_string, cfg_node *> &nodes, std::map<const cfg_node *, _getStoreCFGs::cfgflavour_store_t> &cfgFlavours, const char *buf, const char **suffix) { named_string label; _getStoreCFGs::cfgflavour_store_t flavour; if (!parseWord(&label, buf, &buf) || !parseThisChar(' ', buf, &buf) || !parseCfgFlavour(&flavour, buf, &buf) || !parseThisChar('\n', buf, suffix)) return false; if (nodes.count(label)) return false; cfg_node *n = new cfg_node(label, CfgLabel::uninitialised()); nodes[label] = n; cfgFlavours[n] = flavour; return true; }
void ScriptPreprocessor::disableBlock(std::string & str, size_t & i) { while (i < str.size()) { i = str.find_first_of('\n'); if (c == m_beginChar) { std::string directive; parseWord(str, i, directive); if (directive == "endif") { break; } } else if (c != '\n') { str[i] = ' '; } ++i; } }
void Connection::parse(char *buffer, ssize_t len, ev::io &w) { ssize_t buffer_pos = 0; while (buffer_pos < len) { if (!isspace(buffer[buffer_pos])) { if (lastWordLen == BUFFER_SIZE - 1) { lastWord[BUFFER_SIZE-1] = '\0'; log_file << "The word is too long: " << lastWord << buffer[buffer_pos] << std::endl; badRequest(w); return; } lastWord[lastWordLen++] = buffer[buffer_pos++]; } else { if (lastWordLen) { lastWord[lastWordLen] = '\0'; parseWord(w); } lastWordLen = 0; if (buffer[buffer_pos] == '\n') { buffer_pos++; handleLine(w); continue; } else if (buffer[buffer_pos] == '\r') { buffer_pos++; if (buffer_pos < len && buffer[buffer_pos] == '\n') { buffer_pos++; } handleLine(w); continue; } else { while (buffer_pos < len && (buffer[buffer_pos] == ' ' || buffer[buffer_pos] == '\t')) { buffer_pos++; } } } } }
void Shell::exec(bool echo, const char* prompt) { char cmd[LINE_SIZE]; while(true) { *out << prompt; for(int i=0; i<int(sizeof(cmd)-2); ++i) { *in >> cmd[i]; // \r\n if(cmd[i] == '\r' || cmd[i] == '\n') { cmd[i] = 0; break; } else if(cmd[i] == 0) { break; } //Backspace if(cmd[i] == '\b') { if(i!=0) { *out << "\b \b"; cmd[i--] = 0; } cmd[i--] = 0; //ctrl-c } else if(cmd[i] == 3) { *out << endl; *out << prompt; i = 0; //Tab } else if(cmd[i] == '\t') { *out << endl; cmd[i] = 0; i--; completion(cmd, i); *out << prompt; *out << cmd; //ctrl-d } else if(cmd[i] == 0x4) { parseWord("reset"); --i; //Escape } else if(cmd[i] == 0x1b) { *in >> cmd[i]; //Unhandled if(cmd[i] != '[') while(1); *in >> cmd[i]; if(cmd[i] == 'A') { history_pos--; if(history_pos < 0) history_pos = 3; for(i=0;history[history_pos][i];++i) { cmd[i] = history[history_pos][i]; } cmd[i]=0; *out << "\r\x1b[K"; *out << prompt; *out << cmd; } --i; } else if(echo) { *out << cmd[i]; } }
void ScriptPreprocessor::parseExpression(const std::string & str, size_t & i, std::string & out_expr) { parseWord(str, i, out_expr); }