Bug 178170 - [templates] Template variable pattern
Summary: [templates] Template variable pattern
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2007-03-19 23:10 EDT by icemank CLA
Modified: 2007-03-28 08:49 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description icemank CLA 2007-03-19 23:10:27 EDT
Currently, the code templates support forces variables to be indicated in the template text as enclosed between "${" and "}", e.g., "${date}".
However, I have created a plugin for the NSIS scripting language in which ${ xyz} is a valid language construct, hence I would like to indicate variables using a different pattern, i.e., enclosed between % symbols, e.g., "%date%".
However, the jface template source code has the template pattern hard-coded to using the "${xyz}" pattern.
Please enhance the template support to accept other variable patterns.
Comment 1 Tod Creasey CLA 2007-03-20 11:48:22 EDT
Where is the JFace template support code you are referring to?
Comment 2 icemank CLA 2007-03-20 21:56:17 EDT
org.eclipse.jface.text.templates in the org.eclipse.text plugin.
Specifically, org.eclipse.jface.text.templates.TemplateTranslator has the following Regex pattern defined for detecting variables:
	private static final Pattern ESCAPE_PATTERN= Pattern.compile("\\$\\$|\\$\\{\\s*+(\\w*+)\\s*+(?::\\s*+((?:\\w++\\.)*\\w++)\\s*+(?:\\(\\s*+((?:(?:\\w++\\.)*\\w++\\s*+,\\s*+)*(?:\\w++\\.)*\\w++)\\s*+\\))?\\s*+)?\\}|\\$"); //$NON-NLS-1$

Also, the parse(String string) method has the "$" character hard-coded for detecting template variable starts.
Comment 3 Dani Megert CLA 2007-03-21 08:30:29 EDT
You can escape the '$' with another '$', e.g. in your case simply enter $${xyz}
Comment 4 icemank CLA 2007-03-21 21:44:18 EDT
I understand that. However my concern is that it may be confusing to the end user.
Never mind, I can cannibalize the existing implementation and create something that functions the way I want.
Comment 5 Dani Megert CLA 2007-03-22 04:21:12 EDT
If this is important for you, then you might want to implement the correct solution and contribute it back to the Eclipse project. If I get a good quality patch I would accept it.
Comment 6 icemank CLA 2007-03-27 15:01:16 EDT
Well, the easiest way is to:
a) Allow clients to override the parse() method of TemplateTranslator
b) Make the constructors of TemplateVariableType public.
Comment 7 icemank CLA 2007-03-27 21:37:28 EDT
Actually, now that I look at it, there is no need to make the constructors of TemplateVariableType public.
However, is there any particular reason why you don't want clients to override the translate() methods of TemplateTranslator?
I have been able to implement what I need simply by overriding the translate() methods.
Comment 8 Dani Megert CLA 2007-03-28 03:32:34 EDT
>However, is there any particular reason why you don't want clients to override
>the translate() methods of TemplateTranslator?
The main reason is that the string representation in the TemplateBuffer is created by the internal parser and if clients can provide that string it could later break the framework when the proposal is applied.
Comment 9 icemank CLA 2007-03-28 08:38:42 EDT
I am not quite sure I understand why, but I'll take your word for it.
As far as I can see, if parse() returns a valid TemplateBuffer which can be resolved using the registered resolvers for the TemplateVariables within the buffer, then there should not be a problem.
Perhaps I am missing something.
Never mind.
Comment 10 Dani Megert CLA 2007-03-28 08:49:15 EDT
We would have to go trough our code and make sure that everywhere where we use the string from the TemplateBuffer we do not rely on the format currently generated by the internal parse() method. I'm not saying it can't be done.