stringtemplate

String Template: make all variable declaration global

元气小坏坏 提交于 2019-12-07 13:53:12
问题 I am trying to implement a translator using ANTLR+StringTemplate. I have a starting language that is java like and multiple destination language. I used the example: http://www.antlr.org/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate One of my destination language needs all variables to be declared globally. I wrote a grammar that recognizes variables, but i cannot find e way in my template for making a local variable to be declared globally. Of course if I would have

embed java code inside a template

可紊 提交于 2019-12-06 23:42:34
Is it possible to embed executable java code inside a ST4 template? eg if I want to pass a string to my template, which sometimes prints the string as-is, and sometimes prints it in caps, so I want a java code to do the necessary conversion. Without this feature, I see 3 ways to achieve the same functionality: (1) pre-compute the alternative values in java, and pass them all to the template at one shot (but this may result in too many arguments): // in the below code, if the template can compute DESCRIPTION_CAPS from DESCRIPTION, using embedded java code, that reduces one argument test

Working example of wikitext-to-HTML in ANTLR 3

*爱你&永不变心* 提交于 2019-12-06 11:47:35
问题 I'm trying to flesh out a wikitext-to-HTML translator in ANTLR 3, but I keep getting stuck. Do you know of a working example that I can inspect? I tried the MediaWiki ANTLR grammar and the Wiki Creole grammar, but I can't get them to generate the lexer & parser in ANTLR 3. Here are the links to two grammars I've tried using: http://www.mediawiki.org/wiki/Markup_spec/ANTLR http://www.wikicreole.org/wiki/EBNFGrammarForCreole1.0 I can't get any of these two to generate my Java Lexer and Parser.

Custom format functions for StringTemplate4

不问归期 提交于 2019-12-06 07:28:42
I would like to know how to create a custom format function for string template. Let say I have the following code: render(attributes) :: << <html> $atributes: { <div> $customformat(atribute.name)$</div> } </html> >> customformat(name) ::= << $name; format="upper"$ >> Currently the behaviour of the function customformat is: Input: "hello world" -> Output: "HELLO WORLD" And I would like to modify the customformat function so the output is something like the following: Input: "hello world" -> Output: "HELLO_WORLD" Andy Stabler As far as I'm aware this isn't possible, since StringTemplate is all

使用线程池+队列实现异步处理业务问题

跟風遠走 提交于 2019-12-06 06:50:22
背景 当系统中的业务存在大量的相同任务(比如发送大量邮件),并且每个任务花费的时间也比较长,前段需要较快 的响应,针对这种需求,我们可以采用消息队列进行异步通知,同时也可以采用线程池+内存队列实现异步通知,处理业务问题。 代码实现 以下采用发送邮件作为demo 邮箱实体类 @Data public class Email implements Serializable { private static final long serialVersionUID = 1L; /** * 自增主键 */ private Long id; /** * 接收人邮箱(多个逗号分开) */ private String receiveEmail; /** * 主题 */ private String subject; /** * 发送内容 */ private String content; /** * 模板 */ private String template; /** * 发送时间 */ private Timestamp sendTime; } 邮件队列 public class MailQueue { //队列大小 static final int QUEUE_MAX_SIZE = 1000; static BlockingQueue<Email> blockingQueue = new

Antlr4 language translation - separating template logic from visitor class?

微笑、不失礼 提交于 2019-12-06 05:56:23
问题 I’m looking at pragmatically translating huge amounts of relatively simple TSQL code to Groovy code. There are a number of reasons sure, but the driving reason is just to see if it can be done and in the process learn about compilers/grammers/ etc. Antlr4 seems like the ideal tool for this problem (Java is a plus). Tokenizing / parsing the TSQL (using a grammar file), and reading the tree using the generated Listener/Visitor is pretty straight forward. I know I could just create the string

String Template: make all variable declaration global

十年热恋 提交于 2019-12-06 02:17:00
I am trying to implement a translator using ANTLR+StringTemplate. I have a starting language that is java like and multiple destination language. I used the example: http://www.antlr.org/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate One of my destination language needs all variables to be declared globally. I wrote a grammar that recognizes variables, but i cannot find e way in my template for making a local variable to be declared globally. Of course if I would have just one translation I would be able to do it, but I have multiple translation and some of them have local

NoIndentWriter not respecting whitespace in template

青春壹個敷衍的年華 提交于 2019-12-05 16:09:31
I am trying to use the NoIndentWriter class to get around a problem I am facing related to the inserting of whitespace in multiline Strings . However, it appears that NoIndentWriter does a lot more than just not auto-indenting. In particular it trims all leading (but not trailing whitespace) even if explicitly present in a template. E.g. with the following template file: $ cat src/templates/a.xml.stg ladder(value)::=<< 0 1 2 3 ^value^ >> ... and the following code: public static void main(String args[]) throws Exception { STGroup stGroup = new STGroupFile("templates/a.xml.stg", '^', '^'); ST

Format date in String Template email

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:27:35
I'm creating an email using String Template but when I print out a date, it prints out the full date (eg. Wed Apr 28 10:51:37 BST 2010). I'd like to print it out in the format dd/mm/yyyy but don't know how to format this in the .st file. I can't modify the date individually (using java's simpleDateFormatter) because I iterate over a collection of objects with dates. Is there a way to format the date in the .st email template? Use additional renderers like this: internal class AdvancedDateTimeRenderer : IAttributeRenderer { public string ToString(object o) { return ToString(o, null); } public

Which Java MVC frameworks integrate easily with StringTemplate?

跟風遠走 提交于 2019-12-04 17:11:29
问题 It's hard to see how StringTemplate integrates easily (or not) with popular Java web MVC frameworks. Which Java MVC frameworks integrate easily with StringTemplate? A good answer: mentions one solution to integrate with a framework, includes a link to something useful and applicable, like: a tutorial , or documentation , or a reference to source code : free , and open source or public domain . Readers/Voters , please vote for a solution if you know it's true and great. In the scope of this