2 * Copyright 2005-2007 Adrian Thurston <thurston@complang.org>
5 /* This file is part of Ragel.
7 * Ragel is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Ragel is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Ragel; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "xmlcodegen.h"
26 #include "parsedata.h"
33 XMLCodeGen::XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm,
34 std::ostream &out, XmlParser &xmlParser )
46 void XMLCodeGen::writeActionList()
48 /* Determine which actions to write. */
50 for ( ActionList::Iter act = pd->actionList; act.lte(); act++ ) {
51 if ( act->numRefs() > 0 || act->numCondRefs > 0 )
52 act->actionId = nextActionId++;
56 out << " <action_list length=\"" << nextActionId << "\">\n";
57 for ( ActionList::Iter act = pd->actionList; act.lte(); act++ ) {
58 if ( act->actionId >= 0 )
61 out << " </action_list>\n";
64 void XMLCodeGen::writeActionTableList()
66 /* Must first order the action tables based on their id. */
67 int numTables = nextActionTableId;
68 RedActionTable **tables = new RedActionTable*[numTables];
69 for ( ActionTableMap::Iter at = actionTableMap; at.lte(); at++ )
72 out << " <action_table_list length=\"" << numTables << "\">\n";
73 for ( int t = 0; t < numTables; t++ ) {
74 out << " <action_table id=\"" << t << "\" length=\"" <<
75 tables[t]->key.length() << "\">";
76 for ( ActionTable::Iter atel = tables[t]->key; atel.lte(); atel++ ) {
77 out << atel->value->actionId;
81 out << "</action_table>\n";
83 out << " </action_table_list>\n";
88 void XMLCodeGen::reduceActionTables()
90 /* Reduce the actions tables to a set. */
91 for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
92 RedActionTable *actionTable = 0;
94 /* Reduce To State Actions. */
95 if ( st->toStateActionTable.length() > 0 ) {
96 if ( actionTableMap.insert( st->toStateActionTable, &actionTable ) )
97 actionTable->id = nextActionTableId++;
100 /* Reduce From State Actions. */
101 if ( st->fromStateActionTable.length() > 0 ) {
102 if ( actionTableMap.insert( st->fromStateActionTable, &actionTable ) )
103 actionTable->id = nextActionTableId++;
106 /* Reduce EOF actions. */
107 if ( st->eofActionTable.length() > 0 ) {
108 if ( actionTableMap.insert( st->eofActionTable, &actionTable ) )
109 actionTable->id = nextActionTableId++;
112 /* Loop the transitions and reduce their actions. */
113 for ( TransList::Iter trans = st->outList; trans.lte(); trans++ ) {
114 if ( trans->actionTable.length() > 0 ) {
115 if ( actionTableMap.insert( trans->actionTable, &actionTable ) )
116 actionTable->id = nextActionTableId++;
122 void XMLCodeGen::appendTrans( TransListVect &outList, Key lowKey,
123 Key highKey, TransAp *trans )
125 if ( trans->toState != 0 || trans->actionTable.length() > 0 )
126 outList.append( TransEl( lowKey, highKey, trans ) );
129 void XMLCodeGen::writeKey( Key key )
131 if ( keyOps->isSigned )
134 out << (unsigned long) key.getVal();
137 void XMLCodeGen::writeTrans( Key lowKey, Key highKey, TransAp *trans )
139 /* First reduce the action. */
140 RedActionTable *actionTable = 0;
141 if ( trans->actionTable.length() > 0 )
142 actionTable = actionTableMap.find( trans->actionTable );
144 /* Write the transition. */
150 if ( trans->toState != 0 )
151 out << " " << trans->toState->alg.stateNum;
155 if ( actionTable != 0 )
156 out << " " << actionTable->id;
162 void XMLCodeGen::writeTransList( StateAp *state )
164 TransListVect outList;
166 /* If there is only are no ranges the task is simple. */
167 if ( state->outList.length() > 0 ) {
168 /* Loop each source range. */
169 for ( TransList::Iter trans = state->outList; trans.lte(); trans++ ) {
170 /* Reduce the transition. If it reduced to anything then add it. */
171 appendTrans( outList, trans->lowKey, trans->highKey, trans );
175 out << " <trans_list length=\"" << outList.length() << "\">\n";
176 for ( TransListVect::Iter tvi = outList; tvi.lte(); tvi++ )
177 writeTrans( tvi->lowKey, tvi->highKey, tvi->value );
178 out << " </trans_list>\n";
181 void XMLCodeGen::writeEofTrans( StateAp *state )
183 RedActionTable *eofActions = 0;
184 if ( state->eofActionTable.length() > 0 )
185 eofActions = actionTableMap.find( state->eofActionTable );
187 /* The <eof_t> is used when there is an eof target, otherwise the eof
188 * action goes into state actions. */
189 if ( state->eofTarget != 0 ) {
190 out << " <eof_t>" << state->eofTarget->alg.stateNum;
192 if ( eofActions != 0 )
193 out << " " << eofActions->id;
197 out << "</eof_t>" << endl;
201 void XMLCodeGen::writeText( InlineItem *item )
203 if ( item->prev == 0 || item->prev->type != InlineItem::Text )
205 xmlEscapeHost( out, item->data, strlen(item->data) );
206 if ( item->next == 0 || item->next->type != InlineItem::Text )
210 void XMLCodeGen::writeGoto( InlineItem *item )
212 if ( pd->generatingSectionSubset )
213 out << "<goto>-1</goto>";
215 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
216 out << "<goto>" << targ->value->alg.stateNum << "</goto>";
220 void XMLCodeGen::writeCall( InlineItem *item )
222 if ( pd->generatingSectionSubset )
223 out << "<call>-1</call>";
225 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
226 out << "<call>" << targ->value->alg.stateNum << "</call>";
230 void XMLCodeGen::writeNext( InlineItem *item )
232 if ( pd->generatingSectionSubset )
233 out << "<next>-1</next>";
235 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
236 out << "<next>" << targ->value->alg.stateNum << "</next>";
240 void XMLCodeGen::writeGotoExpr( InlineItem *item )
242 out << "<goto_expr>";
243 writeInlineList( item->children );
244 out << "</goto_expr>";
247 void XMLCodeGen::writeCallExpr( InlineItem *item )
249 out << "<call_expr>";
250 writeInlineList( item->children );
251 out << "</call_expr>";
254 void XMLCodeGen::writeNextExpr( InlineItem *item )
256 out << "<next_expr>";
257 writeInlineList( item->children );
258 out << "</next_expr>";
261 void XMLCodeGen::writeEntry( InlineItem *item )
263 if ( pd->generatingSectionSubset )
264 out << "<entry>-1</entry>";
266 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
267 out << "<entry>" << targ->value->alg.stateNum << "</entry>";
271 void XMLCodeGen::writeActionExec( InlineItem *item )
274 writeInlineList( item->children );
278 void XMLCodeGen::writeLmOnLast( InlineItem *item )
280 out << "<set_tokend>1</set_tokend>";
282 if ( item->longestMatchPart->action != 0 ) {
283 out << "<sub_action>";
284 writeInlineList( item->longestMatchPart->action->inlineList );
285 out << "</sub_action>";
289 void XMLCodeGen::writeLmOnNext( InlineItem *item )
291 out << "<set_tokend>0</set_tokend>";
292 out << "<hold></hold>";
294 if ( item->longestMatchPart->action != 0 ) {
295 out << "<sub_action>";
296 writeInlineList( item->longestMatchPart->action->inlineList );
297 out << "</sub_action>";
301 void XMLCodeGen::writeLmOnLagBehind( InlineItem *item )
303 out << "<exec><get_tokend></get_tokend></exec>";
305 if ( item->longestMatchPart->action != 0 ) {
306 out << "<sub_action>";
307 writeInlineList( item->longestMatchPart->action->inlineList );
308 out << "</sub_action>";
312 void XMLCodeGen::writeLmSwitch( InlineItem *item )
314 LongestMatch *longestMatch = item->longestMatch;
315 out << "<lm_switch>\n";
317 /* We can't put the <exec> here because we may need to handle the error
318 * case and in that case p should not be changed. Instead use a default
319 * label in the switch to adjust p when user actions are not set. An id of
320 * -1 indicates the default. */
322 if ( longestMatch->lmSwitchHandlesError ) {
323 /* If the switch handles error then we should have also forced the
325 assert( fsm->errState != 0 );
327 out << " <sub_action id=\"0\">";
328 out << "<goto>" << fsm->errState->alg.stateNum << "</goto>";
329 out << "</sub_action>\n";
332 bool needDefault = false;
333 for ( LmPartList::Iter lmi = *longestMatch->longestMatchList; lmi.lte(); lmi++ ) {
334 if ( lmi->inLmSelect ) {
335 if ( lmi->action == 0 )
338 /* Open the action. Write it with the context that sets up _p
339 * when doing control flow changes from inside the machine. */
340 out << " <sub_action id=\"" << lmi->longestMatchId << "\">";
341 out << "<exec><get_tokend></get_tokend></exec>";
342 writeInlineList( lmi->action->inlineList );
343 out << "</sub_action>\n";
349 out << " <sub_action id=\"-1\"><exec><get_tokend>"
350 "</get_tokend></exec></sub_action>\n";
353 out << " </lm_switch>";
356 void XMLCodeGen::writeInlineList( InlineList *inlineList )
358 for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) {
359 switch ( item->type ) {
360 case InlineItem::Text:
363 case InlineItem::Goto:
366 case InlineItem::GotoExpr:
367 writeGotoExpr( item );
369 case InlineItem::Call:
372 case InlineItem::CallExpr:
373 writeCallExpr( item );
375 case InlineItem::Next:
378 case InlineItem::NextExpr:
379 writeNextExpr( item );
381 case InlineItem::Break:
382 out << "<break></break>";
384 case InlineItem::Ret:
385 out << "<ret></ret>";
387 case InlineItem::PChar:
388 out << "<pchar></pchar>";
390 case InlineItem::Char:
391 out << "<char></char>";
393 case InlineItem::Curs:
394 out << "<curs></curs>";
396 case InlineItem::Targs:
397 out << "<targs></targs>";
399 case InlineItem::Entry:
403 case InlineItem::Hold:
404 out << "<hold></hold>";
406 case InlineItem::Exec:
407 writeActionExec( item );
410 case InlineItem::LmSetActId:
411 out << "<set_act>" <<
412 item->longestMatchPart->longestMatchId <<
415 case InlineItem::LmSetTokEnd:
416 out << "<set_tokend>1</set_tokend>";
419 case InlineItem::LmOnLast:
420 writeLmOnLast( item );
422 case InlineItem::LmOnNext:
423 writeLmOnNext( item );
425 case InlineItem::LmOnLagBehind:
426 writeLmOnLagBehind( item );
428 case InlineItem::LmSwitch:
429 writeLmSwitch( item );
432 case InlineItem::LmInitAct:
433 out << "<init_act></init_act>";
435 case InlineItem::LmInitTokStart:
436 out << "<init_tokstart></init_tokstart>";
438 case InlineItem::LmSetTokStart:
439 out << "<set_tokstart></set_tokstart>";
445 void XMLCodeGen::makeKey( GenInlineList *outList, Key key )
449 void XMLCodeGen::makeText( GenInlineList *outList, InlineItem *item )
451 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Text );
452 inlineItem->data = item->data;
454 outList->append( inlineItem );
457 void XMLCodeGen::makeTargetItem( GenInlineList *outList, InlineItem *item, GenInlineItem::Type type )
460 if ( pd->generatingSectionSubset )
463 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
464 targetState = targ->value->alg.stateNum;
468 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), type );
469 inlineItem->targId = targetState;
470 outList->append( inlineItem );
473 /* Make a sublist item with a given type. */
474 void XMLCodeGen::makeSubList( GenInlineList *outList,
475 InlineList *inlineList, GenInlineItem::Type type )
477 /* Fill the sub list. */
478 GenInlineList *subList = new GenInlineList;
479 makeGenInlineList( subList, inlineList );
482 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), type );
483 inlineItem->children = subList;
484 outList->append( inlineItem );
487 void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item )
489 makeSetTokend( outList, 1 );
491 if ( item->longestMatchPart->action != 0 ) {
492 makeSubList( outList,
493 item->longestMatchPart->action->inlineList,
494 GenInlineItem::SubAction );
498 void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item )
500 makeSetTokend( outList, 0 );
501 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ) );
503 if ( item->longestMatchPart->action != 0 ) {
504 makeSubList( outList,
505 item->longestMatchPart->action->inlineList,
506 GenInlineItem::SubAction );
510 void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item )
512 /* Make the sublist containing a just get_tokend. */
513 GenInlineItem *getTokend = new GenInlineItem( GenInputLoc(), GenInlineItem::LmGetTokEnd );
514 GenInlineList *subList = new GenInlineList;
515 subList->append( getTokend );
517 /* Make the Exec item. */
518 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Exec );
519 inlineItem->children = subList;
520 outList->append( inlineItem );
522 if ( item->longestMatchPart->action != 0 ) {
523 makeSubList( outList,
524 item->longestMatchPart->action->inlineList,
525 GenInlineItem::SubAction );
530 void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item )
534 void XMLCodeGen::makeSetTokend( GenInlineList *outList, long offset )
536 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokEnd );
537 inlineItem->offset = offset;
538 outList->append( inlineItem );
541 void XMLCodeGen::makeSetAct( GenInlineList *outList, long lmId )
543 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetActId );
544 inlineItem->lmId = lmId;
545 outList->append( inlineItem );
548 void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList )
550 for ( InlineList::Iter item = *inList; item.lte(); item++ ) {
551 switch ( item->type ) {
552 case InlineItem::Text:
553 makeText( outList, item );
555 case InlineItem::Goto:
556 makeTargetItem( outList, item, GenInlineItem::Goto );
558 case InlineItem::GotoExpr:
559 makeSubList( outList, item->children, GenInlineItem::GotoExpr );
561 case InlineItem::Call:
562 makeTargetItem( outList, item, GenInlineItem::Call );
564 case InlineItem::CallExpr:
565 makeSubList( outList, item->children, GenInlineItem::CallExpr );
567 case InlineItem::Next:
568 makeTargetItem( outList, item, GenInlineItem::Next );
570 case InlineItem::NextExpr:
571 makeSubList( outList, item->children, GenInlineItem::NextExpr );
573 case InlineItem::Break:
574 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Break ) );
576 case InlineItem::Ret:
577 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Ret ) );
579 case InlineItem::PChar:
580 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::PChar ) );
582 case InlineItem::Char:
583 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Char ) );
585 case InlineItem::Curs:
586 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Curs ) );
588 case InlineItem::Targs:
589 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Targs ) );
591 case InlineItem::Entry:
592 makeTargetItem( outList, item, GenInlineItem::Entry );
595 case InlineItem::Hold:
596 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::Hold ) );
598 case InlineItem::Exec:
599 makeSubList( outList, item->children, GenInlineItem::Exec );
602 case InlineItem::LmSetActId:
603 makeSetAct( outList, item->longestMatchPart->longestMatchId );
605 case InlineItem::LmSetTokEnd:
606 makeSetTokend( outList, 1 );
609 case InlineItem::LmOnLast:
610 makeLmOnLast( outList, item );
612 case InlineItem::LmOnNext:
613 makeLmOnNext( outList, item );
615 case InlineItem::LmOnLagBehind:
616 makeLmOnLagBehind( outList, item );
618 case InlineItem::LmSwitch:
619 makeLmSwitch( outList, item );
622 case InlineItem::LmInitAct:
623 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitAct ) );
625 case InlineItem::LmInitTokStart:
626 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmInitTokStart ) );
628 case InlineItem::LmSetTokStart:
629 outList->append( new GenInlineItem( GenInputLoc(), GenInlineItem::LmSetTokStart ) );
630 xmlParser.cgd->hasLongestMatch = true;
637 void XMLCodeGen::writeAction( Action *action )
639 out << " <action id=\"" << action->actionId << "\"";
640 if ( action->name != 0 )
641 out << " name=\"" << action->name << "\"";
642 out << " line=\"" << action->loc.line << "\" col=\"" << action->loc.col << "\">";
643 writeInlineList( action->inlineList );
644 out << "</action>\n";
647 void xmlEscapeHost( std::ostream &out, char *data, long len )
649 char *end = data + len;
650 while ( data != end ) {
652 case '<': out << "<"; break;
653 case '>': out << ">"; break;
654 case '&': out << "&"; break;
655 default: out << *data; break;
661 void XMLCodeGen::writeStateActions( StateAp *state )
663 RedActionTable *toStateActions = 0;
664 if ( state->toStateActionTable.length() > 0 )
665 toStateActions = actionTableMap.find( state->toStateActionTable );
667 RedActionTable *fromStateActions = 0;
668 if ( state->fromStateActionTable.length() > 0 )
669 fromStateActions = actionTableMap.find( state->fromStateActionTable );
671 /* EOF actions go out here only if the state has no eof target. If it has
672 * an eof target then an eof transition will be used instead. */
673 RedActionTable *eofActions = 0;
674 if ( state->eofTarget == 0 && state->eofActionTable.length() > 0 )
675 eofActions = actionTableMap.find( state->eofActionTable );
677 if ( toStateActions != 0 || fromStateActions != 0 || eofActions != 0 ) {
678 out << " <state_actions>";
679 if ( toStateActions != 0 )
680 out << toStateActions->id;
684 if ( fromStateActions != 0 )
685 out << " " << fromStateActions->id;
689 if ( eofActions != 0 )
690 out << " " << eofActions->id;
694 out << "</state_actions>\n";
698 void XMLCodeGen::writeStateConditions( StateAp *state )
700 if ( state->stateCondList.length() > 0 ) {
701 out << " <cond_list length=\"" << state->stateCondList.length() << "\">\n";
702 for ( StateCondList::Iter scdi = state->stateCondList; scdi.lte(); scdi++ ) {
704 writeKey( scdi->lowKey );
706 writeKey( scdi->highKey );
708 out << scdi->condSpace->condSpaceId;
711 out << " </cond_list>\n";
715 void XMLCodeGen::writeStateList()
717 /* Write the list of states. */
718 out << " <state_list length=\"" << fsm->stateList.length() << "\">\n";
719 for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
720 out << " <state id=\"" << st->alg.stateNum << "\"";
721 if ( st->isFinState() )
722 out << " final=\"t\"";
725 writeStateActions( st );
727 writeStateConditions( st );
728 writeTransList( st );
730 out << " </state>\n";
735 out << " </state_list>\n";
738 bool XMLCodeGen::writeNameInst( NameInst *nameInst )
740 bool written = false;
741 if ( nameInst->parent != 0 )
742 written = writeNameInst( nameInst->parent );
744 if ( nameInst->name != 0 ) {
747 out << nameInst->name;
754 void XMLCodeGen::writeEntryPoints()
756 /* List of entry points other than start state. */
757 if ( fsm->entryPoints.length() > 0 || pd->lmRequiresErrorState ) {
758 out << " <entry_points";
759 if ( pd->lmRequiresErrorState )
760 out << " error=\"t\"";
762 for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
763 /* Get the name instantiation from nameIndex. */
764 NameInst *nameInst = pd->nameIndex[en->key];
765 StateAp *state = en->value;
766 out << " <entry name=\"";
767 writeNameInst( nameInst );
768 out << "\">" << state->alg.stateNum << "</entry>\n";
770 out << " </entry_points>\n";
774 void XMLCodeGen::writeMachine()
776 /* Open the machine. */
777 out << " <machine>\n";
780 reduceActionTables();
783 writeActionTableList();
787 out << " <start_state>" << fsm->startState->alg.stateNum <<
791 if ( fsm->errState != 0 ) {
792 out << " <error_state>" << fsm->errState->alg.stateNum <<
799 out << " </machine>\n";
803 void XMLCodeGen::writeConditions()
805 if ( condData->condSpaceMap.length() > 0 ) {
806 long nextCondSpaceId = 0;
807 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ )
808 cs->condSpaceId = nextCondSpaceId++;
810 out << " <cond_space_list length=\"" << condData->condSpaceMap.length() << "\">\n";
811 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ ) {
812 out << " <cond_space id=\"" << cs->condSpaceId <<
813 "\" length=\"" << cs->condSet.length() << "\">";
814 writeKey( cs->baseKey );
815 for ( CondSet::Iter csi = cs->condSet; csi.lte(); csi++ )
816 out << " " << (*csi)->actionId;
817 out << "</cond_space>\n";
819 out << " </cond_space_list>\n";
823 void XMLCodeGen::writeExports()
825 if ( pd->exportList.length() > 0 ) {
826 out << " <exports>\n";
827 for ( ExportList::Iter exp = pd->exportList; exp.lte(); exp++ ) {
828 out << " <ex name=\"" << exp->name << "\">";
829 writeKey( exp->key );
832 out << " </exports>\n";
836 void XMLCodeGen::writeXML()
838 /* Open the definition. */
839 out << "<ragel_def name=\"" << fsmName << "\">\n";
842 out << " <alphtype>" << keyOps->alphType->internalName << "</alphtype>\n";
844 /* Getkey expression. */
845 if ( pd->getKeyExpr != 0 ) {
847 writeInlineList( pd->getKeyExpr );
848 out << "</getkey>\n";
851 /* Access expression. */
852 if ( pd->accessExpr != 0 ) {
854 writeInlineList( pd->accessExpr );
855 out << "</access>\n";
858 /* PrePush expression. */
859 if ( pd->prePushExpr != 0 ) {
861 writeInlineList( pd->prePushExpr );
862 out << "</prepush>\n";
865 /* PostPop expression. */
866 if ( pd->postPopExpr != 0 ) {
868 writeInlineList( pd->postPopExpr );
869 out << "</postpop>\n";
873 * Variable expressions.
876 if ( pd->pExpr != 0 ) {
878 writeInlineList( pd->pExpr );
879 out << "</p_expr>\n";
882 if ( pd->peExpr != 0 ) {
884 writeInlineList( pd->peExpr );
885 out << "</pe_expr>\n";
888 if ( pd->eofExpr != 0 ) {
889 out << " <eof_expr>";
890 writeInlineList( pd->eofExpr );
891 out << "</eof_expr>\n";
894 if ( pd->csExpr != 0 ) {
896 writeInlineList( pd->csExpr );
897 out << "</cs_expr>\n";
900 if ( pd->topExpr != 0 ) {
901 out << " <top_expr>";
902 writeInlineList( pd->topExpr );
903 out << "</top_expr>\n";
906 if ( pd->stackExpr != 0 ) {
907 out << " <stack_expr>";
908 writeInlineList( pd->stackExpr );
909 out << "</stack_expr>\n";
912 if ( pd->actExpr != 0 ) {
913 out << " <act_expr>";
914 writeInlineList( pd->actExpr );
915 out << "</act_expr>\n";
918 if ( pd->tokstartExpr != 0 ) {
919 out << " <tokstart_expr>";
920 writeInlineList( pd->tokstartExpr );
921 out << "</tokstart_expr>\n";
924 if ( pd->tokendExpr != 0 ) {
925 out << " <tokend_expr>";
926 writeInlineList( pd->tokendExpr );
927 out << "</tokend_expr>\n";
930 if ( pd->dataExpr != 0 ) {
931 out << " <data_expr>";
932 writeInlineList( pd->dataExpr );
933 out << "</data_expr>\n";
944 void XMLCodeGen::makeBackend()
946 /* Open the definition. */
947 xmlParser.open_ragel_def( fsmName );
950 xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
952 /* Getkey expression. */
953 if ( pd->getKeyExpr != 0 ) {
955 writeInlineList( pd->getKeyExpr );
956 out << "</getkey>\n";
959 /* Access expression. */
960 if ( pd->accessExpr != 0 ) {
962 writeInlineList( pd->accessExpr );
963 out << "</access>\n";
966 /* PrePush expression. */
967 if ( pd->prePushExpr != 0 ) {
969 writeInlineList( pd->prePushExpr );
970 out << "</prepush>\n";
973 /* PostPop expression. */
974 if ( pd->postPopExpr != 0 ) {
976 writeInlineList( pd->postPopExpr );
977 out << "</postpop>\n";
981 * Variable expressions.
984 if ( pd->pExpr != 0 ) {
986 writeInlineList( pd->pExpr );
987 out << "</p_expr>\n";
990 if ( pd->peExpr != 0 ) {
992 writeInlineList( pd->peExpr );
993 out << "</pe_expr>\n";
996 if ( pd->eofExpr != 0 ) {
997 out << " <eof_expr>";
998 writeInlineList( pd->eofExpr );
999 out << "</eof_expr>\n";
1002 if ( pd->csExpr != 0 ) {
1003 out << " <cs_expr>";
1004 writeInlineList( pd->csExpr );
1005 out << "</cs_expr>\n";
1008 if ( pd->topExpr != 0 ) {
1009 out << " <top_expr>";
1010 writeInlineList( pd->topExpr );
1011 out << "</top_expr>\n";
1014 if ( pd->stackExpr != 0 ) {
1015 out << " <stack_expr>";
1016 writeInlineList( pd->stackExpr );
1017 out << "</stack_expr>\n";
1020 if ( pd->actExpr != 0 ) {
1021 out << " <act_expr>";
1022 writeInlineList( pd->actExpr );
1023 out << "</act_expr>\n";
1026 if ( pd->tokstartExpr != 0 ) {
1027 out << " <tokstart_expr>";
1028 writeInlineList( pd->tokstartExpr );
1029 out << "</tokstart_expr>\n";
1032 if ( pd->tokendExpr != 0 ) {
1033 out << " <tokend_expr>";
1034 writeInlineList( pd->tokendExpr );
1035 out << "</tokend_expr>\n";
1038 if ( pd->dataExpr != 0 ) {
1039 out << " <data_expr>";
1040 writeInlineList( pd->dataExpr );
1041 out << "</data_expr>\n";