includeDepth(includeDepth),
line(1), column(1), lastnl(0),
parser(0), active(false),
- parserExistsError(false), ragelDefOpen(false),
+ parserExistsError(false),
whitespaceOn(true)
{}
void updateCol();
void startSection();
void endSection();
- void openRagelDef();
void do_scan();
bool parserExists();
ostream &scan_error();
/* This is set if ragel has already emitted an error stating that
* no section name has been seen and thus no parser exists. */
bool parserExistsError;
- bool ragelDefOpen;
/* This is for inline code. By default it is on. It goes off for
* statements and values in inline blocks which are parsed. */
action write_command
{
if ( active ) {
- openRagelDef();
if ( strcmp( tokdata, "data" ) != 0 &&
strcmp( tokdata, "init" ) != 0 &&
strcmp( tokdata, "exec" ) != 0 &&
{
scan_error() << "unknown write command" << endl;
}
- output << " <write what=\"" << tokdata << "\">";
+ output << "<write def_name=\"" << parser->sectionName <<
+ "\" what=\"" << tokdata << "\">";
}
}
if ( includeDepth == 0 ) {
if ( machineSpec == 0 && machineName == 0 )
output << "</host>\n";
- ragelDefOpen = false;
}
sectionLoc.fileName = fileName;
sectionLoc.col = 0;
}
-void Scanner::openRagelDef()
-{
- if ( ! ragelDefOpen ) {
- ragelDefOpen = true;
- output << "<ragel_def name=\"" << parser->sectionName << "\">\n";
- }
-}
-
void Scanner::endSection( )
{
/* Execute the eof actions for the section parser. */
}
if ( includeDepth == 0 ) {
- if ( ragelDefOpen ) {
- output << "</ragel_def>\n";
- ragelDefOpen = false;
- }
-
if ( machineSpec == 0 && machineName == 0 ) {
/* The end section may include a newline on the end, so
* we use the last line, which will count the newline. */
gblErrorCount += 1;
};
-tag_ragel: tag_ragel_head host_or_def_list '/' TAG_ragel;
+tag_ragel: tag_ragel_head ragel_def_list host_or_write_list '/' TAG_ragel;
tag_ragel_head: TAG_ragel
final {
outStream = openOutput( sourceFileName );
};
-host_or_def_list: host_or_def_list host_or_def;
-host_or_def_list: ;
+ragel_def_list: ragel_def_list ragel_def;
+ragel_def_list: ;
-host_or_def: host;
-host_or_def: ragel_def;
+host_or_write_list: host_or_write_list host_or_write;
+host_or_write_list: ;
-host:
+host_or_write: tag_host;
+host_or_write: tag_write;
+
+tag_host:
TAG_host '/' TAG_host
final {
Attribute *lineAttr = $1->tag->findAttr( "line" );
*outStream << $3->tag->content;
};
-ragel_def:
- tag_ragel_def_head ragel_def_item_list '/' TAG_ragel_def
- final {
- if ( gblErrorCount == 0 )
- cgd->generate();
- };
+ragel_def: tag_ragel_def_head ragel_def_item_list '/' TAG_ragel_def;
tag_ragel_def_head: TAG_ragel_def
final {
cgd = makeCodeGen( sourceFileName, fsmName, *outStream, wantComplete );
}
- cgd->writeOps = 0;
- cgd->writeData = false;
- cgd->writeInit = false;
- cgd->writeExec = false;
- cgd->writeEOF = false;
::keyOps = &cgd->thisKeyOps;
};
ragel_def_item: tag_access_expr;
ragel_def_item: tag_curstate_expr;
ragel_def_item: tag_machine;
-ragel_def_item: tag_write;
tag_alph_type: TAG_alphtype '/' TAG_alphtype
final {
cgd->curStateExpr = $2->inlineList;
};
-tag_write: TAG_write write_option_list '/' TAG_write
+tag_write: tag_write_head write_option_list '/' TAG_write
final {
Attribute *what = $1->tag->findAttr( "what" );
if ( what == 0 ) {
cgd->writeExec = true;
else if ( strcmp( what->value, "eof" ) == 0 )
cgd->writeEOF = true;
+
+ if ( gblErrorCount == 0 )
+ cgd->generate();
+ }
+ };
+
+nonterm tag_write_head
+{
+ XMLTag *tag;
+ InputLoc loc;
+};
+
+tag_write_head: TAG_write
+ final {
+ Attribute *nameAttr = $1->tag->findAttr( "def_name" );
+ if ( nameAttr == 0 ) {
+ error($1->loc) << "tag <write> requires a def_name attribute" << endl;
}
+ else {
+ CodeGenMapEl *mapEl = codeGenMap.find( nameAttr->value );
+ assert( mapEl != 0 );
+ cgd = mapEl->value;
+ }
+
+ cgd->writeData = false;
+ cgd->writeInit = false;
+ cgd->writeExec = false;
+ cgd->writeEOF = false;
+ ::keyOps = &cgd->thisKeyOps;
+
+ $$->tag = $1->tag;
+ $$->loc = $1->loc;
};
+
write_option_list: write_option_list tag_option;
write_option_list: ;