Backend main functions are now factored out.
[external/ragel.git] / ragel / xmlcodegen.cpp
1 /*
2  *  Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
3  */
4
5 /*  This file is part of Ragel.
6  *
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.
11  * 
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.
16  * 
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 
20  */
21
22
23 #include "ragel.h"
24 #include "xmlcodegen.h"
25 #include "parsedata.h"
26 #include "fsmgraph.h"
27 #include <string.h>
28
29 using namespace std;
30
31 XMLCodeGen::XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, 
32                 std::ostream &out )
33 :
34         fsmName(fsmName),
35         pd(pd),
36         fsm(fsm),
37         out(out),
38         nextActionTableId(0)
39 {
40 }
41
42
43 void XMLCodeGen::writeActionList()
44 {
45         /* Determine which actions to write. */
46         int nextActionId = 0;
47         for ( ActionList::Iter act = pd->actionList; act.lte(); act++ ) {
48                 if ( act->numRefs() > 0 || act->numCondRefs > 0 )
49                         act->actionId = nextActionId++;
50         }
51
52         /* Write the list. */
53         out << "    <action_list length=\"" << nextActionId << "\">\n";
54         for ( ActionList::Iter act = pd->actionList; act.lte(); act++ ) {
55                 if ( act->actionId >= 0 )
56                         writeAction( act );
57         }
58         out << "    </action_list>\n";
59 }
60
61 void XMLCodeGen::writeActionTableList()
62 {
63         /* Must first order the action tables based on their id. */
64         int numTables = nextActionTableId;
65         RedActionTable **tables = new RedActionTable*[numTables];
66         for ( ActionTableMap::Iter at = actionTableMap; at.lte(); at++ )
67                 tables[at->id] = at;
68
69         out << "    <action_table_list length=\"" << numTables << "\">\n";
70         for ( int t = 0; t < numTables; t++ ) {
71                 out << "      <action_table id=\"" << t << "\" length=\"" << 
72                                 tables[t]->key.length() << "\">";
73                 for ( ActionTable::Iter atel = tables[t]->key; atel.lte(); atel++ ) {
74                         out << atel->value->actionId;
75                         if ( ! atel.last() )
76                                 out << " ";
77                 }
78                 out << "</action_table>\n";
79         }
80         out << "    </action_table_list>\n";
81
82         delete[] tables;
83 }
84
85 void XMLCodeGen::reduceActionTables()
86 {
87         /* Reduce the actions tables to a set. */
88         for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
89                 RedActionTable *actionTable = 0;
90
91                 /* Reduce To State Actions. */
92                 if ( st->toStateActionTable.length() > 0 ) {
93                         if ( actionTableMap.insert( st->toStateActionTable, &actionTable ) )
94                                 actionTable->id = nextActionTableId++;
95                 }
96
97                 /* Reduce From State Actions. */
98                 if ( st->fromStateActionTable.length() > 0 ) {
99                         if ( actionTableMap.insert( st->fromStateActionTable, &actionTable ) )
100                                 actionTable->id = nextActionTableId++;
101                 }
102
103                 /* Reduce EOF actions. */
104                 if ( st->eofActionTable.length() > 0 ) {
105                         if ( actionTableMap.insert( st->eofActionTable, &actionTable ) )
106                                 actionTable->id = nextActionTableId++;
107                 }
108
109                 /* Loop the transitions and reduce their actions. */
110                 for ( TransList::Iter trans = st->outList; trans.lte(); trans++ ) {
111                         if ( trans->actionTable.length() > 0 ) {
112                                 if ( actionTableMap.insert( trans->actionTable, &actionTable ) )
113                                         actionTable->id = nextActionTableId++;
114                         }
115                 }
116         }
117 }
118
119 void XMLCodeGen::appendTrans( TransListVect &outList, Key lowKey, 
120                 Key highKey, TransAp *trans )
121 {
122         if ( trans->toState != 0 || trans->actionTable.length() > 0 )
123                 outList.append( TransEl( lowKey, highKey, trans ) );
124 }
125
126 void XMLCodeGen::writeKey( Key key )
127 {
128         if ( keyOps->isSigned )
129                 out << key.getVal();
130         else
131                 out << (unsigned long) key.getVal();
132 }
133
134 void XMLCodeGen::writeTrans( Key lowKey, Key highKey, TransAp *trans )
135 {
136         /* First reduce the action. */
137         RedActionTable *actionTable = 0;
138         if ( trans->actionTable.length() > 0 )
139                 actionTable = actionTableMap.find( trans->actionTable );
140
141         /* Write the transition. */
142         out << "        <t>";
143         writeKey( lowKey );
144         out << " ";
145         writeKey( highKey );
146
147         if ( trans->toState != 0 )
148                 out << " " << trans->toState->alg.stateNum;
149         else
150                 out << " x";
151
152         if ( actionTable != 0 )
153                 out << " " << actionTable->id;
154         else
155                 out << " x";
156         out << "</t>\n";
157 }
158
159 void XMLCodeGen::writeTransList( StateAp *state )
160 {
161         TransListVect outList;
162
163         /* If there is only are no ranges the task is simple. */
164         if ( state->outList.length() > 0 ) {
165                 /* Loop each source range. */
166                 for ( TransList::Iter trans = state->outList; trans.lte(); trans++ ) {
167                         /* Reduce the transition. If it reduced to anything then add it. */
168                         appendTrans( outList, trans->lowKey, trans->highKey, trans );
169                 }
170         }
171
172         out << "      <trans_list length=\"" << outList.length() << "\">\n";
173         for ( TransListVect::Iter tvi = outList; tvi.lte(); tvi++ )
174                 writeTrans( tvi->lowKey, tvi->highKey, tvi->value );
175         out << "      </trans_list>\n";
176 }
177
178 void XMLCodeGen::writeEofTrans( StateAp *state )
179 {
180         RedActionTable *eofActions = 0;
181         if ( state->eofActionTable.length() > 0 )
182                 eofActions = actionTableMap.find( state->eofActionTable );
183         
184         /* The <eof_t> is used when there is an eof target, otherwise the eof
185          * action goes into state actions. */
186         if ( state->eofTarget != 0 ) {
187                 out << "      <eof_t>" << state->eofTarget->alg.stateNum;
188
189                 if ( eofActions != 0 )
190                         out << " " << eofActions->id;
191                 else
192                         out << " x"; 
193
194                 out << "</eof_t>" << endl;
195         }
196 }
197
198 void XMLCodeGen::writeText( InlineItem *item )
199 {
200         if ( item->prev == 0 || item->prev->type != InlineItem::Text )
201                 out << "<text>";
202         xmlEscapeHost( out, item->data, strlen(item->data) );
203         if ( item->next == 0 || item->next->type != InlineItem::Text )
204                 out << "</text>";
205 }
206
207 void XMLCodeGen::writeGoto( InlineItem *item )
208 {
209         if ( pd->generatingSectionSubset )
210                 out << "<goto>-1</goto>";
211         else {
212                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
213                 out << "<goto>" << targ->value->alg.stateNum << "</goto>";
214         }
215 }
216
217 void XMLCodeGen::writeCall( InlineItem *item )
218 {
219         if ( pd->generatingSectionSubset )
220                 out << "<call>-1</call>";
221         else {
222                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
223                 out << "<call>" << targ->value->alg.stateNum << "</call>";
224         }
225 }
226
227 void XMLCodeGen::writeNext( InlineItem *item )
228 {
229         if ( pd->generatingSectionSubset )
230                 out << "<next>-1</next>";
231         else {
232                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
233                 out << "<next>" << targ->value->alg.stateNum << "</next>";
234         }
235 }
236
237 void XMLCodeGen::writeGotoExpr( InlineItem *item )
238 {
239         out << "<goto_expr>";
240         writeInlineList( item->children );
241         out << "</goto_expr>";
242 }
243
244 void XMLCodeGen::writeCallExpr( InlineItem *item )
245 {
246         out << "<call_expr>";
247         writeInlineList( item->children );
248         out << "</call_expr>";
249 }
250
251 void XMLCodeGen::writeNextExpr( InlineItem *item )
252 {
253         out << "<next_expr>";
254         writeInlineList( item->children );
255         out << "</next_expr>";
256 }
257
258 void XMLCodeGen::writeEntry( InlineItem *item )
259 {
260         if ( pd->generatingSectionSubset )
261                 out << "<entry>-1</entry>";
262         else {
263                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
264                 out << "<entry>" << targ->value->alg.stateNum << "</entry>";
265         }
266 }
267
268 void XMLCodeGen::writeActionExec( InlineItem *item )
269 {
270         out << "<exec>";
271         writeInlineList( item->children );
272         out << "</exec>";
273 }
274
275 void XMLCodeGen::writeLmOnLast( InlineItem *item )
276 {
277         out << "<set_tokend>1</set_tokend>";
278
279         if ( item->longestMatchPart->action != 0 ) {
280                 out << "<sub_action>";
281                 writeInlineList( item->longestMatchPart->action->inlineList );
282                 out << "</sub_action>";
283         }
284 }
285
286 void XMLCodeGen::writeLmOnNext( InlineItem *item )
287 {
288         out << "<set_tokend>0</set_tokend>";
289         out << "<hold></hold>";
290
291         if ( item->longestMatchPart->action != 0 ) {
292                 out << "<sub_action>";
293                 writeInlineList( item->longestMatchPart->action->inlineList );
294                 out << "</sub_action>";
295         }
296 }
297
298 void XMLCodeGen::writeLmOnLagBehind( InlineItem *item )
299 {
300         out << "<exec><get_tokend></get_tokend></exec>";
301
302         if ( item->longestMatchPart->action != 0 ) {
303                 out << "<sub_action>";
304                 writeInlineList( item->longestMatchPart->action->inlineList );
305                 out << "</sub_action>";
306         }
307 }
308
309 void XMLCodeGen::writeLmSwitch( InlineItem *item )
310 {
311         LongestMatch *longestMatch = item->longestMatch;
312         out << "<lm_switch>\n";
313
314         /* We can't put the <exec> here because we may need to handle the error
315          * case and in that case p should not be changed. Instead use a default
316          * label in the switch to adjust p when user actions are not set. An id of
317          * -1 indicates the default. */
318
319         if ( longestMatch->lmSwitchHandlesError ) {
320                 /* If the switch handles error then we should have also forced the
321                  * error state. */
322                 assert( fsm->errState != 0 );
323
324                 out << "        <sub_action id=\"0\">";
325                 out << "<goto>" << fsm->errState->alg.stateNum << "</goto>";
326                 out << "</sub_action>\n";
327         }
328         
329         bool needDefault = false;
330         for ( LmPartList::Iter lmi = *longestMatch->longestMatchList; lmi.lte(); lmi++ ) {
331                 if ( lmi->inLmSelect ) {
332                         if ( lmi->action == 0 )
333                                 needDefault = true;
334                         else {
335                                 /* Open the action. Write it with the context that sets up _p 
336                                  * when doing control flow changes from inside the machine. */
337                                 out << "        <sub_action id=\"" << lmi->longestMatchId << "\">";
338                                 out << "<exec><get_tokend></get_tokend></exec>";
339                                 writeInlineList( lmi->action->inlineList );
340                                 out << "</sub_action>\n";
341                         }
342                 }
343         }
344
345         if ( needDefault ) {
346                 out << "        <sub_action id=\"-1\"><exec><get_tokend>"
347                                 "</get_tokend></exec></sub_action>\n";
348         }
349
350         out << "    </lm_switch>";
351 }
352
353 void XMLCodeGen::writeInlineList( InlineList *inlineList )
354 {
355         for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) {
356                 switch ( item->type ) {
357                 case InlineItem::Text:
358                         writeText( item );
359                         break;
360                 case InlineItem::Goto:
361                         writeGoto( item );
362                         break;
363                 case InlineItem::GotoExpr:
364                         writeGotoExpr( item );
365                         break;
366                 case InlineItem::Call:
367                         writeCall( item );
368                         break;
369                 case InlineItem::CallExpr:
370                         writeCallExpr( item );
371                         break;
372                 case InlineItem::Next:
373                         writeNext( item );
374                         break;
375                 case InlineItem::NextExpr:
376                         writeNextExpr( item );
377                         break;
378                 case InlineItem::Break:
379                         out << "<break></break>";
380                         break;
381                 case InlineItem::Ret: 
382                         out << "<ret></ret>";
383                         break;
384                 case InlineItem::PChar:
385                         out << "<pchar></pchar>";
386                         break;
387                 case InlineItem::Char: 
388                         out << "<char></char>";
389                         break;
390                 case InlineItem::Curs: 
391                         out << "<curs></curs>";
392                         break;
393                 case InlineItem::Targs: 
394                         out << "<targs></targs>";
395                         break;
396                 case InlineItem::Entry:
397                         writeEntry( item );
398                         break;
399
400                 case InlineItem::Hold:
401                         out << "<hold></hold>";
402                         break;
403                 case InlineItem::Exec:
404                         writeActionExec( item );
405                         break;
406
407                 case InlineItem::LmSetActId:
408                         out << "<set_act>" << 
409                                         item->longestMatchPart->longestMatchId << 
410                                         "</set_act>";
411                         break;
412                 case InlineItem::LmSetTokEnd:
413                         out << "<set_tokend>1</set_tokend>";
414                         break;
415
416                 case InlineItem::LmOnLast:
417                         writeLmOnLast( item );
418                         break;
419                 case InlineItem::LmOnNext:
420                         writeLmOnNext( item );
421                         break;
422                 case InlineItem::LmOnLagBehind:
423                         writeLmOnLagBehind( item );
424                         break;
425                 case InlineItem::LmSwitch: 
426                         writeLmSwitch( item );
427                         break;
428
429                 case InlineItem::LmInitAct:
430                         out << "<init_act></init_act>";
431                         break;
432                 case InlineItem::LmInitTokStart:
433                         out << "<init_tokstart></init_tokstart>";
434                         break;
435                 case InlineItem::LmSetTokStart:
436                         out << "<set_tokstart></set_tokstart>";
437                         break;
438                 }
439         }
440 }
441
442 void XMLCodeGen::writeAction( Action *action )
443 {
444         out << "      <action id=\"" << action->actionId << "\"";
445         if ( action->name != 0 ) 
446                 out << " name=\"" << action->name << "\"";
447         out << " line=\"" << action->loc.line << "\" col=\"" << action->loc.col << "\">";
448         writeInlineList( action->inlineList );
449         out << "</action>\n";
450 }
451
452 void xmlEscapeHost( std::ostream &out, char *data, long len )
453 {
454         char *end = data + len;
455         while ( data != end ) {
456                 switch ( *data ) {
457                 case '<': out << "&lt;"; break;
458                 case '>': out << "&gt;"; break;
459                 case '&': out << "&amp;"; break;
460                 default: out << *data; break;
461                 }
462                 data += 1;
463         }
464 }
465
466 void XMLCodeGen::writeStateActions( StateAp *state )
467 {
468         RedActionTable *toStateActions = 0;
469         if ( state->toStateActionTable.length() > 0 )
470                 toStateActions = actionTableMap.find( state->toStateActionTable );
471
472         RedActionTable *fromStateActions = 0;
473         if ( state->fromStateActionTable.length() > 0 )
474                 fromStateActions = actionTableMap.find( state->fromStateActionTable );
475
476         /* EOF actions go out here only if the state has no eof target. If it has
477          * an eof target then an eof transition will be used instead. */
478         RedActionTable *eofActions = 0;
479         if ( state->eofTarget == 0 && state->eofActionTable.length() > 0 )
480                 eofActions = actionTableMap.find( state->eofActionTable );
481         
482         if ( toStateActions != 0 || fromStateActions != 0 || eofActions != 0 ) {
483                 out << "      <state_actions>";
484                 if ( toStateActions != 0 )
485                         out << toStateActions->id;
486                 else
487                         out << "x";
488
489                 if ( fromStateActions != 0 )
490                         out << " " << fromStateActions->id;
491                 else
492                         out << " x";
493
494                 if ( eofActions != 0 )
495                         out << " " << eofActions->id;
496                 else
497                         out << " x";
498
499                 out << "</state_actions>\n";
500         }
501 }
502
503 void XMLCodeGen::writeStateConditions( StateAp *state )
504 {
505         if ( state->stateCondList.length() > 0 ) {
506                 out << "      <cond_list length=\"" << state->stateCondList.length() << "\">\n";
507                 for ( StateCondList::Iter scdi = state->stateCondList; scdi.lte(); scdi++ ) {
508                         out << "        <c>";
509                         writeKey( scdi->lowKey );
510                         out << " ";
511                         writeKey( scdi->highKey );
512                         out << " ";
513                         out << scdi->condSpace->condSpaceId;
514                         out << "</c>\n";
515                 }
516                 out << "      </cond_list>\n";
517         }
518 }
519
520 void XMLCodeGen::writeStateList()
521 {
522         /* Write the list of states. */
523         out << "    <state_list length=\"" << fsm->stateList.length() << "\">\n";
524         for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
525                 out << "      <state id=\"" << st->alg.stateNum << "\"";
526                 if ( st->isFinState() )
527                         out << " final=\"t\"";
528                 out << ">\n";
529
530                 writeStateActions( st );
531                 writeEofTrans( st );
532                 writeStateConditions( st );
533                 writeTransList( st );
534
535                 out << "      </state>\n";
536
537                 if ( !st.last() )
538                         out << "\n";
539         }
540         out << "    </state_list>\n";
541 }
542
543 bool XMLCodeGen::writeNameInst( NameInst *nameInst )
544 {
545         bool written = false;
546         if ( nameInst->parent != 0 )
547                 written = writeNameInst( nameInst->parent );
548         
549         if ( nameInst->name != 0 ) {
550                 if ( written )
551                         out << '_';
552                 out << nameInst->name;
553                 written = true;
554         }
555
556         return written;
557 }
558
559 void XMLCodeGen::writeEntryPoints()
560 {
561         /* List of entry points other than start state. */
562         if ( fsm->entryPoints.length() > 0 || pd->lmRequiresErrorState ) {
563                 out << "    <entry_points";
564                 if ( pd->lmRequiresErrorState )
565                         out << " error=\"t\"";
566                 out << ">\n";
567                 for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
568                         /* Get the name instantiation from nameIndex. */
569                         NameInst *nameInst = pd->nameIndex[en->key];
570                         StateAp *state = en->value;
571                         out << "      <entry name=\"";
572                         writeNameInst( nameInst );
573                         out << "\">" << state->alg.stateNum << "</entry>\n";
574                 }
575                 out << "    </entry_points>\n";
576         }
577 }
578
579 void XMLCodeGen::writeMachine()
580 {
581         /* Open the machine. */
582         out << "  <machine>\n"; 
583         
584         /* Action tables. */
585         reduceActionTables();
586
587         writeActionList();
588         writeActionTableList();
589         writeConditions();
590
591         /* Start state. */
592         out << "    <start_state>" << fsm->startState->alg.stateNum << 
593                         "</start_state>\n";
594         
595         /* Error state. */
596         if ( fsm->errState != 0 ) {
597                 out << "    <error_state>" << fsm->errState->alg.stateNum << 
598                         "</error_state>\n";
599         }
600
601         writeEntryPoints();
602         writeStateList();
603
604         out << "  </machine>\n";
605 }
606
607
608 void XMLCodeGen::writeConditions()
609 {
610         if ( condData->condSpaceMap.length() > 0 ) {
611                 long nextCondSpaceId = 0;
612                 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ )
613                         cs->condSpaceId = nextCondSpaceId++;
614
615                 out << "    <cond_space_list length=\"" << condData->condSpaceMap.length() << "\">\n";
616                 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ ) {
617                         out << "      <cond_space id=\"" << cs->condSpaceId << 
618                                 "\" length=\"" << cs->condSet.length() << "\">";
619                         writeKey( cs->baseKey );
620                         for ( CondSet::Iter csi = cs->condSet; csi.lte(); csi++ )
621                                 out << " " << (*csi)->actionId;
622                         out << "</cond_space>\n";
623                 }
624                 out << "    </cond_space_list>\n";
625         }
626 }
627
628 void XMLCodeGen::writeExports()
629 {
630         if ( pd->exportList.length() > 0 ) {
631                 out << "  <exports>\n";
632                 for ( ExportList::Iter exp = pd->exportList; exp.lte(); exp++ ) {
633                         out << "    <ex name=\"" << exp->name << "\">";
634                         writeKey( exp->key );
635                         out << "</ex>\n";
636                 }
637                 out << "  </exports>\n";
638         }
639 }
640
641 void XMLCodeGen::writeXML()
642 {
643         /* Open the definition. */
644         out << "<ragel_def name=\"" << fsmName << "\">\n";
645
646         /* Alphabet type. */
647         out << "  <alphtype>" << keyOps->alphType->internalName << "</alphtype>\n";
648         
649         /* Getkey expression. */
650         if ( pd->getKeyExpr != 0 ) {
651                 out << "  <getkey>";
652                 writeInlineList( pd->getKeyExpr );
653                 out << "</getkey>\n";
654         }
655
656         /* Access expression. */
657         if ( pd->accessExpr != 0 ) {
658                 out << "  <access>";
659                 writeInlineList( pd->accessExpr );
660                 out << "</access>\n";
661         }
662
663         /* PrePush expression. */
664         if ( pd->prePushExpr != 0 ) {
665                 out << "  <prepush>";
666                 writeInlineList( pd->prePushExpr );
667                 out << "</prepush>\n";
668         }
669
670         /* PostPop expression. */
671         if ( pd->postPopExpr != 0 ) {
672                 out << "  <postpop>";
673                 writeInlineList( pd->postPopExpr );
674                 out << "</postpop>\n";
675         }
676
677         /*
678          * Variable expressions.
679          */
680
681         if ( pd->pExpr != 0 ) {
682                 out << "  <p_expr>";
683                 writeInlineList( pd->pExpr );
684                 out << "</p_expr>\n";
685         }
686         
687         if ( pd->peExpr != 0 ) {
688                 out << "  <pe_expr>";
689                 writeInlineList( pd->peExpr );
690                 out << "</pe_expr>\n";
691         }
692
693         if ( pd->eofExpr != 0 ) {
694                 out << "  <eof_expr>";
695                 writeInlineList( pd->eofExpr );
696                 out << "</eof_expr>\n";
697         }
698         
699         if ( pd->csExpr != 0 ) {
700                 out << "  <cs_expr>";
701                 writeInlineList( pd->csExpr );
702                 out << "</cs_expr>\n";
703         }
704         
705         if ( pd->topExpr != 0 ) {
706                 out << "  <top_expr>";
707                 writeInlineList( pd->topExpr );
708                 out << "</top_expr>\n";
709         }
710         
711         if ( pd->stackExpr != 0 ) {
712                 out << "  <stack_expr>";
713                 writeInlineList( pd->stackExpr );
714                 out << "</stack_expr>\n";
715         }
716         
717         if ( pd->actExpr != 0 ) {
718                 out << "  <act_expr>";
719                 writeInlineList( pd->actExpr );
720                 out << "</act_expr>\n";
721         }
722         
723         if ( pd->tokstartExpr != 0 ) {
724                 out << "  <tokstart_expr>";
725                 writeInlineList( pd->tokstartExpr );
726                 out << "</tokstart_expr>\n";
727         }
728         
729         if ( pd->tokendExpr != 0 ) {
730                 out << "  <tokend_expr>";
731                 writeInlineList( pd->tokendExpr );
732                 out << "</tokend_expr>\n";
733         }
734         
735         if ( pd->dataExpr != 0 ) {
736                 out << "  <data_expr>";
737                 writeInlineList( pd->dataExpr );
738                 out << "</data_expr>\n";
739         }
740         
741         writeExports();
742         
743         writeMachine();
744
745         out <<
746                 "</ragel_def>\n";
747 }
748