本文整理汇总了C#中Antlr3.Codegen.CodeGenerator.GetRecognizerFileName方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Codegen.CodeGenerator.GetRecognizerFileName方法的具体用法?C# Antlr3.Codegen.CodeGenerator.GetRecognizerFileName怎么用?C# Antlr3.Codegen.CodeGenerator.GetRecognizerFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Codegen.CodeGenerator
的用法示例。
在下文中一共展示了Antlr3.Codegen.CodeGenerator.GetRecognizerFileName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenRecognizerFile
protected override void GenRecognizerFile(AntlrTool tool, CodeGenerator generator, Grammar grammar, StringTemplate outputFileST)
{
/*
Below is an experimental attempt at providing a few named action blocks
that are printed in both lexer and parser files from combined grammars.
ANTLR appears to first generate a parser, then generate an independent lexer,
and then generate code from that. It keeps the combo/parser grammar object
and the lexer grammar object, as well as their respective code generator and
target instances, completely independent. So, while a bit hack-ish, this is
a solution that should work without having to modify Terrence Parr's
core tool code.
- sharedActionBlocks is a class variable containing a hash map
- if this method is called with a combo grammar, and the action map
in the grammar contains an entry for the named scope "all",
add an entry to sharedActionBlocks mapping the grammar name to
the "all" action map.
- if this method is called with an `implicit lexer'
(one that's extracted from a combo grammar), check to see if
there's an entry in sharedActionBlocks for the lexer's grammar name.
- if there is an action map entry, place it in the lexer's action map
- the recognizerFile template has code to place the
"all" actions appropriately
problems:
- This solution assumes that the parser will be generated
before the lexer. If that changes at some point, this will
not work.
- I have not investigated how this works with delegation yet
Kyle Yetter - March 25, 2010
*/
if (grammar.type == GrammarType.Combined)
{
IDictionary<string, object> all;
if (grammar.Actions.TryGetValue("all", out all))
sharedActionBlocks[grammar.name] = all;
}
else if (grammar.implicitLexer)
{
IDictionary<string, object> shared;
if (sharedActionBlocks.TryGetValue(grammar.name, out shared))
grammar.Actions["all"] = shared;
}
generator.Templates.RegisterRenderer(typeof(string), new RubyRenderer());
string fileName = generator.GetRecognizerFileName(grammar.name, grammar.type);
generator.Write(outputFileST, fileName);
}
示例2: GenRecognizerHeaderFile
protected override void GenRecognizerHeaderFile(AntlrTool tool,
CodeGenerator generator,
Grammar grammar,
StringTemplate headerFileST,
string extName)
{
//Its better we remove the EOF Token, as it would have been defined everywhere in C.
//we define it later as "EOF_TOKEN" instead of "EOF"
IList<object> tokens = (IList<object>)headerFileST.GetAttribute("tokens");
for (int i = 0; i < tokens.Count; ++i)
{
bool can_break = false;
object tok = tokens[i];
if (tok is Aggregate)
{
Aggregate atok = (Aggregate)tok;
foreach (var pair in atok.Properties)
{
if (pair.Value.Equals("EOF"))
{
tokens.RemoveAt(i);
can_break = true;
break;
}
}
}
if (can_break)
break;
}
// Pick up the file name we are generating. This method will return a
// a file suffixed with .c, so we must substring and add the extName
// to it as we cannot assign into strings in Java.
///
string fileName = generator.GetRecognizerFileName(grammar.name, grammar.type);
fileName = fileName.Substring(0, fileName.Length - 4) + extName;
generator.Write(headerFileST, fileName);
}
示例3: GenRecognizerHeaderFile
protected override void GenRecognizerHeaderFile( AntlrTool tool,
CodeGenerator generator,
Grammar grammar,
StringTemplate headerFileST,
string extName )
{
// Pick up the file name we are generating. This method will return a
// a file suffixed with .c, so we must substring and add the extName
// to it as we cannot assign into strings in Java.
///
string fileName = generator.GetRecognizerFileName( grammar.name, grammar.type );
fileName = fileName.Substring( 0, fileName.Length - 2 ) + extName;
generator.Write( headerFileST, fileName );
}
示例4: GenRecognizerFile
protected override void GenRecognizerFile(AntlrTool tool,
CodeGenerator generator,
Grammar grammar,
StringTemplate outputFileST)
{
// Before we write this, and cause it to generate its string,
// we need to add all the string literals that we are going to match
//
outputFileST.Add("literals", strings);
string fileName = generator.GetRecognizerFileName(grammar.name, grammar.type);
generator.Write(outputFileST, fileName);
}
示例5: GenRecognizerFile
protected override void GenRecognizerFile(AntlrTool tool, CodeGenerator generator, Grammar grammar, StringTemplate outputFileST)
{
generator.Templates.RegisterRenderer(typeof(string), new RubyRenderer());
string fileName = generator.GetRecognizerFileName(grammar.name, grammar.type);
generator.Write(outputFileST, fileName);
}