/* Scans a string looking for the file extension. If there is a file
* extension then pointer returned points to inside the string
* passed in. Otherwise returns null. */
-char *findFileExtension( char *stemFile )
+const char *findFileExtension( const char *stemFile )
{
- char *ppos = stemFile + strlen(stemFile) - 1;
+ const char *ppos = stemFile + strlen(stemFile) - 1;
/* Scan backwards from the end looking for the first dot.
* If we encounter a '/' before the first dot, then stop the scan. */
/* Make a file name from a stem. Removes the old filename suffix and
* replaces it with a new one. Returns a newed up string. */
-char *fileNameFromStem( char *stemFile, const char *suffix )
+const char *fileNameFromStem( const char *stemFile, const char *suffix )
{
long len = strlen( stemFile );
assert( len > 0 );
/* Get the extension. */
- char *ppos = findFileExtension( stemFile );
+ const char *ppos = findFileExtension( stemFile );
/* If an extension was found, then shorten what we think the len is. */
if ( ppos != 0 )
};
-char *findFileExtension( char *stemFile );
-char *fileNameFromStem( char *stemFile, const char *suffix );
+const char *findFileExtension( const char *stemFile );
+const char *fileNameFromStem( const char *stemFile, const char *suffix );
struct Export
{
#include "mergesort.h"
#include "xmlcodegen.h"
#include "version.h"
+#include "xmlparse.h"
using namespace std;
pdel->value->token( loc, Parser_tk_eof, 0, 0 );
}
-void writeLanguage( std::ostream &out )
+const char *getLang()
{
- out << " lang=\"";
+ const char *lang = 0;
switch ( hostLang->lang ) {
- case HostLang::C: out << "C"; break;
- case HostLang::D: out << "D"; break;
- case HostLang::Java: out << "Java"; break;
- case HostLang::Ruby: out << "Ruby"; break;
- case HostLang::CSharp: out << "C#"; break;
+ case HostLang::C: lang = "C"; break;
+ case HostLang::D: lang = "D"; break;
+ case HostLang::Java: lang = "Java"; break;
+ case HostLang::Ruby: lang = "Ruby"; break;
+ case HostLang::CSharp: lang = "C#"; break;
}
- out << "\"";
-
+ return lang;
}
void writeMachines( std::ostream &out, std::string hostData,
}
if ( gblErrorCount == 0 ) {
- out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
- writeLanguage( out );
- out << ">\n";
+ xmlParser.ragel( VERSION, inputFileName, getLang() );
for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
ParseData *pd = parser->value->pd;
if ( pd->instanceList.length() > 0 )
pd->generateXML( out );
}
out << hostData;
- out << "</ragel>\n";
}
}
else if ( parserDict.length() > 0 ) {
/* Section/Machine to emit was found. Prepare and emit it. */
parseData->prepareMachineGen( graphDictEl );
if ( gblErrorCount == 0 ) {
- out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
- writeLanguage( out );
- out << ">\n";
+ xmlParser.ragel( VERSION, inputFileName, getLang() );
parseData->generateXML( out );
out << hostData;
- out << "</ragel>\n";
}
}
}
}
}
- for ( ActionTableMap::Iter at = redFsm->actionMap; at.lte(); at++ ) {
+ for ( GenActionTableMap::Iter at = redFsm->actionMap; at.lte(); at++ ) {
/* Maximum id of action lists. */
if ( at->actListId+1 > redFsm->maxActListId )
redFsm->maxActListId = at->actListId+1;
}
/* Analyze reduced action lists. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
for ( GenActionTable::Iter act = redAct->key; act.lte(); act++ )
analyzeActionList( redAct, act->value->inlineList );
}
/* These functions must be implemented by the code generation executable.
* The openOutput function is invoked when the root element is opened. The
* makeCodeGen function is invoked when a ragel_def element is opened. */
-std::ostream *cdOpenOutput( char *inputFile );
-std::ostream *javaOpenOutput( char *inputFile );
-std::ostream *rubyOpenOutput( char *inputFile );
-std::ostream *csharpOpenOutput( char *inputFile );
-std::ostream *dotOpenOutput( char *inputFile );
-
-CodeGenData *cdMakeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
-CodeGenData *javaMakeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
-CodeGenData *rubyMakeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
-CodeGenData *csharpMakeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
-CodeGenData *dotMakeCodeGen( char *sourceFileName,
- char *fsmName, ostream &out, bool wantComplete );
+std::ostream *cdOpenOutput( const char *inputFile );
+std::ostream *javaOpenOutput( const char *inputFile );
+std::ostream *rubyOpenOutput( const char *inputFile );
+std::ostream *csharpOpenOutput( const char *inputFile );
+std::ostream *dotOpenOutput( const char *inputFile );
+
+CodeGenData *cdMakeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
+CodeGenData *javaMakeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
+CodeGenData *rubyMakeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
+CodeGenData *csharpMakeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
+CodeGenData *dotMakeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
void cdLineDirective( ostream &out, const char *fileName, int line );
void javaLineDirective( ostream &out, const char *fileName, int line );
* Collecting the machine.
*/
- char *sourceFileName;
- char *fsmName;
+ const char *sourceFileName;
+ const char *fsmName;
ostream &out;
RedFsmAp *redFsm;
GenAction *allActions;
void RedFsmAp::assignActionLocs()
{
int nextLocation = 0;
- for ( ActionTableMap::Iter act = actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = actionMap; act.lte(); act++ ) {
/* Store the loc, skip over the array and a null terminator. */
act->location = nextLocation;
nextLocation += act->key.length() + 1;
bool bAnyCurStateRef;
bool bAnyBreakStmt;
};
-typedef AvlTree<RedAction, GenActionTable, CmpGenActionTable> ActionTableMap;
+typedef AvlTree<RedAction, GenActionTable, CmpGenActionTable> GenActionTableMap;
/* Reduced transition. */
struct RedTransAp
int nextStateId;
TransApSet transSet;
- ActionTableMap actionMap;
+ GenActionTableMap actionMap;
RedStateList stateList;
RedStateSet entryPoints;
RedStateAp *startState;
int token( int tokenId, int col, int line );
int token( XMLTag *tag, int col, int line );
+ void ragel( const char *version, const char *fileName, const char *lang );
+
/* Report an error encountered by the parser. */
ostream &warning( const GenInputLoc &loc );
ostream &error();
/* The name of the root section, this does not change during an include. */
const char *fileName;
- char *sourceFileName;
+ const char *sourceFileName;
ostream *outStream;
bool outputActive;
bool wantComplete;
GenInputLoc loc;
};
-CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *makeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *cgd = 0;
void lineDirective( ostream &out, const char *fileName, int line )
{
- CodeGenData *cgd = 0;
if ( !generateDot ) {
if ( hostLang == &hostLangC )
cdLineDirective( out, fileName, line );
lineDirective( out, filter->fileName, filter->line + 1 );
}
+void XmlParser::ragel( const char *version, const char *fileName, const char *lang )
+{
+ /* Check for file name attribute. */
+ sourceFileName = fileName;
+
+ if ( generateDot )
+ outStream = dotOpenOutput( sourceFileName );
+ else if ( strcmp( lang, "C" ) == 0 ) {
+ hostLang = &hostLangC;
+ outStream = cdOpenOutput( sourceFileName );
+ }
+ else if ( strcmp( lang, "D" ) == 0 ) {
+ hostLang = &hostLangD;
+ outStream = cdOpenOutput( sourceFileName );
+ }
+ else if ( strcmp( lang, "Java" ) == 0 ) {
+ hostLang = &hostLangJava;
+ outStream = javaOpenOutput( sourceFileName );
+ }
+ else if ( strcmp( lang, "Ruby" ) == 0 ) {
+ hostLang = &hostLangRuby;
+ outStream = rubyOpenOutput( sourceFileName );
+ }
+ else if ( strcmp( lang, "C#" ) == 0 ) {
+ hostLang = &hostLangCSharp;
+ outStream = csharpOpenOutput( sourceFileName );
+ }
+ else {
+ assert( false );
+ }
+}
%%{
parser XmlParser;
include "xmlparse.kh";
-start: tag_ragel;
-start:
- final {
- /* If we get no input the assumption is that the frontend died and
- * emitted an error. This forces the backend to return a non-zero
- * exit status, but does not print an error. */
- gblErrorCount += 1;
- };
-
-tag_ragel: tag_ragel_head ragel_def_list host_or_write_list '/' TAG_ragel;
-
-tag_ragel_head: TAG_ragel
- final {
- /* Check version used to generated the intermediate file. */
- Attribute *versionAttr = $1->tag->findAttr( "version" );
- if ( versionAttr == 0 )
- error($1->loc) << "tag <ragel> requires a version attribute" << endp;
- if ( strcmp( versionAttr->value, VERSION ) != 0 )
- error($1->loc) << "version mismatch between frontend and backend" << endp;
-
- /* Check for file name attribute. */
- Attribute *fileNameAttr = $1->tag->findAttr( "filename" );
- if ( fileNameAttr == 0 )
- error($1->loc) << "tag <ragel> requires a filename attribute" << endp;
- sourceFileName = fileNameAttr->value;
-
- /* Check for language attribute. */
- Attribute *langAttr = $1->tag->findAttr( "lang" );
- if ( langAttr == 0 )
- error($1->loc) << "tag <ragel> requires a lang attribute" << endp;
-
- if ( generateDot )
- outStream = dotOpenOutput( sourceFileName );
- else if ( strcmp( langAttr->value, "C" ) == 0 ) {
- hostLang = &hostLangC;
- outStream = cdOpenOutput( sourceFileName );
- }
- else if ( strcmp( langAttr->value, "D" ) == 0 ) {
- hostLang = &hostLangD;
- outStream = cdOpenOutput( sourceFileName );
- }
- else if ( strcmp( langAttr->value, "Java" ) == 0 ) {
- hostLang = &hostLangJava;
- outStream = javaOpenOutput( sourceFileName );
- }
- else if ( strcmp( langAttr->value, "Ruby" ) == 0 ) {
- hostLang = &hostLangRuby;
- outStream = rubyOpenOutput( sourceFileName );
- }
- else if ( strcmp( langAttr->value, "C#" ) == 0 ) {
- hostLang = &hostLangCSharp;
- outStream = csharpOpenOutput( sourceFileName );
- }
- else {
- error($1->loc) << "expecting lang attribute to be "
- "one of C, D, Java, Ruby or C#" << endp;
- }
- };
+start: ragel_def_list host_or_write_list;
ragel_def_list: ragel_def_list ragel_def;
ragel_def_list: ;
std::ostream &FFlatCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FFlatCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FFlatCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FFlatCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FGotoCodeGen::EXEC_ACTIONS()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* We are at the start of a glob, write the case. */
out << "f" << redAct->actListId << ":\n";
std::ostream &FGotoCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FGotoCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FGotoCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
{
out << "\t0, ";
int totalActions = 1;
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
/* Write out the length, which will never be the last character. */
out << act->key.length() << ", ";
/* Put in a line break every 8 */
std::ostream &FTabCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FTabCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FTabCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &FTabCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &GotoCodeGen::EXEC_FUNCS()
{
/* Make labels that set acts and jump to execFuncs. Loop func indicies. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
out << " f" << redAct->actListId << ": " <<
"_acts = " << ARR_OFF(A(), itoa( redAct->location+1 ) ) << ";"
out << " case " << st->id << ": goto tr" << st->eofTrans->id << ";\n";
}
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
if ( act->eofRefs != 0 ) {
for ( IntSet::Iter pst = *act->eofRefs; pst.lte(); pst++ )
out << " case " << *pst << ": \n";
*/
/* Invoked by the parser when the root element is opened. */
-ostream *cdOpenOutput( char *inputFile )
+ostream *cdOpenOutput( const char *inputFile )
{
if ( hostLang->lang != HostLang::C && hostLang->lang != HostLang::D ) {
error() << "this code generator is for C and D only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
if ( outputFileName == 0 ) {
- char *ext = findFileExtension( inputFile );
+ const char *ext = findFileExtension( inputFile );
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
outputFileName = fileNameFromStem( inputFile, ".h" );
else {
}
/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *cdMakeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *cdMakeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *codeGen = 0;
for ( int p = 0; p < redFsm->nParts; p++ ) {
char suffix[10];
sprintf( suffix, suffFormat, p );
- char *fn = fileNameFromStem( sourceFileName, suffix );
- char *include = fileNameFromStem( sourceFileName, ".h" );
+ const char *fn = fileNameFromStem( sourceFileName, suffix );
+ const char *include = fileNameFromStem( sourceFileName, ".h" );
/* Create the filter on the output and open it. */
output_filter *partFilter = new output_filter( fn );
std::ostream &CSharpFFlatCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFFlatCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFFlatCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFFlatCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFGotoCodeGen::EXEC_ACTIONS()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* We are at the start of a glob, write the case. */
out << "f" << redAct->actListId << ":\n";
std::ostream &CSharpFGotoCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFGotoCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFGotoCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
{
out << "\t0, ";
int totalActions = 1;
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
/* Write out the length, which will never be the last character. */
out << act->key.length() << ", ";
/* Put in a line break every 8 */
std::ostream &CSharpFTabCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFTabCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFTabCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpFTabCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\tcase " << redAct->actListId+1 << ":\n";
std::ostream &CSharpGotoCodeGen::EXEC_FUNCS()
{
/* Make labels that set acts and jump to execFuncs. Loop func indicies. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
out << " f" << redAct->actListId << ": " <<
"_acts = " << itoa( redAct->location+1 ) << ";"
out << " case " << st->id << ": goto tr" << st->eofTrans->id << ";\n";
}
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
if ( act->eofRefs != 0 ) {
for ( IntSet::Iter pst = *act->eofRefs; pst.lte(); pst++ )
out << " case " << *pst << ": \n";
*/
/* Invoked by the parser when the root element is opened. */
-ostream *csharpOpenOutput( char *inputFile )
+ostream *csharpOpenOutput( const char *inputFile )
{
if ( hostLang->lang != HostLang::CSharp ) {
csharp_error() << "this code generator is for C# only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
if ( outputFileName == 0 ) {
- char *ext = findFileExtension( inputFile );
+ const char *ext = findFileExtension( inputFile );
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
outputFileName = fileNameFromStem( inputFile, ".h" );
else
}
/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *csharpMakeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *csharpMakeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *codeGen = 0;
for ( int p = 0; p < redFsm->nParts; p++ ) {
char suffix[10];
sprintf( suffix, suffFormat, p );
- char *fn = fileNameFromStem( sourceFileName, suffix );
- char *include = fileNameFromStem( sourceFileName, ".h" );
+ const char *fn = fileNameFromStem( sourceFileName, suffix );
+ const char *include = fileNameFromStem( sourceFileName, ".h" );
/* Create the filter on the output and open it. */
output_filter *partFilter = new output_filter( fn );
*/
/* Invoked by the parser when the root element is opened. */
-ostream *dotOpenOutput( char *inputFile )
+ostream *dotOpenOutput( const char *inputFile )
{
/* Make sure we are not writing to the same file as the input file. */
if ( outputFileName != 0 && strcmp( inputFile, outputFileName ) == 0 ) {
}
/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *dotMakeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *dotMakeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *codeGen = new GraphvizDotGen(out);
std::ostream &JavaTabCodeGen::ACTIONS_ARRAY()
{
ARRAY_ITEM( INT(0), false );
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
/* Write out the length, which will never be the last character. */
ARRAY_ITEM( INT(act->key.length()), false );
*/
/* Invoked by the parser when the root element is opened. */
-ostream *javaOpenOutput( char *inputFile )
+ostream *javaOpenOutput( const char *inputFile )
{
if ( hostLang->lang != HostLang::Java ) {
error() << "this code generator is for Java only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
if ( outputFileName == 0 ) {
- char *ext = findFileExtension( inputFile );
+ const char *ext = findFileExtension( inputFile );
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
outputFileName = fileNameFromStem( inputFile, ".h" );
else
}
/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *javaMakeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *javaMakeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *codeGen = new JavaTabCodeGen(out);
*/
/* Invoked by the parser when the root element is opened. */
-ostream *rubyOpenOutput( char *inputFile )
+ostream *rubyOpenOutput( const char *inputFile )
{
if ( hostLang->lang != HostLang::Ruby ) {
error() << "this code generator is for Ruby only" << endl;
/* If the output format is code and no output file name is given, then
* make a default. */
if ( outputFileName == 0 ) {
- char *ext = findFileExtension( inputFile );
+ const char *ext = findFileExtension( inputFile );
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
outputFileName = fileNameFromStem( inputFile, ".h" );
else
}
/* Invoked by the parser when a ragel definition is opened. */
-CodeGenData *rubyMakeCodeGen( char *sourceFileName, char *fsmName,
+CodeGenData *rubyMakeCodeGen( const char *sourceFileName, const char *fsmName,
ostream &out, bool wantComplete )
{
CodeGenData *codeGen = 0;
std::ostream &RbxGotoCodeGen::EXEC_FUNCS()
{
/* Make labels that set acts and jump to execFuncs. Loop func indicies. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
rbxLabel(out, label("f", redAct->actListId)) << "\n" <<
"_acts = " << itoa( redAct->location+1 ) << "\n";
START_ARRAY_LINE();
int totalActions = 0;
ARRAY_ITEM( INT(0), ++totalActions, false );
- for ( ActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
+ for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
/* Write out the length, which will never be the last character. */
ARRAY_ITEM( INT(act->key.length()), ++totalActions, false );
std::ostream &RubyFFlatCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFFlatCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFFlatCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFFlatCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFTabCodeGen::TO_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numToStateRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFTabCodeGen::FROM_STATE_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numFromStateRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFTabCodeGen::EOF_ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numEofRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";
std::ostream &RubyFTabCodeGen::ACTION_SWITCH()
{
/* Loop the actions. */
- for ( ActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
+ for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
if ( redAct->numTransRefs > 0 ) {
/* Write the entry label. */
out << "\twhen " << redAct->actListId+1 << " then\n";