[TxMt] Re: Composable grammars
Jacob Carlborg
doob at me.com
Sun Apr 10 16:38:02 UTC 2016
On 2016-04-10 16:43, Allan Odgaard wrote:
> Just to be sure I understand, you would like to define somewhere in the
> grammar how e.g. an identifier looks (regex) and then in other patterns,
> say a function prototype, be able to insert this definition (in the full
> regex for the function prototype)?
Kind of.
> If so, have a look at this proposal:
> https://github.com/textmate/textmate/pull/1276#issuecomment-63450941 and
> let me know if that fits your needs.
I've looked at that before. It's difficult to tell if it fits my needs
without trying it.
It's question of how well it scales and how it's implement. I would
prefer to define rules in the TextMate grammar that exactly matches the
rules in the official grammar of a language. For that it would require
many variables and many levels deep.
It will no work by just providing some syntax that allows to interpolate
the regular expression. I tried that. I've even create a full Ruby DSL
[1] to describe TextMate grammars. It worked great until TextMate choke
on the generated regular expression being too long. I gave up when it
took 15 seconds to load language.
Here's an example using that Ruby DSL to describe an integer literal
[2]. That might give you and idea of what I'm after.
[1] https://github.com/jacob-carlborg/tm_grammar/tree/dev
[2]
https://github.com/jacob-carlborg/d.tmbundle/blob/reboot_grammar/Syntaxes/rules/integer_literal.tm_lang.rb
--
/Jacob Carlborg
More information about the textmate
mailing list