本文整理汇总了C#中Antlr3.ST.StringTemplateGroup类的典型用法代码示例。如果您正苦于以下问题:C# StringTemplateGroup类的具体用法?C# StringTemplateGroup怎么用?C# StringTemplateGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringTemplateGroup类属于Antlr3.ST命名空间,在下文中一共展示了StringTemplateGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createContent
private void createContent(String varName, Object objectToPass, StringReader reader, String outputFileName)
{
Dictionary<String, Object> map = new Dictionary<String, Object>();
map.Add(varName, objectToPass);
String outputContent = null;
StringTemplateGroup group = new StringTemplateGroup(reader);
var contentTemplate = group.GetInstanceOf("Content");
contentTemplate.Attributes = map;
outputContent = contentTemplate.ToString();
//StringBuilder sb = new StringBuilder(outputContent);
StringWriter writer = new StringWriter(new StringBuilder(outputContent));
writer.Flush();
StreamWriter fileWriter = null;
try
{
fileWriter = new StreamWriter(outputFileName + "/report.html.data");
fileWriter.Write(writer.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
writer.Close();
fileWriter.Close();
}
示例2: Generate
public void Generate(string path)
{
StringTemplateGroup group = new StringTemplateGroup("myGroup", @".\Templet");
StringTemplate st = group.GetInstanceOf("CourseHome");
int ID = 1;
st.SetAttribute("Function", AllShiftFunction);
st.SetAttribute("ProjectSum", projectSum);
foreach (var testSummary in AllTableSummary) {
st.SetAttribute("IDNum", ID++);
st.SetAttribute("Title", testSummary.title);
st.SetAttribute("Content", testSummary.attributions + "</p>" + testSummary.methodInfo);
st.SetAttribute("Index", testSummary.tableIndex);
foreach (var subSummary in AllColumnSummary)
{
if (subSummary.tableName != testSummary.tableName) continue;
st.SetAttribute("IDNum", ID++);
st.SetAttribute("Title", subSummary.title);
st.SetAttribute("Content", subSummary.attributions + "</p>" + subSummary.methodInfo);
}
}
String result = st.ToString();
StreamWriter writetext = new StreamWriter(path);
writetext.WriteLine(result);
writetext.Close();
}
示例3: GenerateSummary
//This function is used to generate the summary of whole target projet. The summary is showed in the left part of our report, the details is defined in the two HashSet above.
public void GenerateSummary(string stsum)
{
Console.WriteLine("Now let's generate summary..");
foreach(var table in db.tablesInfo)
{
table.generateDescription(db);
if (table.directMethods.Count>0 || table.columns.Find(x => x.directMethods.Count>0)!=null)
{
SingleSummary tcSummary = new SingleSummary(table.title, table.attribute, table.methodsDes,table.name,table.generateLeftIndex());
AllTableSummary.Add(tcSummary);
}
foreach(var column in table.columns)
{
column.generateDescription(db);
if (column.directMethods.Count == 0) continue;
SingleSummary tcSummary = new SingleSummary(column.title, column.attribute, column.methodsDes,table.name,"");
AllColumnSummary.Add(tcSummary);
}
}
//generating Javascript for webpage
StringTemplateGroup group = new StringTemplateGroup("myGroup", @".\Templet");
StringTemplate st = group.GetInstanceOf("GenerateScript");
foreach(var me in extractor.methodsInfo)
{
st.SetAttribute("FunctionName",TakePointOff(me.name));
st.SetAttribute("MethodFullName",me.name);
st.SetAttribute("MethodName", me.methodself.Name);
}
FinalGenerator homePageGenerator = new FinalGenerator(this.AllTableSummary, this.AllColumnSummary,st.ToString(),stsum);
homePageGenerator.Generate(outputLoc);
}
示例4: EvaluateFile
public string EvaluateFile(string fileName, IDictionary<string, object> context)
{
var stringTemplateGroup = new StringTemplateGroup("group", AppDomain.CurrentDomain.BaseDirectory);
stringTemplateGroup.ErrorListener = new StringTemplateErrorListener();
StringTemplate stringTemplate = stringTemplateGroup.GetInstanceOf(fileName, context);
return stringTemplate.ToString();
}
示例5: View
static View()
{
Group = new StringTemplateGroup("Views", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views"))
{
RefreshInterval = CachingIsEnabled() ? new TimeSpan(1, 0, 0) : TimeSpan.Zero
};
}
示例6: FuncProtoToShimParser
public FuncProtoToShimParser(string templatefile, ITokenStream input)
: this(input, new RecognizerSharedState())
{
using (TextReader tr = new StreamReader(templatefile))
{
TemplateGroup = new StringTemplateGroup(tr);
tr.Close();
}
}
示例7: generate
/// <summary>Generate metadata repository and source files.</summary>
private void generate() {
// Clear repository
Repository.Clear();
Repository.TypesMapper.AddRange(this.TemplateInfo.TypesMap);
foreach (BplPackage pkg in this.packages) {
Repository.AllPackages.Add(pkg.CanonicName, pkg);
}
string appDir = Path.GetDirectoryName(Application.ExecutablePath);
string tmpDir = Path.Combine(appDir, "Templates");
Type lexarType = (this.TemplateInfo.Lexer.Equals("$"))
? typeof(Antlr3.ST.Language.TemplateLexer)
: typeof(Antlr3.ST.Language.AngleBracketTemplateLexer);
// Read group from file
using (StreamReader sr = new StreamReader(this.TemplateInfo.GroupFile)) {
this.stGroup = new StringTemplateGroup(sr, lexarType);
}
// Filter packages
List<BplPackage> packages = this.packages.Where<BplPackage>(pkg => this.TemplateInfo.IsMatch(pkg.CanonicName)).ToList<BplPackage>();
// Build class metadata
packages.Apply<BplPackage>(pkg => {
this.notifyAction("Generating package {0} ...", pkg.Name);
pkg.Classes.Apply<BplClass>(cls => new MetaClass(cls));
});
foreach (TemplateCommand tc in this.TemplateInfo.RunCommands) {
if (tc.Level == TemplateLevel.Root) {
// Generate root level source code
this.generateRootFile(tc.TemplateName, tc.RelativeFolder, tc.FilePattern);
} else if (tc.Level == TemplateLevel.Package) {
// Generate packages source code
Repository.RegisteredPackages.Values.Apply<BplPackage>(pkg => this.generatePackageFile(pkg, tc.TemplateName, tc.RelativeFolder, tc.FilePattern));
} else if (tc.Level == TemplateLevel.Class) {
// Generate classes source code
Repository.RegisteredClasses.Values.Apply<MetaClass>(cls => { this.generateClassFile(cls, tc.TemplateName, tc.RelativeFolder, tc.FilePattern); });
} else if (tc.Level == TemplateLevel.Primitive) {
// Generate primitives source code
Repository.RegisteredPrimitives.Values.Apply<MetaPrimitive>(prv => { this.generatePrimitiveFile(prv, tc.TemplateName, tc.RelativeFolder, tc.FilePattern); });
} else if (tc.Level == TemplateLevel.Enum) {
// Generate primitives source code
Repository.RegisteredEnums.Values.Apply<MetaEnum>(enm => { this.generateEnumFile(enm, tc.TemplateName, tc.RelativeFolder, tc.FilePattern); });
} else {
throw new Exception("Unrecognized value");
}
}
// Notify user about end of process
MessageBox.Show("Code files generated successfully.");
}
示例8: RenderTemplate
public string RenderTemplate(string groupName, string groupPath, string templateName, IEnumerable<KeyValuePair<string, object>> templateData)
{
var templateGroup = new StringTemplateGroup(groupName, groupPath);
var template = templateGroup.GetInstanceOf(templateName);
foreach(var d in templateData)
{
template.SetAttribute(d.Key, d.Value);
}
template.RegisterRenderer(typeof(DateTime), new DateRenderer());
template.RegisterRenderer(typeof(String), new BasicFormatRenderer());
return template.ToString();
}
示例9: getHtmlDescribe
//This method would generate the description of this method and we could show the description in the final report.
public string getHtmlDescribe(List<string> allSql, string TorC, string optType)
{
string htmlText = "";
StringTemplateGroup group = new StringTemplateGroup("myGroup", @".\Templet");
StringTemplate st = group.GetInstanceOf("MethodDes");
st.SetAttribute("FunctionName", TakePointOff(name));
st.SetAttribute("MethodFullName", name);
st.SetAttribute("MethodName", methodself.Name);
st.SetAttribute("MethodSum", swumsummary);
if (allSql != null)
{
foreach (var singleSql in allSql)
{
var tempText = translateStmt(singleSql, TorC, optType);
if (tempText == "") continue;
st.SetAttribute("SQLs", translateStmt(singleSql, TorC, optType));
}
}
htmlText = st.ToString();
return htmlText;
}
示例10: run
//This method would generate the summary for the project and prepare all the other data for final report.
public void run()
{
Console.WriteLine("Starting collecting data for reporter");
StringTemplateGroup group = new StringTemplateGroup("myGroup", @".\Templet");
StringTemplate stsum = group.GetInstanceOf("ProjectSummary");
int tableCount = 0;
int totalCount = 0;
foreach (var tempT in db.tablesInfo)
{
if (tempT.directMethods.Count > 0) { tableCount++; totalCount++; }
foreach (var tempC in tempT.columns)
{
if (tempC.directMethods.Count > 0) totalCount++;
}
}
stsum.SetAttribute("TableNumber", tableCount);
stsum.SetAttribute("AllNumber", totalCount);
stsum.SetAttribute("MethodNumber", extractor.allDirectMethods.Count);
GenerateSummary(stsum.ToString());
}
示例11: Generate
/// <summary>
/// Given the output report path, generate HTML-formate report for the target project.
/// </summary>
/// <param name="path">Report location</param>
public void Generate(string path)
{
List<string> methodFullNameAndParams = new List<string>();
StringTemplateGroup group = new StringTemplateGroup("myGroup", Constants.TemplatesLoc);
StringTemplate st = group.GetInstanceOf("Home");
st.SetAttribute("ProjName", this.projName);
st.SetAttribute("NUM_DB_METHODS", this.num_db_methods);
st.SetAttribute("NUM_TOTAL_METHODS", this.num_total_methods);
st.SetAttribute("NUM_SQL_OPERATING", this.num_sql_operating);
st.SetAttribute("NUM_LOCAL", this.num_local);
st.SetAttribute("NUM_DELEGATED", this.num_delegated);
foreach (string methodTitle in allMethodTitles)
{
string[] tokens = methodTitle.Split(new string[] { "] " }, StringSplitOptions.None);
string methodHeader = tokens[1];
methodFullNameAndParams.Add(methodHeader);
string methodDescription = allMethodFullDescriptions[methodTitle];
st.SetAttribute("IDNum", globalMethodHeaderToIndex[methodHeader]);
st.SetAttribute("MethodSignature", methodTitle);
//st.SetAttribute("SourceCode", "...");
//st.SetAttribute("SwumDesc", "xxx");
st.SetAttribute("MethodBodyDesc", methodDescription);
//allMethodSigniture.Add(methodTitle);
}
methodFullNameAndParams.Sort();
//hyper index
foreach (string mh in methodFullNameAndParams)
{
st.SetAttribute("MethodLinkID", mh);
}
//st.SetAttribute("Message", "hello ");
String result = st.ToString(); // yields "int x = 0;"
//Console.WriteLine(result);
StreamWriter writetext = new StreamWriter(path);
writetext.WriteLine(result);
writetext.Close();
}
示例12: StringTemplateViewEngine
/// <summary>
/// Creates a new instance of the StringTemplateViewEngine
/// </summary>
/// <param name="viewPath">The physical path to the root views directory</param>
public StringTemplateViewEngine(string viewPath)
{
Group = new StringTemplateGroup("views", viewPath);
}
示例13: button1_Click
private void button1_Click(object sender, EventArgs e)
{
/*StringTemplate template = new StringTemplate(txtTemplate.Text);
template.SetAttribute(txtName.Text, txtValue.Text);
template.SetAttribute(txtName2.Text, txtValue2.Text);
txtOutput.Text = template.ToString();
*/
System.IO.TextReader tr = new System.IO.StreamReader("stellar_test_group.stg");
StringTemplateGroup stg = new StringTemplateGroup(tr,typeof(TemplateLexer)); //lexer added to use $..$ in group templates instead of <..>
StringTemplate st = stg.GetInstanceOf("E57_URI");
StringTemplate st2 = stg.GetInstanceOf("E19_URI");
StringTemplate st3 = stg.GetInstanceOf("E57");
StringTemplate st4 = stg.GetInstanceOf("E19");
st2.SetAttribute("site", "molas");
st2.SetAttribute("id", "12345");
st3.SetAttribute("site", "molas");
st3.SetAttribute("id", "12345");
st4.SetAttribute("uri", st2.ToString());
String s = st3.ToString();
txtOutput.Text = s;
}
示例14: dlgOpenTemplate_FileOk
private void dlgOpenTemplate_FileOk(object sender, CancelEventArgs e)
{
System.IO.TextReader tr;
txtTemplateFileName.Text = dlgOpenTemplate.FileName;
using(tr = new System.IO.StreamReader(dlgOpenTemplate.FileName))
{
//tr = new System.IO.StreamReader(dlgOpenTemplate.FileName);
stg = new StringTemplateGroup(tr, typeof(TemplateLexer)); //lexer added to use $..$ in group templates instead of <..>
//StringTemplate st = stg.GetInstanceOf("E57_URI");
lstTemplates.Items.Clear();
ICollection < String > names = stg.GetTemplateNames();
//foreach (StringTemplate st in stg.Templates)
foreach (String s in names)
{
lstTemplates.Items.Add (s);
}
tr.Close();
}
}
示例15: TestCannotFindInterfaceFile
public void TestCannotFindInterfaceFile()
{
// this also tests the group loader
IStringTemplateErrorListener errors = new ErrorBuffer();
string tmpdir = Path.GetTempPath();
StringTemplateGroup.RegisterGroupLoader( new PathGroupLoader( tmpdir, errors ) );
string templates =
"group testG implements blort;" + newline +
"t() ::= <<foo>>" + newline +
"bold(item) ::= <<foo>>" + newline +
"duh(a,b,c) ::= <<foo>>" + newline;
WriteFile( tmpdir, "testG.stg", templates );
StringTemplateGroup group =
new StringTemplateGroup( new StreamReader( tmpdir + "/testG.stg" ), errors );
string expecting = "no such interface file blort.sti";
Assert.AreEqual( expecting, errors.ToString() );
}