Esempio n. 1
0
void SAXParser::parse()
{
	_terminated = _doubleTerminated = false;
	if (!detectFIDocument())
		throw std::runtime_error("Input is not a Fast Infoset document.");
	processDocument();
}
bool HbXmlLoaderBaseSyntax::readGeneralStartItem()
{
    bool result = false;
    switch( mCurrentElementType ) {
         case HbXml::DOCUMENT:
         {
            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: DOCUMENT" );
            result = processDocument();
            break;
         }
         case HbXml::LAYOUT:
         {
            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: LAYOUT" );
            result = processLayout();

            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: SWITCHING TO LAYOUT PROCESSING MODE" );
            mElementState = ES_LAYOUT_ITEM;
            break;
         }
         case HbXml::CONTAINER:
         {
            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: CONTAINER" );
            result = processContainer();

            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: SWITCHING TO CONTAINER PROCESSING MODE" );
            mElementState = ES_CONTAINER_ITEM;
            break;
         }
         case HbXml::SECTION:
         {
            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: SECTION" );
            QString name = attribute( ATTR_NAME );
            if( name.isEmpty() ) {
                qWarning() << "Section witout a name, line " << mReader.lineNumber();
                break;
            }

            HB_DOCUMENTLOADER_PRINT( QString( "GENERAL START ITEM: LEAVING SECTION " ) + "'" + mCurrentSection.join(" ") + "'" );
            mCurrentSection << name;
            HB_DOCUMENTLOADER_PRINT( QString( "GENERAL START ITEM: ENTERING SECTION " ) + "'" + mCurrentSection.join(" ") + "'" );

            result = true;
            break;
         }
         default:
         {
            HB_DOCUMENTLOADER_PRINT( "GENERAL START ITEM: ERROR" );
            qWarning() << "Unknown element, line " << mReader.lineNumber();
            break;
         }
    }
    return result;
}
static unsigned int processDocuments( const strus::PatternMatcherInstanceInterface* ptinst, const KeyTokenMap& keytokenmap, const std::vector<TreeNode*> treear, const std::vector<strus::utils::Document>& docs, std::map<std::string,double>& stats, const char* outputpath)
{
	unsigned int totalNofmatches = 0;
	std::vector<strus::utils::Document>::const_iterator di = docs.begin(), de = docs.end();
	std::size_t didx = 0;
	for (; di != de; ++di,++didx)
	{
#ifdef STRUS_LOWLEVEL_DEBUG
		std::cout << "document " << di->tostring() << std::endl;
#endif
		std::vector<strus::analyzer::PatternMatcherResult>
			results = eliminateDuplicates( sortResults( processDocument( ptinst, *di, stats)));

		if (outputpath)
		{
			std::ostringstream out;
			out << "number of matches " << results.size() << std::endl;
			strus::utils::printResults( out, std::vector<strus::SegmenterPosition>(), results);

			std::string outputfile( outputpath);
			outputfile.push_back( strus::dirSeparator());
			outputfile.append( "res.txt");

			strus::writeFile( outputfile, out.str());
		}
		std::vector<strus::analyzer::PatternMatcherResult>
			expectedResults = eliminateDuplicates( sortResults( processDocumentAlt( keytokenmap, treear, *di)));

		if (outputpath)
		{
			std::ostringstream out;
			out << "number of matches " << expectedResults.size() << std::endl;
			strus::utils::printResults( out, std::vector<strus::SegmenterPosition>(), expectedResults);

			std::string outputfile( outputpath);
			outputfile.push_back( strus::dirSeparator());
			outputfile.append( "exp.txt");

			strus::writeFile( outputfile, out.str());
		}

		if (!compareResults( results, expectedResults))
		{
			throw std::runtime_error(std::string( "results differ to expected for document ") + di->id);
		}
		totalNofmatches += results.size();
		if (g_errorBuffer->hasError())
		{
			throw std::runtime_error("error matching rule");
		}
	}
	return totalNofmatches;
}
bool HbXmlLoaderBaseSyntax::readDocument()
{
    bool result = false;
    switch( mDocumentState ) {
        case DS_START_DOCUMENT:
        {
            HB_DOCUMENTLOADER_PRINT( "DOCUMENT_STATE START DOCUMENT" );
            if( mCurrentElementType == HbXml::DOCUMENT ) {
                result = processDocument();
                HB_DOCUMENTLOADER_PRINT( "SWITCHING TO READ SECTIONS STATE" );
                mDocumentState = DS_READ_SECTIONS;
            }
            break;
        }
        case DS_READ_SECTIONS:
        {
            if( ( mCurrentElementType == HbXml::DOCUMENT ) && ( mCurrentTokenType == QXmlStreamReader::EndElement ) ) {
                HB_DOCUMENTLOADER_PRINT( "SWITCHING TO END DOCUMENT STATE" );
                mDocumentState = DS_END_DOCUMENT;
                result = checkEndElementCorrectness();
                break;
            }

            if( ( mCurrentSection != mRequiredSection ) ) {
                HB_DOCUMENTLOADER_PRINT( "DOCUMENT_STATE READ ALIEN SECTIONS" );
                result = readAlienSection();
            } else {
                HB_DOCUMENTLOADER_PRINT( "DOCUMENT_STATE READ TARGET SECTIONS" );
                result = readTargetSection();
            }
            break;
        }
        case DS_END_DOCUMENT:
        {
            HB_DOCUMENTLOADER_PRINT( "DOCUMENT_STATE END DOCUMENT - ERROR" );
            break;
        }
    }

    return result;
}
Esempio n. 5
0
String OMLView::processHtml(shared_ptr<OMLItem> i, shared_ptr<OMLContext> context) const
{	
	if(context->checkPortalPageAvailable(i) == false) 
		return String::EMPTY;

	shared_ptr<IPortalPage> page = context->getPortalPage();
	if(page == nullptr) return String::EMPTY;

	mapDefaultParamTo(i, _S("mode"));

	String id = i->getHtmlChilds(context);

	String mode = i->getParam(_S("mode"));
	if(mode.empty())
	{
		mode = _S("row");
		i->setParam(_S("mode"), mode);
	}

	if( (mode != _S("row")) && (mode != _S("lite")) && (mode != _S("full")) )
	{
		context->addWarning(String::format(_S("%S doesn't support the mode '%S'.").c_str(), context->getFriendlyName(i).c_str(), mode.c_str()));
		return String::EMPTY;
	}

	shared_ptr<XMLDocument> doc = initDocument(i, context);
		
	XMLPortalExporter::ExportMode exportMode = (mode != _S("row")) ? XMLPortalExporter::emFull : XMLPortalExporter::emLite;
	bool withStats = (mode != _S("row"));

	shared_ptr<XMLNode> nodeUser = doc->getRoot()->addChild(_S("object"));
	shared_ptr<XMLPortalExporter> exporter(OS_NEW XMLPortalExporter(nodeUser, page, exportMode, withStats));
	shared_ptr<ObjectsIObject> object = page->getObject(id.to_ascii());
	if(object != nullptr)
	{
		object->exportXML(exporter);
	}

	return processDocument(doc, i, context);	
}
Esempio n. 6
0
void CppEditorDocument::onFilePathChanged(const Utils::FileName &oldPath,
        const Utils::FileName &newPath)
{
    Q_UNUSED(oldPath);

    if (!newPath.isEmpty()) {
        Utils::MimeDatabase mdb;
        setMimeType(mdb.mimeTypeForFile(newPath.toFileInfo()).name());

        disconnect(this, SIGNAL(contentsChanged()), this, SLOT(scheduleProcessDocument()));
        connect(this, SIGNAL(contentsChanged()), this, SLOT(scheduleProcessDocument()));

        // Un-Register/Register in ModelManager
        m_editorDocumentHandle.reset();
        m_editorDocumentHandle.reset(new CppEditorDocumentHandleImpl(this));

        resetProcessor();
        updatePreprocessorSettings();
        m_processorRevision = document()->revision();
        processDocument();
    }
}
Esempio n. 7
0
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    xmlTextReaderPtr xmlReaderP;

    pnm_init(&argc, argv);

    xmlInitParser();

    LIBXML_TEST_VERSION;

    parseCommandLine(argc, argv, &cmdline);
    
    traceDraw = cmdline.trace;

    ifP = pm_openr(cmdline.inputFileName);

    xmlReaderP = xmlReaderForFd(fileno(ifP), "SVG_IMAGE", NULL, 0);

    if (xmlReaderP) {
        processDocument(xmlReaderP, stdout);

        /* xmlTextReaderIsValid() does not appear to work.  It always says
           the document is invalid
        */

        xmlFreeTextReader(xmlReaderP);
    } else
        pm_error("Failed to create xmlReader");

    xmlCleanupParser();

    return 0;
}
void QmlJsTodoItemsScanner::documentUpdated(QmlJS::Document::Ptr doc)
{
    if (shouldProcessFile(doc->fileName()))
        processDocument(doc);
}
Esempio n. 9
0
void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc)
{
    if (shouldProcessFile(doc->fileName()))
        processDocument(doc);
}
int main( int argc, const char** argv)
{
	try
	{
		initRand();

		g_errorBuffer = strus::createErrorBuffer_standard( 0, 1, NULL/*debug trace interface*/);
		if (!g_errorBuffer)
		{
			std::cerr << "construction of error buffer failed" << std::endl;
			return -1;
		}
		else if (argc > 1)
		{
			std::cerr << "too many arguments" << std::endl;
			return 1;
		}
		unsigned int documentSize = 100;

		strus::local_ptr<strus::PatternMatcherInterface> pt( strus::createPatternMatcher_std( g_errorBuffer));
		if (!pt.get()) throw std::runtime_error("failed to create pattern matcher");
		strus::local_ptr<strus::PatternMatcherInstanceInterface> ptinst( pt->createInstance());
		if (!ptinst.get()) throw std::runtime_error("failed to create pattern matcher instance");
		createPatterns( ptinst.get(), testPatterns);
		ptinst->compile();

		if (g_errorBuffer->hasError())
		{
			throw std::runtime_error( "error creating automaton for evaluating rules");
		}
		Document doc = createDocument( 1, documentSize);
		std::cerr << "starting rule evaluation ..." << std::endl;

		// Evaluate results:
		std::vector<strus::analyzer::PatternMatcherResult> 
			results = processDocument( ptinst.get(), doc);

		// Verify results:
		std::vector<strus::analyzer::PatternMatcherResult>::const_iterator
			ri = results.begin(), re = results.end();

		typedef std::pair<std::string,unsigned int> Match;
		std::set<Match> matches;
		for (;ri != re; ++ri)
		{
			matches.insert( Match( ri->name(), ri->ordpos()));
		}
		std::set<Match>::const_iterator li = matches.begin(), le = matches.end();
		for (; li != le; ++li)
		{
			std::cout << "MATCH " << li->first << " -> " << li->second << std::endl;
		}
		unsigned int ti=0;
		for (; testPatterns[ti].name; ++ti)
		{
			unsigned int ei=0;
			for (; testPatterns[ti].results[ei]; ++ei)
			{
				std::cout << "CHECK " << ti << ": " << testPatterns[ti].name << " -> " << testPatterns[ti].results[ei] << std::endl;
				std::set<Match>::iterator
					mi = matches.find( Match( testPatterns[ti].name, testPatterns[ti].results[ei]));
				if (mi == matches.end())
				{
					char numbuf[ 64];
					::snprintf( numbuf, sizeof(numbuf), "%u", testPatterns[ti].results[ei]);
					throw std::runtime_error( std::string("expected match not found '") + testPatterns[ti].name + "' at ordpos " + numbuf);
				}
				else
				{
					matches.erase( mi);
				}
			}
		}
		if (!matches.empty())
		{
			std::set<Match>::const_iterator mi = matches.begin(), me = matches.end();
			for (; mi != me; ++mi)
			{
				std::cerr << "unexpected match of '" << mi->first << "' at ordpos " << mi->second << std::endl;
			}
			throw std::runtime_error( "more matches found than expected");
		}
		if (g_errorBuffer->hasError())
		{
			throw std::runtime_error("error matching rule");
		}
		std::cerr << "OK" << std::endl;
		delete g_errorBuffer;
		return 0;
	}
	catch (const std::runtime_error& err)
	{
		if (g_errorBuffer->hasError())
		{
			std::cerr << "error processing pattern matching: "
					<< g_errorBuffer->fetchError() << " (" << err.what()
					<< ")" << std::endl;
		}
		else
		{
			std::cerr << "error processing pattern matching: "
					<< err.what() << std::endl;
		}
	}
	catch (const std::bad_alloc&)
	{
		std::cerr << "out of memory processing pattern matching" << std::endl;
	}
	delete g_errorBuffer;
	return -1;
}