Put the scanner action generators together.
[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::writeText( InlineItem *item )
179 {
180         if ( item->prev == 0 || item->prev->type != InlineItem::Text )
181                 out << "<text>";
182         xmlEscapeHost( out, item->data, strlen(item->data) );
183         if ( item->next == 0 || item->next->type != InlineItem::Text )
184                 out << "</text>";
185 }
186
187 bool isLmItem( InlineItem *context )
188 {
189         return context != 0 && (
190                 context->type == InlineItem::LmOnLast ||
191                 context->type == InlineItem::LmOnNext ||
192                 context->type == InlineItem::LmOnLagBehind ||
193                 context->type == InlineItem::LmSwitch );
194 }
195
196 void XMLCodeGen::writeCtrlFlow( InlineItem *item, InlineItem *context )
197 {
198         if ( isLmItem( context ) ) {
199                 out << "<sub_action>";
200                 out << "<exec><get_tokend></get_tokend></exec>";
201         }
202
203         switch ( item->type ) {
204         case InlineItem::Goto:
205                 writeGoto( item, context );
206                 break;
207         case InlineItem::GotoExpr:
208                 writeGotoExpr( item, context );
209                 break;
210         case InlineItem::Call:
211                 writeCall( item, context );
212                 break;
213         case InlineItem::CallExpr:
214                 writeCallExpr( item, context );
215                 break;
216         case InlineItem::Next:
217                 writeNext( item, context );
218                 break;
219         case InlineItem::NextExpr:
220                 writeNextExpr( item, context );
221                 break;
222         case InlineItem::Break:
223                 out << "<break></break>";
224                 break;
225         case InlineItem::Ret: 
226                 out << "<ret></ret>";
227                 break;
228         default: break;
229         }
230
231         if ( isLmItem( context ) )
232                 out << "</sub_action>";
233 }
234
235 void XMLCodeGen::writePtrMod( InlineItem *item, InlineItem *context )
236 {
237         if ( isLmItem( context ) ) {
238                 switch ( item->type ) {
239                 case InlineItem::Hold:
240                         out << "<holdte></holdte>";
241                         break;
242                 case InlineItem::Exec:
243                         writeActionExecTE( item );
244                         break;
245                 default: break;
246                 }
247         }
248         else {
249                 switch ( item->type ) {
250                 case InlineItem::Hold:
251                         out << "<hold></hold>";
252                         break;
253                 case InlineItem::Exec:
254                         writeActionExec( item );
255                         break;
256                 default: break;
257                 }
258         }
259 }
260
261
262 void XMLCodeGen::writeGoto( InlineItem *item, InlineItem *context )
263 {
264         if ( pd->generatingSectionSubset )
265                 out << "<goto>-1</goto>";
266         else {
267                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
268                 out << "<goto>" << targ->value->alg.stateNum << "</goto>";
269         }
270 }
271
272 void XMLCodeGen::writeCall( InlineItem *item, InlineItem *context )
273 {
274         if ( pd->generatingSectionSubset )
275                 out << "<call>-1</call>";
276         else {
277                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
278                 out << "<call>" << targ->value->alg.stateNum << "</call>";
279         }
280 }
281
282 void XMLCodeGen::writeNext( InlineItem *item, InlineItem *context )
283 {
284         if ( pd->generatingSectionSubset )
285                 out << "<next>-1</next>";
286         else {
287                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
288                 out << "<next>" << targ->value->alg.stateNum << "</next>";
289         }
290 }
291
292 void XMLCodeGen::writeGotoExpr( InlineItem *item, InlineItem *context )
293 {
294         out << "<goto_expr>";
295         writeInlineList( item->children, 0 );
296         out << "</goto_expr>";
297 }
298
299 void XMLCodeGen::writeCallExpr( InlineItem *item, InlineItem *context )
300 {
301         out << "<call_expr>";
302         writeInlineList( item->children, 0 );
303         out << "</call_expr>";
304 }
305
306 void XMLCodeGen::writeNextExpr( InlineItem *item, InlineItem *context )
307 {
308         out << "<next_expr>";
309         writeInlineList( item->children, 0 );
310         out << "</next_expr>";
311 }
312
313 void XMLCodeGen::writeEntry( InlineItem * item )
314 {
315         if ( pd->generatingSectionSubset )
316                 out << "<entry>-1</entry>";
317         else {
318                 EntryMapEl *targ = fsm->entryPoints.find( item->nameTarg->id );
319                 out << "<entry>" << targ->value->alg.stateNum << "</entry>";
320         }
321 }
322
323 void XMLCodeGen::writeActionExec( InlineItem *item )
324 {
325         out << "<exec>";
326         writeInlineList( item->children, 0 );
327         out << "</exec>";
328 }
329
330 void XMLCodeGen::writeActionExecTE( InlineItem *item )
331 {
332         out << "<execte>";
333         writeInlineList( item->children, 0 );
334         out << "</execte>";
335 }
336
337 void XMLCodeGen::writeLmOnLast( InlineItem *item )
338 {
339         out << "<set_tokend>1</set_tokend>";
340         if ( item->longestMatchPart->action != 0 ) {
341                 out << "<sub_action>";
342                 writeInlineList( item->longestMatchPart->action->inlineList, item );
343                 out << "</sub_action>";
344         }
345         out << "<exec><get_tokend></get_tokend></exec>";
346 }
347
348 void XMLCodeGen::writeLmOnNext( InlineItem *item )
349 {
350         out << "<set_tokend>0</set_tokend>";
351         if ( item->longestMatchPart->action != 0 ) {
352                 out << "<sub_action>";
353                 writeInlineList( item->longestMatchPart->action->inlineList, item );
354                 out << "</sub_action>";
355         }
356         out << "<exec><get_tokend></get_tokend></exec>";
357 }
358
359 void XMLCodeGen::writeLmOnLagBehind( InlineItem *item )
360 {
361         if ( item->longestMatchPart->action != 0 ) {
362                 out << "<sub_action>";
363                 writeInlineList( item->longestMatchPart->action->inlineList, item );
364                 out << "</sub_action>";
365         }
366         out << "<exec><get_tokend></get_tokend></exec>";
367 }
368
369 void XMLCodeGen::writeLmSwitch( InlineItem *item )
370 {
371         LongestMatch *longestMatch = item->longestMatch;
372
373         out << "<lm_switch";
374         if ( longestMatch->lmSwitchHandlesError )
375                 out << " handles_error=\"t\"";
376         out << ">\n";
377         
378         for ( LmPartList::Iter lmi = *longestMatch->longestMatchList; lmi.lte(); lmi++ ) {
379                 if ( lmi->inLmSelect && lmi->action != 0 ) {
380                         /* Open the action. Write it with the context that sets up _p 
381                          * when doing control flow changes from inside the machine. */
382                         out << "      <sub_action id=\"" << lmi->longestMatchId << "\">";
383                         writeInlineList( lmi->action->inlineList, item );
384                         out << "</sub_action>\n";
385                 }
386         }
387
388         out << "    </lm_switch><exec><get_tokend></get_tokend></exec>";
389 }
390
391 void XMLCodeGen::writeInlineList( InlineList *inlineList, InlineItem *context )
392 {
393         for ( InlineList::Iter item = *inlineList; item.lte(); item++ ) {
394                 switch ( item->type ) {
395                 case InlineItem::Text:
396                         writeText( item );
397                         break;
398                 case InlineItem::Goto: case InlineItem::GotoExpr:
399                 case InlineItem::Call: case InlineItem::CallExpr:
400                 case InlineItem::Next: case InlineItem::NextExpr:
401                 case InlineItem::Break: case InlineItem::Ret: 
402                         writeCtrlFlow( item, context );
403                         break;
404                 case InlineItem::PChar:
405                         out << "<pchar></pchar>";
406                         break;
407                 case InlineItem::Char: 
408                         out << "<char></char>";
409                         break;
410                 case InlineItem::Curs: 
411                         out << "<curs></curs>";
412                         break;
413                 case InlineItem::Targs: 
414                         out << "<targs></targs>";
415                         break;
416                 case InlineItem::Entry:
417                         writeEntry( item );
418                         break;
419
420                 case InlineItem::Hold:
421                 case InlineItem::Exec:
422                         writePtrMod( item, context );
423                         break;
424
425                 case InlineItem::LmSetActId:
426                         out << "<set_act>" << 
427                                         item->longestMatchPart->longestMatchId << 
428                                         "</set_act>";
429                         break;
430                 case InlineItem::LmSetTokEnd:
431                         out << "<set_tokend>1</set_tokend>";
432                         break;
433
434                 case InlineItem::LmOnLast:
435                         writeLmOnLast( item );
436                         break;
437                 case InlineItem::LmOnNext:
438                         writeLmOnNext( item );
439                         break;
440                 case InlineItem::LmOnLagBehind:
441                         writeLmOnLagBehind( item );
442                         break;
443                 case InlineItem::LmSwitch: 
444                         writeLmSwitch( item );
445                         break;
446
447                 case InlineItem::LmInitAct:
448                         out << "<init_act></init_act>";
449                         break;
450                 case InlineItem::LmInitTokStart:
451                         out << "<init_tokstart></init_tokstart>";
452                         break;
453                 case InlineItem::LmSetTokStart:
454                         out << "<set_tokstart></set_tokstart>";
455                         break;
456                 }
457         }
458 }
459
460 void XMLCodeGen::writeAction( Action *action )
461 {
462         out << "      <action id=\"" << action->actionId << "\"";
463         if ( action->name != 0 ) 
464                 out << " name=\"" << action->name << "\"";
465         out << " line=\"" << action->loc.line << "\" col=\"" << action->loc.col << "\">";
466         writeInlineList( action->inlineList, 0 );
467         out << "</action>\n";
468 }
469
470 void xmlEscapeHost( std::ostream &out, char *data, long len )
471 {
472         char *end = data + len;
473         while ( data != end ) {
474                 switch ( *data ) {
475                 case '<': out << "&lt;"; break;
476                 case '>': out << "&gt;"; break;
477                 case '&': out << "&amp;"; break;
478                 default: out << *data; break;
479                 }
480                 data += 1;
481         }
482 }
483
484 void XMLCodeGen::writeStateActions( StateAp *state )
485 {
486         RedActionTable *toStateActions = 0;
487         if ( state->toStateActionTable.length() > 0 )
488                 toStateActions = actionTableMap.find( state->toStateActionTable );
489
490         RedActionTable *fromStateActions = 0;
491         if ( state->fromStateActionTable.length() > 0 )
492                 fromStateActions = actionTableMap.find( state->fromStateActionTable );
493
494         RedActionTable *eofActions = 0;
495         if ( state->eofActionTable.length() > 0 )
496                 eofActions = actionTableMap.find( state->eofActionTable );
497         
498         if ( toStateActions != 0 || fromStateActions != 0 || eofActions != 0 ) {
499                 out << "      <state_actions>";
500                 if ( toStateActions != 0 )
501                         out << toStateActions->id;
502                 else
503                         out << "x";
504
505                 if ( fromStateActions != 0 )
506                         out << " " << fromStateActions->id;
507                 else
508                         out << " x";
509
510                 if ( eofActions != 0 )
511                         out << " " << eofActions->id;
512                 else
513                         out << " x"; out << "</state_actions>\n";
514         }
515 }
516
517 void XMLCodeGen::writeStateConditions( StateAp *state )
518 {
519         if ( state->stateCondList.length() > 0 ) {
520                 out << "      <cond_list length=\"" << state->stateCondList.length() << "\">\n";
521                 for ( StateCondList::Iter scdi = state->stateCondList; scdi.lte(); scdi++ ) {
522                         out << "        <c>";
523                         writeKey( scdi->lowKey );
524                         out << " ";
525                         writeKey( scdi->highKey );
526                         out << " ";
527                         out << scdi->condSpace->condSpaceId;
528                         out << "</c>\n";
529                 }
530                 out << "      </cond_list>\n";
531         }
532 }
533
534 void XMLCodeGen::writeStateList()
535 {
536         /* Write the list of states. */
537         out << "    <state_list length=\"" << fsm->stateList.length() << "\">\n";
538         for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
539                 out << "      <state id=\"" << st->alg.stateNum << "\"";
540                 if ( st->isFinState() )
541                         out << " final=\"t\"";
542                 out << ">\n";
543
544                 writeStateActions( st );
545                 writeStateConditions( st );
546                 writeTransList( st );
547
548                 out << "      </state>\n";
549
550                 if ( !st.last() )
551                         out << "\n";
552         }
553         out << "    </state_list>\n";
554 }
555
556 bool XMLCodeGen::writeNameInst( NameInst *nameInst )
557 {
558         bool written = false;
559         if ( nameInst->parent != 0 )
560                 written = writeNameInst( nameInst->parent );
561         
562         if ( nameInst->name != 0 ) {
563                 if ( written )
564                         out << '_';
565                 out << nameInst->name;
566                 written = true;
567         }
568
569         return written;
570 }
571
572 void XMLCodeGen::writeEntryPoints()
573 {
574         /* List of entry points other than start state. */
575         if ( fsm->entryPoints.length() > 0 || pd->lmRequiresErrorState ) {
576                 out << "    <entry_points";
577                 if ( pd->lmRequiresErrorState )
578                         out << " error=\"t\"";
579                 out << ">\n";
580                 for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
581                         /* Get the name instantiation from nameIndex. */
582                         NameInst *nameInst = pd->nameIndex[en->key];
583                         StateAp *state = en->value;
584                         out << "      <entry name=\"";
585                         writeNameInst( nameInst );
586                         out << "\">" << state->alg.stateNum << "</entry>\n";
587                 }
588                 out << "    </entry_points>\n";
589         }
590 }
591
592 void XMLCodeGen::writeMachine()
593 {
594         /* Open the machine. */
595         out << "  <machine>\n"; 
596         
597         /* Action tables. */
598         reduceActionTables();
599
600         writeActionList();
601         writeActionTableList();
602         writeConditions();
603
604         /* Start state. */
605         out << "    <start_state>" << fsm->startState->alg.stateNum << 
606                         "</start_state>\n";
607         
608         /* Error state. */
609         if ( fsm->errState != 0 ) {
610                 out << "    <error_state>" << fsm->errState->alg.stateNum << 
611                         "</error_state>\n";
612         }
613
614         writeEntryPoints();
615         writeStateList();
616
617         out << "  </machine>\n";
618 }
619
620
621 void XMLCodeGen::writeConditions()
622 {
623         if ( condData->condSpaceMap.length() > 0 ) {
624                 long nextCondSpaceId = 0;
625                 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ )
626                         cs->condSpaceId = nextCondSpaceId++;
627
628                 out << "    <cond_space_list length=\"" << condData->condSpaceMap.length() << "\">\n";
629                 for ( CondSpaceMap::Iter cs = condData->condSpaceMap; cs.lte(); cs++ ) {
630                         out << "      <cond_space id=\"" << cs->condSpaceId << 
631                                 "\" length=\"" << cs->condSet.length() << "\">";
632                         writeKey( cs->baseKey );
633                         for ( CondSet::Iter csi = cs->condSet; csi.lte(); csi++ )
634                                 out << " " << (*csi)->actionId;
635                         out << "</cond_space>\n";
636                 }
637                 out << "    </cond_space_list>\n";
638         }
639 }
640
641 void XMLCodeGen::writeExports()
642 {
643         if ( pd->exportList.length() > 0 ) {
644                 out << "  <exports>\n";
645                 for ( ExportList::Iter exp = pd->exportList; exp.lte(); exp++ ) {
646                         out << "    <ex name=\"" << exp->name << "\">";
647                         writeKey( exp->key );
648                         out << "</ex>\n";
649                 }
650                 out << "  </exports>\n";
651         }
652 }
653
654 void XMLCodeGen::writeXML()
655 {
656         /* Open the definition. */
657         out << "<ragel_def name=\"" << fsmName << "\">\n";
658
659         /* Alphabet type. */
660         out << "  <alphtype>" << keyOps->alphType->internalName << "</alphtype>\n";
661         
662         /* Getkey expression. */
663         if ( pd->getKeyExpr != 0 ) {
664                 out << "  <getkey>";
665                 writeInlineList( pd->getKeyExpr, 0 );
666                 out << "</getkey>\n";
667         }
668
669         /* Access expression. */
670         if ( pd->accessExpr != 0 ) {
671                 out << "  <access>";
672                 writeInlineList( pd->accessExpr, 0 );
673                 out << "</access>\n";
674         }
675
676         /*
677          * Variable expressions.
678          */
679
680         if ( pd->pExpr != 0 ) {
681                 out << "  <p_expr>";
682                 writeInlineList( pd->pExpr, 0 );
683                 out << "</p_expr>\n";
684         }
685         
686         if ( pd->peExpr != 0 ) {
687                 out << "  <pe_expr>";
688                 writeInlineList( pd->peExpr, 0 );
689                 out << "</pe_expr>\n";
690         }
691         
692         if ( pd->csExpr != 0 ) {
693                 out << "  <cs_expr>";
694                 writeInlineList( pd->csExpr, 0 );
695                 out << "</cs_expr>\n";
696         }
697         
698         if ( pd->topExpr != 0 ) {
699                 out << "  <top_expr>";
700                 writeInlineList( pd->topExpr, 0 );
701                 out << "</top_expr>\n";
702         }
703         
704         if ( pd->stackExpr != 0 ) {
705                 out << "  <stack_expr>";
706                 writeInlineList( pd->stackExpr, 0 );
707                 out << "</stack_expr>\n";
708         }
709         
710         if ( pd->actExpr != 0 ) {
711                 out << "  <act_expr>";
712                 writeInlineList( pd->actExpr, 0 );
713                 out << "</act_expr>\n";
714         }
715         
716         if ( pd->tokstartExpr != 0 ) {
717                 out << "  <tokstart_expr>";
718                 writeInlineList( pd->tokstartExpr, 0 );
719                 out << "</tokstart_expr>\n";
720         }
721         
722         if ( pd->tokendExpr != 0 ) {
723                 out << "  <tokend_expr>";
724                 writeInlineList( pd->tokendExpr, 0 );
725                 out << "</tokend_expr>\n";
726         }
727         
728         writeExports();
729         
730         writeMachine();
731
732         out <<
733                 "</ragel_def>\n";
734 }
735