stringtemplate

Example of subclassing string.Template in Python?

南笙酒味 提交于 2020-01-01 01:52:07
问题 I haven't been able to find a good example of subclassing string.Template in Python, even though I've seen multiple references to doing so in documentation. Are there any examples of this on the web? I want to change the $ to be a different character and maybe change the regex for identifiers. 回答1: From python docs: Advanced usage: you can derive subclasses of Template to customize the placeholder syntax, delimiter character, or the entire regular expression used to parse template strings. To

StringTemplate 3: how to filter a list?

两盒软妹~` 提交于 2019-12-24 17:52:39
问题 How can I remove specific elements from a list(=multi-valued-attribute) using a map? For example, let's say I want to filter out all b's in a given list: <["a", "b", "c", "b"]: {<table.(it)>}; separator=","> table ::= ["b":, default: key] The desired outcome would be "a,c" but the actual result is "a,,c," The thing is that the map successfully turn b's into nulls, but then they're wrapped in an anonymous template {} and become non-null values. So they won't go away with strip() function,

linking xtext editor support with external ANTLR parser

时光怂恿深爱的人放手 提交于 2019-12-24 12:01:49
问题 My current project (name it IoTSuite) takes high-level specifications, parses them, and generates code in Java and Android. In this project, I have written ANTLR grammar to parse the high-level specification and I have used StringTemplate for the code generator. However, due to nice editor support and syntax coloring features, I have used the xtext grammar(same as the ANTLR grammar, but it has been written in xText). Now, I perform the following three steps: Step 1: I have written xtext

StringTemplate indentation adds whitespace inside String

混江龙づ霸主 提交于 2019-12-23 21:50:07
问题 This is obviously a SSCCE. I have the following template file: xml(value)::=<< <a> <b> ^value^ </b> </a> >> ... with the following code: private static final String VALUE="alpha\nbeta"; public static void main(String args[]) throws Exception { STGroup stGroup = new STGroupFile("templates/a.xml.stg", '^', '^'); ST st = stGroup.getInstanceOf("xml"); st.add("value", VALUE); System.out.printf("--------\n%s\n--------", st.render()); } The code produces: [java] -------- [java] <a> [java] <b> [java]

Decompose expression in base operation: ANTLR + StringTemplate

流过昼夜 提交于 2019-12-23 17:30:32
问题 I am trying to write a translator for a Java like language to multiple languages. Right now I am facing 2 problems: First is to decompose complex expression in a sequence of basic operation and then translating them to destination language. For example my starting language can be: var a = (ln(b) + avg(c))*2 I'd like to traslate it like: var x1 = log_N(b); var x2 = average(c); var x3 = sum(x1, x2); var a = multiply(x3, 2); I think i have to use a Tree parser, nut I am not sure how to integrate

ValueError: Invalid placeholder in string

半城伤御伤魂 提交于 2019-12-23 12:48:24
问题 I tried to make my own template for mutate_model.py script (http://salilab.org/modeller/wiki/Mutate%20model) by using python string template where I substituted values for these five variables Model,resType,resPos,pdb,chain to replce and write a new file with values but I am getting a error like below: MyAttempt: import os import re import sys import itertools from modeller import * from docopt import docopt from string import Template from modeller.automodel import * from os.path import join

回波总

天大地大妈咪最大 提交于 2019-12-22 11:02:18
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 波总好, 在 谈谈我对 JFinal Marketing 的一些看法 那篇博文的评论中 我们谈论到了 ANTLR, 这里继续和波总谈谈在技术上我对这方面的理解. 先说下 ANTLR 到底什么. ANTLR 官网给自己的定义是: ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees. 简单地说 ANTLR 是一个词法语法分析工具, 它不是一个应用层面的库, 也不是为应用程序开发使用的. ANTLR 的用户是需要定义某种语法, 并实现对该语法文件的解析的库开发者. 对 ANTLR 的应用场景在 这篇文章 中有更多的介绍. 下面列举几个使用 ANTLR 的项目: Groovy - 解析

subclass string.Formatter

核能气质少年 提交于 2019-12-19 19:56:46
问题 Following a remark here: How to define a new string formatter, I tried subclassing string.Formatter . Here is what I've done. Unfortunately I seem to have broken it in the process import string from math import floor, log10 class CustFormatter(string.Formatter): "Defines special formatting" def __init__(self): super(CustFormatter, self).__init__() def powerise10(self, x): if x == 0: return 0, 0 Neg = x < 0 if Neg: x = -x a = 1.0 * x / 10**(floor(log10(x))) b = int(floor(log10(x))) if Neg: a =

JQuery's $ is in conflict with that of StringTemplate.Net in ASP.Net MVC

余生颓废 提交于 2019-12-17 07:16:12
问题 I am exploring ASP.NET MVC and I wanted to add jQuery to make the site interactive. I used StringTemplate, ported to .Net, as my template engine to generate html and to send JSON. However, when I view the page, I could not see it. After debugging, I've realized that the $ is used by the StringTemplate to access property, etc and jQuery uses it too to manipulate the DOM. Gee, I've looked on other template engines and most of them uses the dollar sign :(. Any alternative template engine for ASP

custom string delimiters stringtemplate-4

怎甘沉沦 提交于 2019-12-12 20:34:15
问题 I am trying to use stringtemplate-4 engine in android. But I need starting delimiter, " {{ " while ending delimiter should be, " }} " Here, I think only char delimiters are allowed. So how to use string delimiters? Thnx in advance. 回答1: StringTemplate only supports using single characters as the delimiter. This limitation is coded in several places, including but not limited to the following. The STGroup constructors, and the delimiterStartChar and delimiterStopChar fields of the same class