コード例 #1
0
inline void CSSPreloadScanner::tokenize(UChar c)
{
    // We are just interested in @import rules, no need for real tokenization here
    // Searching for other types of resources is probably low payoff.
    switch (m_state) {
    case Initial:
        if (isHTMLSpace(c))
            break;
        if (c == '@')
            m_state = RuleStart;
        else if (c == '/')
            m_state = MaybeComment;
        else
            m_state = DoneParsingImportRules;
        break;
    case MaybeComment:
        if (c == '*')
            m_state = Comment;
        else
            m_state = Initial;
        break;
    case Comment:
        if (c == '*')
            m_state = MaybeCommentEnd;
        break;
    case MaybeCommentEnd:
        if (c == '*')
            break;
        if (c == '/')
            m_state = Initial;
        else
            m_state = Comment;
        break;
    case RuleStart:
        if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
            m_rule.clear();
            m_ruleValue.clear();
            m_rule.append(c);
            m_state = Rule;
        } else
            m_state = Initial;
        break;
    case Rule:
        if (isHTMLSpace(c))
            m_state = AfterRule;
        else if (c == ';')
            m_state = Initial;
        else
            m_rule.append(c);
        break;
    case AfterRule:
        if (isHTMLSpace(c))
            break;
        if (c == ';')
            m_state = Initial;
        else if (c == '{')
            m_state = DoneParsingImportRules;
        else {
            m_state = RuleValue;
            m_ruleValue.append(c);
        }
        break;
    case RuleValue:
        if (isHTMLSpace(c))
            m_state = AfterRuleValue;
        else if (c == ';')
            emitRule();
        else
            m_ruleValue.append(c);
        break;
    case AfterRuleValue:
        if (isHTMLSpace(c))
            break;
        if (c == ';')
            emitRule();
        else if (c == '{')
            m_state = DoneParsingImportRules;
        else {
            // FIXME: media rules
            m_state = Initial;
        }
        break;
    case DoneParsingImportRules:
        ASSERT_NOT_REACHED();
        break;
    }
}
コード例 #2
0
ファイル: ZDriver.cpp プロジェクト: iangodin/lime
void
ZDriver::writeReduceFunc( std::ostream &out )
{
	size_t i, nRule;

	nRule = RuleTable::get()->getNumRules();

	emitFuncBreak( out );
	out << "void " << myPimplName << "::reduce( int ruleNum"
		<< myExtraArg << " )" << endl();
	out << "{" << endl();
	if ( isDebugOutput() )
		out << "    std::cout << \"REDUCE rule \" << ruleNum << std::endl;"
			<< endl();
	out << "    int newVal;" << endl();
	out << "    ParserAct next;" << endl();
	out << "    Util::Any data;" << endl();
	out << "    std::vector< Util::Any > rhsData;" << endl() << endl();
	out << "    rhsData.reserve( myRules[ruleNum].second );" << endl();
	out << "    for ( int i = 0, N = myRules[ruleNum].second; i != N; ++i )"
		<< endl();
	out << "    {" << endl();
	out << "        if ( myStack.empty() )" << endl()
		<< "            rhsData.insert( rhsData.begin(), data );" << endl()
		<< "        else" << endl()
		<< "        {" << endl();
	out << "            rhsData.insert( rhsData.begin(), myStack.top().second );"
		<< endl();
	out << "            myStack.pop();" << endl()
		<< "        }" << endl();
	out << "    }" << endl();

	out << endl();
    out << "    next = findParserAction( newVal, myRules[ruleNum].first );"
		<< endl();

	out << endl();
	out << "    switch ( ruleNum )" << endl();
	out << "    {" << endl();
	for ( i = 0; i < nRule; ++i )
	{
		Rule *rp = RuleTable::get()->getNthRule( i );

		out << "        case " << i << ":" << endl();
		out << "        {" << endl();
		out << "            // ";
		rp->print( out );
		out << endl();

		emitRule( rp, out );

		out << "            break;" << endl();
		out << "        }" << endl() << endl();
	}

	out << "        default:" << endl();
	out << "            throw \"Unknown Rule Number\";" << endl();
	out << "            break;" << endl();
	out << "    }" << endl();

	out << endl();
	out << "    if ( PA_SHIFT == next )" << endl();
	out << "        shift( newVal, myRules[ruleNum].first, data );" << endl();
	if ( isValueSet( "parse_accept" ) )
	{
		out << "    else" << endl();
		if ( !myExtraArgCall.empty() )
			out << "        accept( " << myExtraArgCall << " );" << endl();
		else
			out << "        accept();" << endl();
	}

	out << "}" << endl();
}