Template Generator
I would like to create an SQL-like language with MPS (Build 262). Later I would like to use this SQL-like language as the target language in the generation (similar to baseLanguage). So far I have managed to set up a simple structure and editor (they work for test solutions), but I am still missing the possibility to use macros in the language. This is important, since I would like SQL to be the target language of a generation.
My guess is, that I have to run the Template Generator and it will generate an editor with additional hooks for macros. So I run the Template Generator and set the Language Properties as in the attached scr1.png .
When I create a new generator -> sql, I get a broken editor : the editor only shows "" (scr2.png)
Could you give me a hint, what to look for? Maybe my language properties are not correct (e.g. "Target of Generator" has no entry)
Thanks for your help,
Matt
Attachment(s):
scr1.png
scr2.png
Please sign in to leave a comment.
Sorry for the naming-confusion:
With Template Generator I mean the "Template Editor..." in the "Generate" Menu.
Hi Matt, have you generated the template editor?
You should generate and compile java classes before editor start working.
Igor.
Thanks, my configuration was wrong. I can see the template editor now, but I still cannot manage to get the template editor with macros. I want to have an editor for generator templates, that can have macros (ctrlshiftm).
I tried the following steps:
compile the sql language, so it is up to date
generate the template editor for sql (generate->template editor from the menu)
create a new generator of my sql language
create a new root node of my sql language in the generator
an editor comes up but...
(ctrlshiftm) on property nodes or anything else does not have any effect.
Is it possible, that I did a mistake there and MPS uses the regular editor instead of the generated template editor?
Do I need to modify the generated template editor to make it work?
A few possibly related observations:
When I configure the "generate template editor" to put the editor in sql\transform, it actually puts it in sql\transform\editor.mps\sql\transform
the template editor is visible as a node in the project view after generating (in modulepool/sql/<.>/), but it disappears when I refresh the project view
Hi, yes, it seems what MPS uses regular editor. This may happen because MPS failed to find classes of the templates editor.
- make sure you do have Java classes for the template editor generated and compiled. Note that the "Generate Language" command doesn't generate Java classes for template editor (it only generates classes for structure, regular editor and types). To generate Java classes for templates editor: select the editor model in project tree then choose "Generate Form Model" in the popup menu.
- open your language properties window and make sure that path to the templates editor is shown in the "Model roots" section.
- make sure that the editor's Java class files are accessible via Java classpath. They should be either in the classpath on MPS startup or be listed in MPS project -> Settings -> Project Paths -> Classpath entries.
>> * When I configure the "generate template editor" to put the editor in
sql\transform, it actually puts it in sql\transform\editor.mps\sql\transform
Probably, this is a bug in MPS. I would recommend to manually move the model to desired location and set-up root (in language->properties->model roots) accordingly.
Igor.
Thanks Igor.
When I try to generate from my templates editor model, it complains, that the Queries file is missing. So I copy the Queries file from the base language template editor in queries-src.zip to my project and change the package name appropriately (see scr_queries.png). When I generate from my templates editor model, I still get the error msg (see scr_error.png).
Did I put Queries in the right place (see scr_queries.png)?
Any ideas?
Thanks, Matt
Attachment(s):
scr_error.png
scr_queries.png
There should be java class c.t.editor.Queries
It should be compiled and available in the classpath.
Content of c.t.editor.Queries class is similar to that in the jetbrains.mps.transformation.baseLanguage.editor.Queries.
The following rules are applied:
- the c.t.editor.Queries should extend the c.editor.Queries
- first 3 methods should be exactly as shown:
public static boolean semanticNodeCondition_IsTemplateFragmentOrHasNodeMacro(SNode node) {
return semanticNodeCondition_IsTemplateFragment(node) || semanticNodeCondition_HasNodeMacro(node);
}
public static boolean semanticNodeCondition_HasNodeMacro(SNode node) {
return node.getChild("_TL_NodeMacro") != null;
}
public static boolean semanticNodeCondition_IsTemplateFragment(SNode node) {
return TemplateLanguageUtil.isTemplateFragment(node);
}
- for each property (in language structure) add the query method such as
public static boolean semanticNodeCondition_HasPropertyMacro_(SNode node) { return node.getChild("_PropertyMacro_") != null; } (replace the with actual property name) - for each reference link (in language structure) add the query method such as public static boolean semanticNodeCondition_HasReferenceMacro_(SNode node) { return node.getChild("_ReferenceMacro_") != null; } (replace the with actual link role)
Tip!!! To get an idea what names to use open the _TemplateLinksDeclarations pseudo-concept in the c.t.editor.Queries where all PropertyMacroxxx/_ReferenceMacro_xxx are declared.
Igor.
... sorry, the __TemplateLinksDeclarations pseudo-concept is in the "c.t.editor" model.
Igor
This is great, it works.
Thanks a lot Igor. Your input has been very helpful.
Matt