Esempio n. 1
0
QList<KeyData> QCrmlParser::parseBit(quint32 repoUid, quint32 keyInt)
{
    QList <KeyData> rv;
    QStringList mandatoryAttributes;
    mandatoryAttributes << QLatin1String("ref");
    if (!checkMandatoryAttributes(mandatoryAttributes)) {
        rv.clear();
        return rv;
    }

    QString keyPath = attributes().value(QLatin1String("ref")).toString();
    if (!keyPath.startsWith(QLatin1Char('/')))
        keyPath.prepend(QLatin1Char('/'));

    int bitIndex = 0;
    while(!atEnd()) {
        readNext();
        if (QXmlStreamReader::error() != QXmlStreamReader::NoError) {
            setError(ParseError, QXmlStreamReader::errorString());
            rv.clear();
            return rv;
        }

        if (isEndElement() && name() == "bit")
            break;
        if(isStartElement()) {
            parseUnknownElement();
            if (error() != NoError) {
                rv.clear();
                return rv;
            }
        } else if (isCharacters()) {
            bool ok;
            QString txt = text().toString();
            if (txt.simplified().isEmpty())
                continue;
            bitIndex = txt.toInt(&ok);
            if (!ok || bitIndex <= 0) {
                //Note: binary keys have no maximum bit index
                setError(ParseError, QObject::tr("bit element has invalid text value on line %1")
                        .arg(QString::number(lineNumber())));
                rv.clear();
                return rv;
            }
        }
    }

    if (!isEndElement() && name() !="bit") {
        setError(ParseError, QObject::tr("bit element does not have end tag at line: %1")
                            .arg(QString::number(lineNumber())));
        rv.clear();
        return rv;
    }

    quint64 uid = repoUid;
    uid = uid << 32;
    uid += keyInt;
    rv.append(KeyData(keyPath,uid, m_target, bitIndex));
    return rv;
}
Esempio n. 2
0
    Entry * createEntry()
    {
        Entry * entry = new Entry();

        entry->protection = Public ;
        entry->virt       = Normal;
        entry->stat       = false;
        entry->lang       = SrcLangExt_XML;
        entry->spec       = 0;

        entry->fileName  = m_fileName;
        entry->startLine = lineNumber();
        entry->bodyLine = lineNumber();

        entry->callGraph = false;
        entry->callerGraph = false;

        initGroupInfo(entry);

        m_currentEntry = entry;

        handleComment();

        return entry;
    }
void Scanner::eatToken(token toConsume) {
    // This function consumes the next token.
    
    token foundToken = nextToken();
    
    if( foundToken == toConsume) 
      
      switch(toConsume) {
        case T_MINUS:
        case T_PLUS:
        case T_MULTIPLY:
        case T_DIVIDE:
        case T_SEMICOLON:
        case T_M:
        case T_EQUALS:
        case T_OPENPAREN:
        case T_CLOSEPAREN:
        case T_OPENBRACKET:
        case T_CLOSEBRACKET:
          std::cin.get();
          break;
        
        case T_POWER:
          std::cin.get();
          std::cin.get();
          break;
        
        case T_NUMBER:
        
        int temp;
        number = (std::cin.get() - 48);
                
        while ( isdigit(std::cin.peek()) ) { 
         temp = std::cin.get();
         temp = temp - 48;
         number = ((number * 10) + temp); 
                                 
         }          
          break;
         
         case T_PRINT:
           std::string print = "print";
           std::string cap_print = "PRINT";
           char p;
           for(int i = 0; i < 5; i++) {
             p = std::cin.get();
             if ((print[i] == p)  || (cap_print[i] == p)) continue;
             else 
               scanError(lineNumber(), p);
            }
           break;
        }
     
     else {
       mismatchError(lineNumber(), toConsume, foundToken);
       
     }
}
Esempio n. 4
0
void XmlReader::unknown()
      {
      if (QXmlStreamReader::error())
            qDebug("%s ", qPrintable(errorString()));
      if (!docName.isEmpty())
            qDebug("tag in <%s> line %lld col %lld: %s",
               qPrintable(docName), lineNumber(), columnNumber(), name().toUtf8().data());
      else
            qDebug("tag; line %lld col %lld: %s", lineNumber(), columnNumber(), name().toUtf8().data());
      skipCurrentElement();
      }
