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::makeGoto( GenInlineList *outList, InlineItem *item )
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(), GenInlineItem::Goto );
469 inlineItem->targId = targetState;
470 outList->append( inlineItem );
473 void XMLCodeGen::makeGotoExpr( GenInlineList *outList, InlineItem *item )
475 /* Fill the sub list. */
476 GenInlineList *subList = new GenInlineList;
477 makeGenInlineList( subList, item->children );
480 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::GotoExpr );
481 inlineItem->children = subList;
482 outList->append( inlineItem );
485 void XMLCodeGen::makeCall( GenInlineList *outList, InlineItem *item )
488 if ( pd->generatingSectionSubset )
491 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
492 targetState = targ->value->alg.stateNum;
495 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Call );
496 inlineItem->targId = targetState;
497 outList->append( inlineItem );
500 void XMLCodeGen::makeCallExpr( GenInlineList *outList, InlineItem *item )
502 /* Fill the sub list. */
503 GenInlineList *subList = new GenInlineList;
504 makeGenInlineList( subList, item->children );
507 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::CallExpr );
508 inlineItem->children = subList;
509 outList->append( inlineItem );
512 void XMLCodeGen::makeNext( GenInlineList *outList, InlineItem *item )
515 if ( pd->generatingSectionSubset )
518 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
519 targetState = targ->value->alg.stateNum;
522 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Next );
523 inlineItem->targId = targetState;
526 void XMLCodeGen::makeNextExpr( GenInlineList *outList, InlineItem *item )
528 /* Fill the sub list. */
529 GenInlineList *subList = new GenInlineList;
530 makeGenInlineList( subList, item->children );
533 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::NextExpr );
534 inlineItem->children = subList;
535 outList->append( inlineItem );
538 void XMLCodeGen::makeEntry( GenInlineList *outList, InlineItem *item )
541 if ( pd->generatingSectionSubset )
544 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
545 entryState = targ->value->alg.stateNum;
548 GenInlineItem *inlineItem = new GenInlineItem( GenInputLoc(), GenInlineItem::Entry );
549 inlineItem->targId = entryState;
552 void XMLCodeGen::makeLmSetActId( GenInlineList *outList, InlineItem *item )
556 void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item )
560 void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item )
564 void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item )
568 void XMLCodeGen::makeActionExec( GenInlineList *outList, InlineItem *item )
572 void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item )
576 void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList )
578 for ( InlineList::Iter item = *inList; item.lte(); item++ ) {
579 switch ( item->type ) {
580 case InlineItem::Text:
581 makeText( outList, item );
583 case InlineItem::Goto:
584 makeGoto( outList, item );
586 case InlineItem::GotoExpr:
587 makeGotoExpr( outList, item );
589 case InlineItem::Call:
590 makeCall( outList, item );
592 case InlineItem::CallExpr:
593 makeCallExpr( outList, item );
595 case InlineItem::Next:
596 makeNext( outList, item );
598 case InlineItem::NextExpr:
599 makeNextExpr( outList, item );
601 case InlineItem::Break:
602 out << "<break></break>";
604 case InlineItem::Ret:
605 out << "<ret></ret>";
607 case InlineItem::PChar:
608 out << "<pchar></pchar>";
610 case InlineItem::Char:
611 out << "<char></char>";
613 case InlineItem::Curs:
614 out << "<curs></curs>";
616 case InlineItem::Targs:
617 out << "<targs></targs>";
619 case InlineItem::Entry:
620 makeEntry( outList, item );
623 case InlineItem::Hold:
624 out << "<hold></hold>";
626 case InlineItem::Exec:
627 makeActionExec( outList, item );
630 case InlineItem::LmSetActId:
631 out << "<set_act>" <<
632 item->longestMatchPart->longestMatchId <<
635 case InlineItem::LmSetTokEnd:
636 out << "<set_tokend>1</set_tokend>";
639 case InlineItem::LmOnLast:
640 makeLmOnLast( outList, item );
642 case InlineItem::LmOnNext:
643 makeLmOnNext( outList, item );
645 case InlineItem::LmOnLagBehind:
646 makeLmOnLagBehind( outList, item );
648 case InlineItem::LmSwitch:
649 makeLmSwitch( outList, item );
652 case InlineItem::LmInitAct:
653 out << "<init_act></init_act>";
655 case InlineItem::LmInitTokStart:
656 out << "<init_tokstart></init_tokstart>";
658 case InlineItem::LmSetTokStart:
659 out << "<set_tokstart></set_tokstart>";
666 void XMLCodeGen::writeAction( Action *action )
668 out << " <action id=\"" << action->actionId << "\"";
669 if ( action->name != 0 )
670 out << " name=\"" << action->name << "\"";
671 out << " line=\"" << action->loc.line << "\" col=\"" << action->loc.col << "\">";
672 writeInlineList( action->inlineList );
673 out << "</action>\n";
676 void xmlEscapeHost( std::ostream &out, char *data, long len )
678 char *end = data + len;
679 while ( data != end ) {
681 case '<': out << "<"; break;
682 case '>': out << ">"; break;
683 case '&': out << "&"; break;
684 default: out << *data; break;
690 void XMLCodeGen::writeStateActions( StateAp *state )
692 RedActionTable *toStateActions = 0;
693 if ( state->toStateActionTable.length() > 0 )
694 toStateActions = actionTableMap.find( state->toStateActionTable );
696 RedActionTable *fromStateActions = 0;
697 if ( state->fromStateActionTable.length() > 0 )
698 fromStateActions = actionTableMap.find( state->fromStateActionTable );
700 /* EOF actions go out here only if the state has no eof target. If it has
701 * an eof target then an eof transition will be used instead. */
702 RedActionTable *eofActions = 0;
703 if ( state->eofTarget == 0 && state->eofActionTable.length() > 0 )
704 eofActions = actionTableMap.find( state->eofActionTable );
706 if ( toStateActions != 0 || fromStateActions != 0 || eofActions != 0 ) {
707 out << " <state_actions>";
708 if ( toStateActions != 0 )
709 out << toStateActions->id;
713 if ( fromStateActions != 0 )
714 out << " " << fromStateActions->id;
718 if ( eofActions != 0 )
719 out << " " << eofActions->id;
723 out << "</state_actions>\n";
727 void XMLCodeGen::writeStateConditions( StateAp *state )
729 if ( state->stateCondList.length() > 0 ) {
730 out << " <cond_list length=\"" << state->stateCondList.length() << "\">\n";
731 for ( StateCondList::Iter scdi = state->stateCondList; scdi.lte(); scdi++ ) {
733 writeKey( scdi->lowKey );
735 writeKey( scdi->highKey );
737 out << scdi->condSpace->condSpaceId;
740 out << " </cond_list>\n";
744 void XMLCodeGen::writeStateList()
746 /* Write the list of states. */
747 out << " <state_list length=\"" << fsm->stateList.length() << "\">\n";
748 for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
749 out << " <state id=\"" << st->alg.stateNum << "\"";
750 if ( st->isFinState() )
751 out << " final=\"t\"";
754 writeStateActions( st );
756 writeStateConditions( st );
757 writeTransList( st );
759 out << " </state>\n";
764 out << " </state_list>\n";
767 bool XMLCodeGen::writeNameInst( NameInst *nameInst )
769 bool written = false;
770 if ( nameInst->parent != 0 )
771 written = writeNameInst( nameInst->parent );
773 if ( nameInst->name != 0 ) {
776 out << nameInst->name;
783 void XMLCodeGen::writeEntryPoints()
785 /* List of entry points other than start state. */
786 if ( fsm->entryPoints.length() > 0 || pd->lmRequiresErrorState ) {
787 out << " <entry_points";
788 if ( pd->lmRequiresErrorState )
789 out << " error=\"t\"";
791 for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
792 /* Get the name instantiation from nameIndex. */
793 NameInst *nameInst = pd->nameIndex[en->key];
794 StateAp *state = en->value;
795 out << " <entry name=\"";
796 writeNameInst( nameInst );
797 out << "\">" << state->alg.stateNum << "</entry>\n";
799 out << " </entry_points>\n";
803 void XMLCodeGen::writeMachine()
805 /* Open the machine. */
806 out << " <machine>\n";
809 reduceActionTables();
812 writeActionTableList();
816 out << " <start_state>" << fsm->startState->alg.stateNum <<
820 if ( fsm->errState != 0 ) {
821 out << " <error_state>" << fsm->errState->alg.stateNum <<
828 out << " </machine>\n";
832 void XMLCodeGen::writeConditions()
834 if ( condData->condSpaceMap.length() > 0 ) {
835 long nextCondSpaceId = 0;
836 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ )
837 cs->condSpaceId = nextCondSpaceId++;
839 out << " <cond_space_list length=\"" << condData->condSpaceMap.length() << "\">\n";
840 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ ) {
841 out << " <cond_space id=\"" << cs->condSpaceId <<
842 "\" length=\"" << cs->condSet.length() << "\">";
843 writeKey( cs->baseKey );
844 for ( CondSet::Iter csi = cs->condSet; csi.lte(); csi++ )
845 out << " " << (*csi)->actionId;
846 out << "</cond_space>\n";
848 out << " </cond_space_list>\n";
852 void XMLCodeGen::writeExports()
854 if ( pd->exportList.length() > 0 ) {
855 out << " <exports>\n";
856 for ( ExportList::Iter exp = pd->exportList; exp.lte(); exp++ ) {
857 out << " <ex name=\"" << exp->name << "\">";
858 writeKey( exp->key );
861 out << " </exports>\n";
865 void XMLCodeGen::writeXML()
867 /* Open the definition. */
868 xmlParser.open_ragel_def( fsmName );
871 xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
873 /* Getkey expression. */
874 if ( pd->getKeyExpr != 0 ) {
876 writeInlineList( pd->getKeyExpr );
877 out << "</getkey>\n";
880 /* Access expression. */
881 if ( pd->accessExpr != 0 ) {
883 writeInlineList( pd->accessExpr );
884 out << "</access>\n";
887 /* PrePush expression. */
888 if ( pd->prePushExpr != 0 ) {
890 writeInlineList( pd->prePushExpr );
891 out << "</prepush>\n";
894 /* PostPop expression. */
895 if ( pd->postPopExpr != 0 ) {
897 writeInlineList( pd->postPopExpr );
898 out << "</postpop>\n";
902 * Variable expressions.
905 if ( pd->pExpr != 0 ) {
907 writeInlineList( pd->pExpr );
908 out << "</p_expr>\n";
911 if ( pd->peExpr != 0 ) {
913 writeInlineList( pd->peExpr );
914 out << "</pe_expr>\n";
917 if ( pd->eofExpr != 0 ) {
918 out << " <eof_expr>";
919 writeInlineList( pd->eofExpr );
920 out << "</eof_expr>\n";
923 if ( pd->csExpr != 0 ) {
925 writeInlineList( pd->csExpr );
926 out << "</cs_expr>\n";
929 if ( pd->topExpr != 0 ) {
930 out << " <top_expr>";
931 writeInlineList( pd->topExpr );
932 out << "</top_expr>\n";
935 if ( pd->stackExpr != 0 ) {
936 out << " <stack_expr>";
937 writeInlineList( pd->stackExpr );
938 out << "</stack_expr>\n";
941 if ( pd->actExpr != 0 ) {
942 out << " <act_expr>";
943 writeInlineList( pd->actExpr );
944 out << "</act_expr>\n";
947 if ( pd->tokstartExpr != 0 ) {
948 out << " <tokstart_expr>";
949 writeInlineList( pd->tokstartExpr );
950 out << "</tokstart_expr>\n";
953 if ( pd->tokendExpr != 0 ) {
954 out << " <tokend_expr>";
955 writeInlineList( pd->tokendExpr );
956 out << "</tokend_expr>\n";
959 if ( pd->dataExpr != 0 ) {
960 out << " <data_expr>";
961 writeInlineList( pd->dataExpr );
962 out << "</data_expr>\n";
973 void XMLCodeGen::makeBackend()
975 /* Open the definition. */
976 xmlParser.open_ragel_def( fsmName );
979 xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
981 /* Getkey expression. */
982 if ( pd->getKeyExpr != 0 ) {
984 writeInlineList( pd->getKeyExpr );
985 out << "</getkey>\n";
988 /* Access expression. */
989 if ( pd->accessExpr != 0 ) {
991 writeInlineList( pd->accessExpr );
992 out << "</access>\n";
995 /* PrePush expression. */
996 if ( pd->prePushExpr != 0 ) {
998 writeInlineList( pd->prePushExpr );
999 out << "</prepush>\n";
1002 /* PostPop expression. */
1003 if ( pd->postPopExpr != 0 ) {
1004 out << " <postpop>";
1005 writeInlineList( pd->postPopExpr );
1006 out << "</postpop>\n";
1010 * Variable expressions.
1013 if ( pd->pExpr != 0 ) {
1015 writeInlineList( pd->pExpr );
1016 out << "</p_expr>\n";
1019 if ( pd->peExpr != 0 ) {
1020 out << " <pe_expr>";
1021 writeInlineList( pd->peExpr );
1022 out << "</pe_expr>\n";
1025 if ( pd->eofExpr != 0 ) {
1026 out << " <eof_expr>";
1027 writeInlineList( pd->eofExpr );
1028 out << "</eof_expr>\n";
1031 if ( pd->csExpr != 0 ) {
1032 out << " <cs_expr>";
1033 writeInlineList( pd->csExpr );
1034 out << "</cs_expr>\n";
1037 if ( pd->topExpr != 0 ) {
1038 out << " <top_expr>";
1039 writeInlineList( pd->topExpr );
1040 out << "</top_expr>\n";
1043 if ( pd->stackExpr != 0 ) {
1044 out << " <stack_expr>";
1045 writeInlineList( pd->stackExpr );
1046 out << "</stack_expr>\n";
1049 if ( pd->actExpr != 0 ) {
1050 out << " <act_expr>";
1051 writeInlineList( pd->actExpr );
1052 out << "</act_expr>\n";
1055 if ( pd->tokstartExpr != 0 ) {
1056 out << " <tokstart_expr>";
1057 writeInlineList( pd->tokstartExpr );
1058 out << "</tokstart_expr>\n";
1061 if ( pd->tokendExpr != 0 ) {
1062 out << " <tokend_expr>";
1063 writeInlineList( pd->tokendExpr );
1064 out << "</tokend_expr>\n";
1067 if ( pd->dataExpr != 0 ) {
1068 out << " <data_expr>";
1069 writeInlineList( pd->dataExpr );
1070 out << "</data_expr>\n";