eclipse / xtext

Eclipse Xtext™ is a language development framework
http://www.eclipse.org/Xtext
Eclipse Public License 2.0
768 stars 321 forks source link

Provide generator fragment for TextMate grammars #1329

Closed kthoms closed 6 months ago

kthoms commented 5 years ago

It would be useful if Xtext could provide a generator fragment that creates a tmLanguage TextMate file for the grammar. This can be useful for the creation of language server extensions that make use of TextMate grammars like VSCode. See also #1327

cdietrich commented 5 years ago

TODO:

miklossy commented 4 years ago

Hint: The YAKINDU Solidity-IDE project already contains a hand-written TextMate grammar, see solidity.tmLanguage. This could serve as a good starting point when implementing such a generator fragment.

rubenporras commented 2 years ago

Hi,

we are thinking about writing one generator fragment for TextMate grammars for our codebase. We would start with something simple (e.g. keywords, maybe comments and strings as suggested above). I think it would be nice if we could contribute it, so I would like to check beforehand what would be the criteria for inclussion.

Do you have any input?

cdietrich commented 2 years ago

having keywords, strings, ints, comments should be enhough i assume no library at all would be best. (just rich strings as for the other templates) @szarnekow what do you think`?

szarnekow commented 2 years ago

@rubenporras A contribution would be very welcome. This has been a long standing issue and it's great that you're volunteering to look into it.

Can you please help me understand why you'd need a library that serializes gson for that fragment? I thought textmate grammars are either a sort of xml dialect or a JSON file - would you plan to provide a model along with the serialization to text? Would you consider this one to be some kind of API?

If it's not too cumbersome, a plain text generation is probably the best fit for the existing abstractions.

Keywords as a starter would be fine. Strings and comments as well as other terminals can be added in a subsequent step.

A few questions:

rubenporras commented 2 years ago

Hi @szarnekow,

cdietrich commented 2 years ago

@rubenporras with you ui plugin: do you mean the .ide or the .ui plugin. in most textmate usescases like vscode there wont be a .ui plugin i guess. am not sure if tm grammars can be merged or if the generation should be a generate once.

rubenporras commented 2 years ago

@cdietrich , yes, some use cases might not have such .ui plugin, or maybe since it is small (basically the TextMate grammar and the plugin.xml to register a bunch of extension points, like a custom DocumentProvider), one would prefer to have the grammars for all supported DSLs in one plugin (i am actually thinking about that for our product). I can imagine, we could make it configurable. Regarding if grammars can be merged, at least there is an include option, so if strings and comments are the same for all DSLs in a family, a base TextMate grammar could be generated. I was planning that as long temr for our product, specially if I would write the grammars by hand.

jnt0r commented 1 year ago

Just found this. Is there any update?

cdietrich commented 1 year ago

not from my side

rubenporras commented 1 year ago

Hi @cdietrich , we have by now written this generator and have used it internally, similar to https://github.com/eclipse/xtext/pull/2639, it is not fully generic but a bit trimmed down to simplify the implementation given our needs.

Since we are now not working on it actively, I propose that we close the issue, unless you are interested in our implementation. If you are interested, I can go through the code, post the simplifications we did, and if you are still interested, see if we can do a PR.

szarnekow commented 6 months ago

A first version of it is available on main in https://github.com/eclipse/xtext/tree/main/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/textmate

szarnekow commented 6 months ago

@rubenporras Maybe you had something different in mind. We'd be happy to apply any improvements to this first version of the fragment.