To create a pattern in a TextMate grammar that matches across multiple lines the "begin" and "end" keys are necessary. But is it possible to somehow restrict what is matched between the begin and the end?
I'm trying to create a pattern for the hex string literal in D. It's like a regular string literal but can only contain hex characters.
You can use a regular expression with the match key. For example in the Python bundle : { name = 'constant.numeric.integer.hexadecimal.python'; match = '\b(?i:(0x\h*))'; };
Grammar writing is well explained there : https://manual.macromates.com/en/language_grammars https://manual.macromates.com/en/language_grammars although this in in the TextMate 1 documentation.
Le 1 nov. 2015 à 20:37, Jacob Carlborg doob@me.com a écrit :
To create a pattern in a TextMate grammar that matches across multiple lines the "begin" and "end" keys are necessary. But is it possible to somehow restrict what is matched between the begin and the end?
I'm trying to create a pattern for the hex string literal in D. It's like a regular string literal but can only contain hex characters.
-- /Jacob Carlborg
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Excuse me, I wasn't very precise, however my link explains the 'pattern‘ attribute.
Le 1 nov. 2015 à 20:52, Louis Abraham louis.abraham@polytechnique.edu a écrit :
You can use a regular expression with the match key. For example in the Python bundle : { name = 'constant.numeric.integer.hexadecimal.python'; match = '\b(?i:(0x\h*))'; };
Grammar writing is well explained there : https://manual.macromates.com/en/language_grammars https://manual.macromates.com/en/language_grammars although this in in the TextMate 1 documentation.
Le 1 nov. 2015 à 20:37, Jacob Carlborg <doob@me.com mailto:doob@me.com> a écrit :
To create a pattern in a TextMate grammar that matches across multiple lines the "begin" and "end" keys are necessary. But is it possible to somehow restrict what is matched between the begin and the end?
I'm trying to create a pattern for the hex string literal in D. It's like a regular string literal but can only contain hex characters.
-- /Jacob Carlborg
textmate mailing list textmate@lists.macromates.com mailto:textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 2015-11-01 20:52, Louis Abraham wrote:
You can use a regular expression with the match key. For example in the Python bundle : {name = 'constant.numeric.integer.hexadecimal.python'; match = '\b(?i:(0x\h*))'; };
Not sure I understand what you mean. The match attribute matches on a single line, not across multiple lines. I need to match code like this:
a = x"abc2 13cd";
This is usually handled by using the "begin" and "end" attributes:
{ begin = 'x"'; end = '"'; }
But everything in between the double quotes will match.
Unfortunately, as stated at https://manual.macromates.com/en/language_grammars https://manual.macromates.com/en/language_grammars, it is not possible to make matches over more than one line. But, using the pattern attribute, you can make matches inside the match. For example, in Python :
Le 1 nov. 2015 à 20:37, Jacob Carlborg doob@me.com a écrit :
To create a pattern in a TextMate grammar that matches across multiple lines the "begin" and "end" keys are necessary. But is it possible to somehow restrict what is matched between the begin and the end?
On 2 Nov 2015, at 3:35, Jacob Carlborg wrote:
Not sure I understand what you mean. The match attribute matches on a single line, not across multiple lines. I need to match code like this:
a = x"abc2 13cd";
This is usually handled by using the "begin" and "end" attributes:
{ begin = 'x"'; end = '"'; }
But everything in between the double quotes will match.
We normally add a match for “illegal” characters in situations lile these, for example:
{ name = "string.quoted.double.hex.python"; begin = 'x"'; end = '"'; patterns = ( { name = "invalid.illegal.not-a-hex-character.python"; match = "[^\h\n]+"; } ); }
That way, if you have: `x"abcq123"` then `q` will be highlighted as illegal (most themes should give it a red background).
On 2015-11-02 02:27, Allan Odgaard wrote:
We normally add a match for “illegal” characters in situations lile these, for example:
{ name = "string.quoted.double.hex.python"; begin = 'x"'; end = '"'; patterns = ( { name = "invalid.illegal.not-a-hex-character.python"; match = "[^\h\n]+"; } ); }
That way, if you have: `x"abcq123"` then `q` will be highlighted as illegal (most themes should give it a red background).
Ah, ok. I guess that's better than nothing.