void QHelpProjectDataPrivate::readKeywords()
{
    while (!atEnd()) {
        readNext();
        if (isStartElement()) {
            if (name() == QLatin1String("keyword")) {
                if (attributes().value(QLatin1String("ref")).toString().isEmpty()
                    || (attributes().value(QLatin1String("name")).toString().isEmpty()
                    && attributes().value(QLatin1String("id")).toString().isEmpty())) {
                    qWarning("Missing attribute in keyword at line %d.", (int)lineNumber());
                    continue;
                }
                filterSectionList.last()
                    .addIndex(QHelpDataIndexItem(attributes().
                                  value(QLatin1String("name")).toString(),
                              attributes().value(QLatin1String("id")).toString(),
                              attributes().value(QLatin1String("ref")).toString()));
            } else {
                raiseUnknownTokenError();
            }
        } else if (isEndElement()) {
            if (name() == QLatin1String("keyword"))
                continue;
            else if (name() == QLatin1String("keywords"))
                break;
            else
                raiseUnknownTokenError();
        }
    }
}
Esempio n. 6
0
bool PdmlReader::read(QIODevice *device, PcapFileFormat *pcap, bool *stop)
{
    setDevice(device);
    pcap_ = pcap;
    stop_ = stop;

    while (!atEnd())
    {
        readNext();
        if (isStartElement())
        {
            if (name() == "pdml")
                readPdml();
            else
                raiseError("Not a pdml file!");
        }
    }

    if (error() && (errorString() != "USER-CANCEL"))
    {
        qDebug("Line %lld", lineNumber());
        qDebug("Col %lld", columnNumber());
        qDebug("%s", errorString().toAscii().constData());
        return false;
    }
    return true;
}
Esempio n. 7
0
    void handleComment()
    {
        if (m_currentComment == 0 || m_currentEntry == 0)
        { return; }

        QCString text(m_currentComment->text);

        m_currentEntry->docFile = m_currentComment->fileName;
        m_currentEntry->docLine = m_currentComment->line;

        int position(0);
        bool needs_entry(false);
        bool brief(false);
        Protection prot(Public);
        int lineNr = lineNumber();

        while (parseCommentBlock(m_parser,
                                 m_currentEntry,
                                 text, m_fileName.data(), 
                                 lineNr,
                                 brief, m_currentComment->isJavaStyle,
                                 false,
                                 prot,
                                 position,
                                 needs_entry))
        {
            if (needs_entry) { createEntry(); }
        }
        if (needs_entry) { createEntry(); }

        delete m_currentComment;
        m_currentComment = 0;
    }
Esempio n. 8
0
    /**
     * Get the display name and line number of the source file containing the specified address.
     * 
     * @param process               Process handle
     * @param address               Address to find
     * @param returnedSourceAndLine Returned source code file name with line number
     */
    static void getSourceFileAndLineNumber( HANDLE process,
                                            DWORD64 address,
                                            std::string* returnedSourceAndLine ) {
        IMAGEHLP_LINE64 line64;
        memset( &line64, 0, sizeof(line64) );
        line64.SizeOfStruct = sizeof(line64);
        DWORD displacement32;
        BOOL ret = SymGetLineFromAddr64( process, address, &displacement32, &line64 );
        if ( FALSE == ret ) {
            returnedSourceAndLine->clear();
            return;
        }

        std::string filename( line64.FileName );
        std::string::size_type start = filename.find( "\\src\\mongo\\" );
        if ( start == std::string::npos ) {
            start = filename.find( "\\src\\third_party\\" );
        }
        if ( start != std::string::npos ) {
            std::string shorter( "..." );
            shorter += filename.substr( start );
            filename.swap( shorter );
        }
        static const size_t bufferSize = 32;
        boost::scoped_array<char> lineNumber( new char[bufferSize] );
        _snprintf( lineNumber.get(), bufferSize, "(%u)", line64.LineNumber );
        filename += lineNumber.get();
        returnedSourceAndLine->swap( filename );
    }
