public virtual string GetLexerGrammar()
{
if ( LexerGrammarTemplate.GetAttribute( "literals" ) == null &&
LexerGrammarTemplate.GetAttribute( "rules" ) == null )
{
// if no rules, return nothing
return null;
}
LexerGrammarTemplate.SetAttribute( "name", name );
IDictionary<string, object> lexerActions;
Actions.TryGetValue("lexer", out lexerActions);
// if there are any actions set for lexer, pass them in
if ( lexerActions != null )
{
LexerGrammarTemplate.SetAttribute( "actionNames",
lexerActions.Keys );
LexerGrammarTemplate.SetAttribute( "actions",
lexerActions.Values );
}
// make sure generated grammar has the same options
if ( options != null )
{
foreach ( var option in options )
{
string optionName = option.Key;
if ( !doNotCopyOptionsToLexer.Contains( optionName ) )
{
object value = option.Value;
LexerGrammarTemplate.SetAttribute( "options.{name,value}", optionName, value );
}
}
}
return LexerGrammarTemplate.Render();
}