Esempio n. 9
0
void TSReader::handleError()
{
    if (isComment())
        return;
    if (hasError() && error() == CustomError) // raised by readContents
        return;

    const QString loc = QString::fromLatin1("at %3:%1:%2")
        .arg(lineNumber()).arg(columnNumber()).arg(m_cd.m_sourceFileName);

    switch (tokenType()) {
    case NoToken: // Cannot happen
    default: // likewise
    case Invalid:
        raiseError(QString::fromLatin1("Parse error %1: %2").arg(loc, errorString()));
        break;
    case StartElement:
        raiseError(QString::fromLatin1("Unexpected tag <%1> %2").arg(name().toString(), loc));
        break;
    case Characters:
        {
            QString tok = text().toString();
            if (tok.length() > 30)
                tok = tok.left(30) + QLatin1String("[...]");
            raiseError(QString::fromLatin1("Unexpected characters '%1' %2").arg(tok, loc));
        }
        break;
    case EntityReference:
        raiseError(QString::fromLatin1("Unexpected entity '&%1;' %2").arg(name().toString(), loc));
        break;
    case ProcessingInstruction:
        raiseError(QString::fromLatin1("Unexpected processing instruction %1").arg(loc));
        break;
    }
}
Esempio n. 10
0
 void SDLError::outputFormattedMessage(std::ostream& os)noexcept{
   os << what()
      << " : " << sdlErrorMessage() << "\n"
      << " at " << functionName()
      << " in " << fileName()
      << " line " << lineNumber()
      << std::endl;
 }
Esempio n. 11
0
template<> bool
QConsoleWidget::_pf<bool, IsInEditorLastLine>(
        QConsoleWidget *  thisp) {
    auto doc_ = thisp->document();
    auto block_ = doc_->lastBlock();
    auto tpos = thisp->textCursor().position();
    if (block_.contains(tpos) == false) { return false; }
    auto blayout = block_.layout();
    if (blayout) {
        if (blayout->lineCount()) {
            auto line0 = blayout->lineAt(blayout->lineCount()-1);
            auto line1 = 
				blayout->lineForTextPosition(tpos - block_.position());
            return (line0.lineNumber() == line1.lineNumber());
        }
    }
    return false;
}
Esempio n. 12
0
void XmlReader::unknown()
      {
      if (QXmlStreamReader::error())
            qDebug("StreamReaderError: %s", qPrintable(errorString()));
      qDebug("%s: xml read error at line %lld col %lld: %s",
         qPrintable(docName), lineNumber(), columnNumber(),
         name().toUtf8().data());
      skipCurrentElement();
      }
Istream& ITstream::read(token& t)
{
    // Return the put back token if it exists
    if (Istream::getBack(t))
    {
        lineNumber_ = t.lineNumber();
        return *this;
    }

    if (tokenIndex_ < size())
    {
        t = operator[](tokenIndex_++);
        lineNumber_ = t.lineNumber();

        if (tokenIndex_ == size())
        {
            setEof();
        }
    }
    else
    {
        if (eof())
        {
            FatalIOErrorIn
            (
                "ITstream::read(token& t)",
                *this
            )   << "attempt to read beyond EOF"
                << exit(FatalIOError);

            setBad();
        }
        else
        {
            setEof();
        }

        if (size())
        {
            token::undefinedToken.lineNumber()
                = operator[](size() - 1).lineNumber();
        }
        else
        {
            token::undefinedToken.lineNumber() = lineNumber();
        }

        t = token::undefinedToken;
    }

    return *this;
}
Esempio n. 14
0
void Foam::IOstream::print(Ostream& os) const
{
    os  << "IOstream: " << "Version "  << version_ << ", format ";

    switch (format_)
    {
        case ASCII:
            os  << "ASCII";
        break;

        case BINARY:
            os  << "BINARY";
        break;
    }

    os  << ", line "       << lineNumber();

    if (opened())
    {
        os  << ", OPENED";
    }

    if (closed())
    {
        os  << ", CLOSED";
    }

    if (good())
    {
        os  << ", GOOD";
    }

    if (eof())
    {
        os  << ", EOF";
    }

    if (fail())
    {
        os  << ", FAIL";
    }

    if (bad())
    {
        os  << ", BAD";
    }

    os  << endl;
}
Esempio n. 15
0
		/**
		 * Returns a string representation of the event, which
		 * includes the event type, the filename and line number.
		 */
		void dump() const
		{
			Aqsis::CqString str;

			// put in the event type
			if (eventType() == AddRef)
				std::cout << "AddRef:  ";
			else if (eventType() == Release)
				std::cout << "Release: ";
			else
				assert(0 && "unknown event type reached");

			// now put in the file name and line
			std::cout << fileName() << ": " << lineNumber();
		}
Esempio n. 16
0
void XMLDocumentParser::doEnd()
{
#if ENABLE(XSLT)
    if (m_sawXSLTransform) {
        document()->setTransformSource(new TransformSource(m_originalSourceForTransform));
        document()->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
        document()->styleSelectorChanged(RecalcStyleImmediately);
        document()->setParsing(true);
        DocumentParser::stopParsing();
    }
#endif

    if (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError
        || (m_wroteText && !m_sawFirstElement && !m_sawXSLTransform && !m_sawError))
        handleError(fatal, qPrintable(m_stream.errorString()), lineNumber(), columnNumber());
}
Esempio n. 17
0
void MemcheckParser::parse()
{
    while (!atEnd()) {
        switch (readNext()) {

        case StartDocument:
            clear();
            break;

        case StartElement:
            startElement();
            break;

        case EndElement:
            endElement();
            break;

        case Characters:
            m_buffer += text().toString();
            break;

        default:
            break;
        }
    }

    if (hasError()) {
        switch (error()) {

        case CustomError:
        case UnexpectedElementError:
        case NotWellFormedError:
            KMessageBox::error(qApp->activeWindow(),
                               i18n("Valgrind XML Parsing: error at line %1, column %2: %3",
                                    lineNumber(),
                                    columnNumber(),
                                    errorString()),
                               i18n("Valgrind Error"));
            break;

        case NoError:
        case PrematureEndOfDocumentError:
            break;
        }
    }
}
void XMLDocumentParser::parseDtd()
{
    QStringRef name = m_stream.dtdName();
    QStringRef publicId = m_stream.dtdPublicId();
    QStringRef systemId = m_stream.dtdSystemId();

    //qDebug() << dtd << name << publicId << systemId;
    if ((publicId == QLatin1String("-//W3C//DTD XHTML 1.0 Transitional//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML 1.1//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML 1.0 Frameset//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML Basic 1.0//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"))
        || (publicId == QLatin1String("-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"))
#if !ENABLE(XHTMLMP)
        || (publicId == QLatin1String("-//WAPFORUM//DTD XHTML Mobile 1.0//EN"))
#endif
       )
        setIsXHTMLDocument(true); // controls if we replace entities or not.
#if ENABLE(XHTMLMP)
    else if ((publicId == QLatin1String("-//WAPFORUM//DTD XHTML Mobile 1.1//EN"))
             || (publicId == QLatin1String("-//WAPFORUM//DTD XHTML Mobile 1.0//EN"))) {
        if (AtomicString(name) != HTMLNames::htmlTag.localName()) {
            handleError(fatal, "Invalid DOCTYPE declaration, expected 'html' as root element.", lineNumber(), columnNumber());
            return;
        }

        if (document()->isXHTMLMPDocument()) // check if the MIME type is correct with this method
            setIsXHTMLMPDocument(true);
        else
            setIsXHTMLDocument(true);
    }
#endif
#if ENABLE(WML)
    else if (document()->isWMLDocument()
             && publicId != QLatin1String("-//WAPFORUM//DTD WML 1.3//EN")
             && publicId != QLatin1String("-//WAPFORUM//DTD WML 1.2//EN")
             && publicId != QLatin1String("-//WAPFORUM//DTD WML 1.1//EN")
             && publicId != QLatin1String("-//WAPFORUM//DTD WML 1.0//EN"))
        handleError(fatal, "Invalid DTD Public ID", lineNumber(), columnNumber());
#endif
    if (!m_parsingFragment)
        document()->parserAddChild(DocumentType::create(document(), name, publicId, systemId));

}
Esempio n. 19
0
/**
 * Report duplicate request use by waits.
 *
 * @param observedCall
 * @param requestVar
 * @param node
 */
void MPIBugReporter::reportDoubleWait(const CallEvent &observedCall,
                                      const RequestVar &requestVar,
                                      const ExplodedNode *const node) const {
    std::string lineNo{lineNumber(requestVar.lastUser_)};
    std::string lastUser =
        requestVar.lastUser_->getCalleeIdentifier()->getName();
    std::string errorText{"Request '" + requestVar.variableName() +
                          "' is already waited upon by '" + lastUser +
                          "' in line " + lineNo + ". "};

    auto bugReport =
        llvm::make_unique<BugReport>(*doubleWaitBugType_, errorText, node);
    bugReport->addRange(observedCall.getSourceRange());
    bugReport->addRange(requestVar.lastUser_->getSourceRange());
    SourceRange r = util::sourceRange(requestVar.memRegion_);
    if (r.isValid()) bugReport->addRange(r);
    bugReporter_.emitReport(std::move(bugReport));
}
Esempio n. 20
0
/**
 * Report a missing wait for a nonblocking call.
 *
 * @param requestVar
 * @param node
 */
void MPIBugReporter::reportMissingWait(const RequestVar &requestVar,
                                       const ExplodedNode *const node) const {
    std::string lineNo{lineNumber(requestVar.lastUser_)};
    std::string lastUser =
        requestVar.lastUser_->getCalleeIdentifier()->getName();

    std::string errorText{
        "'" + lastUser + "' in line " + lineNo + ", using request '" +
        requestVar.variableName() +
        "', has no matching wait in the scope of this function. "};

    auto bugReport =
        llvm::make_unique<BugReport>(*missingWaitBugType_, errorText, node);
    bugReport->addRange(requestVar.lastUser_->getSourceRange());
    SourceRange r = util::sourceRange(requestVar.memRegion_);
    if (r.isValid()) bugReport->addRange(r);
    bugReporter_.emitReport(std::move(bugReport));
}
Esempio n. 21
0
void QHelpProjectDataPrivate::readData(const QByteArray &contents)
{
	addData(contents);
	while (!atEnd()) {
		readNext();
		if (isStartElement()) {
			if (name() == QLatin1String("QtHelpProject") 
                && attributes().value(QLatin1String("version")) == QLatin1String("1.0"))
				readProject();
			else
                raiseError(QObject::tr("Unknown token. Expected \"QtHelpProject\"!"));
		}
	}

    if (hasError()) {
        raiseError(QObject::tr("Error in line %1: %2").arg(lineNumber())
            .arg(errorString()));
    }
}
Esempio n. 22
0
    bool comment(const QString & comment_)
    {
        if (m_currentComment)
        { handleComment(); }

        m_currentComment = new CommentData(m_fileName, lineNumber(), comment_.utf8());

        if (m_currentComment->shouldIgnore)
        {
            delete m_currentComment;
            m_currentComment = 0;
            return true;
        }

        if (m_currentComment->associateWithPrevious)
        { handleComment(); }

        return true;
    }
Esempio n. 23
0
File: main.cpp Progetto: Fale/qtmoko
void CollectionConfigReader::readData(const QByteArray &contents)
{
    m_enableFilterFunctionality = true;
    m_hideFilterFunctionality = true;
    m_enableAddressBar = true;
    m_hideAddressBar = true;
    m_enableDocumentationManager = true;

    addData(contents);
    while (!atEnd()) {
        readNext();
        if (isStartElement()) {
            if (name() == QLatin1String("QHelpCollectionProject")
                && attributes().value(QLatin1String("version")) == QLatin1String("1.0"))
                readConfig();
            else
                raiseError(QObject::tr("Unknown token at line %1. Expected \"QtHelpCollectionProject\"!")
                .arg(lineNumber()));
        }
    }
}
Esempio n. 24
0
void XMLDocumentParser::doWrite(const String& parseString)
{
    m_wroteText = true;

    if (document()->decoder() && document()->decoder()->sawError()) {
        // If the decoder saw an error, report it as fatal (stops parsing)
        handleError(fatal, "Encoding error", lineNumber(), columnNumber());
        return;
    }

    QString data(parseString);
    if (!data.isEmpty()) {
        // JavaScript may cause the parser to detach,
        // keep this alive until this function is done.
        RefPtr<XMLDocumentParser> protect(this);

        m_stream.addData(data);
        parse();
    }

    return;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
void CSymbianUnitTestOutputAsXml::PrintFailureDetailsL( 
    CSymbianUnitTestFailure& aTestFailure )
    {
    iOutputWriter->WriteL( KXmlTestNameOpenTag );
    iOutputWriter->WriteL( aTestFailure.TestName() );
    iOutputWriter->WriteL( KXmlTestNameCloseTag );
    if ( aTestFailure.FileName().Length() > 0 )
        {
        iOutputWriter->WriteL( KXmlFileNameOpenTag );
        iOutputWriter->WriteL( aTestFailure.FileName() );
        iOutputWriter->WriteL( KXmlFileNameCloseTag );
        }
    TInt lineNumber( aTestFailure.LineNumber() );
    if ( lineNumber >= 0 )
        {
        iOutputWriter->WriteL( KXmlLineNumberOpenTag, lineNumber );
        iOutputWriter->WriteL( KXmlLineNumberCloseTag );
        }
    iOutputWriter->WriteL( KXmlReasonOpenTag );
    iOutputWriter->WriteL( aTestFailure.FailureMessage() );
    iOutputWriter->WriteL( KXmlReasonCloseTag );
    }
Esempio n. 26
0
void Foam::ITstream::print(Ostream& os) const
{
    os  << "ITstream : " << name_.c_str();

    if (size())
    {
        if (begin()->lineNumber() == rbegin()->lineNumber())
        {
            os  << ", line " << begin()->lineNumber() << ", ";
        }
        else
        {
            os  << ", lines " << begin()->lineNumber()
                << '-' << rbegin()->lineNumber() << ", ";
        }
    }
    else
    {
        os  << ", line " << lineNumber() << ", ";
    }

    IOstream::print(os);
}
token Scanner::nextToken() {
    // This is a placeholder token, you will need to replace this code
    // with code to return the correct next token.
    
    char peek;
    
    while ( isspace(peek = std::cin.peek()) ) { //check to see if nextToken is whitespace
      if(peek == '\n') line_Number++;
      std::cin.get();                          //if so, consume
    }
    
    char c;
    c = std::cin.peek();
     
     switch (c) {
        case '-':
            return T_MINUS;
            
        case '+':
        	return T_PLUS;
        
        case '*':
            std::cin.get();
            char temp;
            temp = std::cin.peek();
            std::cin.putback ('*');
            
            if(temp == '*') return T_POWER;
            else 
              return T_MULTIPLY;
        
        case '/':
        	return T_DIVIDE;
        
        case ';':
        	return T_SEMICOLON;
       
        case 'M':	
        case 'm':
        	return T_M;
        	
        case '[':
        	return T_OPENBRACKET;
        	
        case ']':
        	return T_CLOSEBRACKET;
        	
        case '(':
        	return T_OPENPAREN;
        	
        case ')':
        	return T_CLOSEPAREN;
        	
        case '=':
        	return T_EQUALS;
        
        case 'P':
        case 'p':
            return T_PRINT;
        
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
             return T_NUMBER;
            
        case EOF:
            return T_EOF;
        
        default:
            scanError(lineNumber(),c);
            break;
    }
    
}
Esempio n. 28
0
Foam::Istream& Foam::UIPstream::read(token& t)
{
    // Return the put back token if it exists
    if (Istream::getBack(t))
    {
        return *this;
    }

    char c;

    // return on error
    if (!read(c))
    {
        t.setBad();
        return *this;
    }

    // Set the line number of this token to the current stream line number
    t.lineNumber() = lineNumber();

    // Analyse input starting with this character.
    switch (c)
    {
        // Punctuation
        case token::END_STATEMENT :
        case token::BEGIN_LIST :
        case token::END_LIST :
        case token::BEGIN_SQR :
        case token::END_SQR :
        case token::BEGIN_BLOCK :
        case token::END_BLOCK :
        case token::COLON :
        case token::COMMA :
        case token::ASSIGN :
        case token::ADD :
        case token::SUBTRACT :
        case token::MULTIPLY :
        case token::DIVIDE :
        {
            t = token::punctuationToken(c);
            return *this;
        }

        // Word
        case token::WORD :
        {
            word* pval = new word;
            if (read(*pval))
            {
                if (token::compound::isCompound(*pval))
                {
                    t = token::compound::New(*pval, *this).ptr();
                    delete pval;
                }
                else
                {
                    t = pval;
                }
            }
            else
            {
                delete pval;
                t.setBad();
            }
            return *this;
        }

        // String
        case token::VERBATIMSTRING :
        {
            // Recurse to read actual string
            read(t);
            t.type() = token::VERBATIMSTRING;
            return *this;
        }
        case token::VARIABLE :
        {
            // Recurse to read actual string
            read(t);
            t.type() = token::VARIABLE;
            return *this;
        }
        case token::STRING :
        {
            string* pval = new string;
            if (read(*pval))
            {
                t = pval;
                if (c == token::VERBATIMSTRING)
                {
                    t.type() = token::VERBATIMSTRING;
                }
            }
            else
            {
                delete pval;
                t.setBad();
            }
            return *this;
        }

        // Label
        case token::LABEL :
        {
            label val;
            if (read(val))
            {
                t = val;
            }
            else
            {
                t.setBad();
            }
            return *this;
        }

        // floatScalar
        case token::FLOAT_SCALAR :
        {
            floatScalar val;
            if (read(val))
            {
                t = val;
            }
            else
            {
                t.setBad();
            }
            return *this;
        }

        // doubleScalar
        case token::DOUBLE_SCALAR :
        {
            doubleScalar val;
            if (read(val))
            {
                t = val;
            }
            else
            {
                t.setBad();
            }
            return *this;
        }

        // Character (returned as a single character word) or error
        default:
        {
            if (isalpha(c))
            {
                t = word(c);
                return *this;
            }

            setBad();
            t.setBad();

            return *this;
        }
    }
}
Esempio n. 29
0
void XMLDocumentParser::parseStartElement()
{
    if (!m_sawFirstElement && m_parsingFragment) {
        // skip dummy element for fragments
        m_sawFirstElement = true;
        return;
    }

    exitText();

    String localName = m_stream.name();
    String uri       = m_stream.namespaceUri();
    String prefix    = prefixFromQName(m_stream.qualifiedName().toString());

    if (m_parsingFragment && uri.isNull()) {
        Q_ASSERT(prefix.isNull());
        uri = m_defaultNamespaceURI;
    }

    QualifiedName qName(prefix, localName, uri);
    RefPtr<Element> newElement = document()->createElement(qName, true);
    if (!newElement) {
        stopParsing();
        return;
    }

#if ENABLE(XHTMLMP)
    if (!m_sawFirstElement && isXHTMLMPDocument()) {
        // As per 7.1 section of OMA-WAP-XHTMLMP-V1_1-20061020-A.pdf,
        // we should make sure that the root element MUST be 'html' and
        // ensure the name of the default namespace on the root elment 'html'
        // MUST be 'http://www.w3.org/1999/xhtml'
        if (localName != HTMLNames::htmlTag.localName()) {
            handleError(fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber());
            return;
        }

        if (uri.isNull()) {
            m_defaultNamespaceURI = HTMLNames::xhtmlNamespaceURI;
            uri = m_defaultNamespaceURI;
            m_stream.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration(prefix, HTMLNames::xhtmlNamespaceURI));
        }
    }
#endif

    bool isFirstElement = !m_sawFirstElement;
    m_sawFirstElement = true;

    ExceptionCode ec = 0;
    handleElementNamespaces(newElement.get(), m_stream.namespaceDeclarations(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    handleElementAttributes(newElement.get(), m_stream.attributes(), ec, m_scriptingPermission);
    if (ec) {
        stopParsing();
        return;
    }

    ScriptElement* scriptElement = toScriptElement(newElement.get());
    if (scriptElement)
        m_scriptStartPosition = textPositionOneBased();

    m_currentNode->deprecatedParserAddChild(newElement.get());

    pushCurrentNode(newElement.get());
    if (m_view && !newElement->attached())
        newElement->attach();

#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    if (newElement->hasTagName(HTMLNames::htmlTag))
        static_cast<HTMLHtmlElement*>(newElement.get())->insertedByParser();
#endif

    if (isFirstElement && document()->frame())
        document()->frame()->loader()->dispatchDocumentElementAvailable();
}
Esempio n. 30
0
void XMLDocumentParser::parse()
{
    while (!isStopped() && !m_parserPaused && !m_stream.atEnd()) {
        m_stream.readNext();
        switch (m_stream.tokenType()) {
        case QXmlStreamReader::StartDocument: {
            startDocument();
        }
            break;
        case QXmlStreamReader::EndDocument: {
            endDocument();
        }
            break;
        case QXmlStreamReader::StartElement: {
#if ENABLE(XHTMLMP)
            if (document()->isXHTMLMPDocument() && !m_hasDocTypeDeclaration) {
                handleError(fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber());
                break;
            }
#endif
            parseStartElement();
        }
            break;
        case QXmlStreamReader::EndElement: {
            parseEndElement();
        }
            break;
        case QXmlStreamReader::Characters: {
            if (m_stream.isCDATA()) {
                //cdata
                parseCdata();
            } else {
                //characters
                parseCharacters();
            }
        }
            break;
        case QXmlStreamReader::Comment: {
            parseComment();
        }
            break;
        case QXmlStreamReader::DTD: {
            //qDebug()<<"------------- DTD";
            parseDtd();
#if ENABLE(XHTMLMP)
            m_hasDocTypeDeclaration = true;
#endif
        }
            break;
        case QXmlStreamReader::EntityReference: {
            //qDebug()<<"---------- ENTITY = "<<m_stream.name().toString()
            //        <<", t = "<<m_stream.text().toString();
            if (isXHTMLDocument()
#if ENABLE(XHTMLMP)
                || isXHTMLMPDocument()
#endif
               ) {
                QString entity = m_stream.name().toString();
                UChar c = decodeNamedEntity(entity.toUtf8().constData());
                if (!m_currentNode->isTextNode())
                    enterText();
                ExceptionCode ec = 0;
                String str(&c, 1);
                // qDebug()<<" ------- adding entity "<<str;
                static_cast<Text*>(m_currentNode)->appendData(str, ec);
            }
        }
            break;
        case QXmlStreamReader::ProcessingInstruction: {
            parseProcessingInstruction();
        }
            break;
        default: {
            if (m_stream.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
                ErrorType type = (m_stream.error() == QXmlStreamReader::NotWellFormedError) ?
                                 fatal : warning;
                handleError(type, qPrintable(m_stream.errorString()), lineNumber(),
                            columnNumber());
            }
        }
            break;
        }
    }
}