Hello,
I'm trying to enhance the Matlab bundle. Especially by trying to make matlab and texmate to interact (shortcut to launch a script etc...). And I must say I'm pretty bad with shell scripts and regular expressions.
I've nevertheless managed to do that, and now I'm trying to recreate matlab "cell mode" : matlab source files are scripts, and it is possible to divide the script in "cells". When you are in the (awful) matlab editor, you can run the current cell just with cmd+enter. This is very useful. The problem is that the cell separator is just a line like this :
%% Title of the new cell
...That's it, there is no ending marker for a cell : the current cell ends where the new one starts ! What I've done now is creating a new "cell" scope delimited by these lines, but as soon as one "%% ...." line is used to mark the end of a scope, it can't be used to start the following one.
Here's my descriptor.
contentName = 'meta.cell.matlab'; begin = '%%.*$\n'; end = '%%.*$\n'; captures = { 0 = { name = 'meta.celltitle.matlab'; }; }; patterns = ( # Here I include all the other scope descriptors, because they can be contained in a cell ! )
For my solution to work, I then have to use two of these "%% ..." lines, one to end the previous cell scope, and one to start the new one. This means matlab files need to be modified to work, which is not so good !
Do you have an idea on how to solve this problem ? A linked problem (but less important) is that I can't get code folding to work with cells : a start marker can't be the same as an end marker.
Thank you !
Le 16 mars 09 à 10:44, Pierre Morel a écrit :
Hello,
I'm trying to enhance the Matlab bundle. Especially by trying to make matlab and texmate to interact (shortcut to launch a script etc...). And I must say I'm pretty bad with shell scripts and regular expressions.
I've nevertheless managed to do that, and now I'm trying to recreate matlab "cell mode" : matlab source files are scripts, and it is possible to divide the script in "cells". When you are in the (awful) matlab editor, you can run the current cell just with cmd+enter. This is very useful. The problem is that the cell separator is just a line like this :
%% Title of the new cell
...That's it, there is no ending marker for a cell : the current cell ends where the new one starts ! What I've done now is creating a new "cell" scope delimited by these lines, but as soon as one "%% ...." line is used to mark the end of a scope, it can't be used to start the following one.
Here's my descriptor.
contentName = 'meta.cell.matlab'; begin = '%%.*$\n'; end = '%%.*$\n'; captures = { 0 = { name = 'meta.celltitle.matlab'; }; }; patterns = ( # Here I include all the other scope descriptors, because they can
be contained in a cell ! )
For my solution to work, I then have to use two of these "%% ..." lines, one to end the previous cell scope, and one to start the new one. This means matlab files need to be modified to work, which is not so good !
Do you have an idea on how to solve this problem ? A linked problem (but less important) is that I can't get code folding to work with cells : a start marker can't be the same as an end marker.
Thank you !
What about look-behind? The expression (?=%%) check that the next two characters indeed are %%, but don’t consume then. Look-ahead, which check the previous characters, is written (?<=subexp) and both come with negative versions — check that the character are *not* something.
More information in the manual: http://manual.macromates.com/en/regular_expressions
Watch out for grammar bugs, however. It’s easy to make TM crash if you write things like:
begin = '(?=a)' end = '(?=b)'
because neither expression consume a character. Thus the expression ab matches the rule, no character is consumed and the string is left similar. And still matches the rule, so TM loop.
Édouard GILBERT edouard.gilbert@gmail.com
On 16 Mar 2009, at 11:01, Édouard Gilbert wrote:
[...] Watch out for grammar bugs, however. It’s easy to make TM crash if you write things like:
begin = '(?=a)' end = '(?=b)'
because neither expression consume a character. [...]
For the records, you’d need to make it:
begin = '(?=a)' end = '(?=a)'
Here, if the ‘patterns’ active between begin/end do not consume anything, we have the infinite loop. In your example the parser would have advanced to “just before b”, so the same rule would not be applicable at the same position.
Le 19 mars 09 à 19:00, Allan Odgaard a écrit :
On 16 Mar 2009, at 11:01, Édouard Gilbert wrote:
[...] Watch out for grammar bugs, however. It’s easy to make TM crash if you write things like:
begin = '(?=a)' end = '(?=b)'
because neither expression consume a character. [...]
For the records, you’d need to make it:
begin = '(?=a)' end = '(?=a)'
Here, if the ‘patterns’ active between begin/end do not consume anything, we have the infinite loop. In your example the parser would have advanced to “just before b”, so the same rule would not be applicable at the same position.
Actually, I ran into the problem with both look-ahead and look behind, as in
begin = '(?<=a)' end = '(?=b)'
so I didn’t thought of that. It might help with some trouble I have on a grammar. Cheers.
While we’re discussing language grammars, I was wondering if we could hope some lexer-like capabilities in TM2.0 — I to have regexes everywhere in my grammars, they make anything barely readable.
And, on quite but not that much unrelated matters, what would be the better way to match something like:
a
I can apply set of rule A
b
I can apply set of rule B
c
My current is
begin = 'a' end = '(?<=c)' patterns= ( { begin = '(?<=a)' end = 'b' patterns = ( A ) begin = '(?<=b)' end = 'c' patterns = ( B ) }
but the restrictions on look-ahead bug me.
begin = '(?=a)' end = 'c' patterns= ( { begin = 'a' end = '(?=b)' patterns = ( A ) begin = 'b' end = '(?=c)' patterns = ( B ) }
might be a better solution. Or is there a efficient and elegant solution I didn't think of?
Édouard GILBERT edouard.gilbert@gmail.com
On 19 Mar 2009, at 20:10, Édouard Gilbert wrote:
[…] While we’re discussing language grammars, I was wondering if we could hope some lexer-like capabilities in TM2.0 — I to have regexes everywhere in my grammars, they make anything barely readable.
The feature set is sort of closed for 2.0, but there should be 2.1 etc. so; what exactly do you mean/propose? I realize that idealized EBNF looks nicer than a TM grammar, but in practice it is not (IMHO).
And, on quite but not that much unrelated matters, what would be the better way to match something like:
a
I can apply set of rule A
b
I can apply set of rule B
c
My current is […]
I am confused as to the size of your scopes.
Is each letter starting a new scope, so b is nested inside a, and c is nested inside b (nested inside a)?
Le 8 avr. 09 à 21:59, Allan Odgaard a écrit :
On 19 Mar 2009, at 20:10, Édouard Gilbert wrote:
[…] While we’re discussing language grammars, I was wondering if we could hope some lexer-like capabilities in TM2.0 — I to have regexes everywhere in my grammars, they make anything barely readable.
The feature set is sort of closed for 2.0, but there should be 2.1 etc. so; what exactly do you mean/propose? I realize that idealized EBNF looks nicer than a TM grammar, but in practice it is not (IMHO).
And, on quite but not that much unrelated matters, what would be the better way to match something like:
a
I can apply set of rule A
b
I can apply set of rule B
c
My current is […]
I am confused as to the size of your scopes.
Is each letter starting a new scope, so b is nested inside a, and c is nested inside b (nested inside a)?
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Édouard GILBERT edouard.gilbert@gmail.com
Sorry about last mail, I clicked “send” instead of “minimize”.
Le 8 avr. 09 à 21:59, Allan Odgaard a écrit :
On 19 Mar 2009, at 20:10, Édouard Gilbert wrote:
[…] While we’re discussing language grammars, I was wondering if we could hope some lexer-like capabilities in TM2.0 — I to have regexes everywhere in my grammars, they make anything barely readable.
The feature set is sort of closed for 2.0, but there should be 2.1 etc. so; what exactly do you mean/propose? I realize that idealized EBNF looks nicer than a TM grammar, but in practice it is not (IMHO).
And, on quite but not that much unrelated matters, what would be the better way to match something like:
a
I can apply set of rule A
b
I can apply set of rule B
c
My current is […]
I am confused as to the size of your scopes.
Is each letter starting a new scope, so b is nested inside a, and c is nested inside b (nested inside a)?
Actually, ‘a’ opens a scope A, ‘b’ both closes A and opens another scope B, which is then closed by ’c’. Note that while I’m interested in scopes, I’m even more interested in grammars development.
An actual example could help: <a # opens a scope for autocompletion of attributes of tag a
# closes the attributes scope and open a scope for autocompletion
of every possible child of a
</a> # closes everything.
Writing directly
</a> is of course meaningless.
A third scope, which opens with <a and closes with </a> might also be useful.
Édouard GILBERT edouard.gilbert@gmail.com
On 8 Apr 2009, at 23:11, Édouard Gilbert wrote:
[...] Actually, ‘a’ opens a scope A, ‘b’ both closes A and opens another scope B, which is then closed by ’c’. Note that while I’m interested in scopes, I’m even more interested in grammars development.
An actual example could help: <a # opens a scope for autocompletion of attributes of tag a
# closes the attributes scope and open a scope for autocompletion
of every possible child of a
</a> # closes everything.
Writing directly
</a> is of course meaningless.
A third scope, which opens with <a and closes with </a> might also be useful.
There are several ways to tackle this, but no ideal way, i.e. they all have pros/cons.
I’d probably approach it something like this:
begin = "(?=<(\w+))" # general tag begin = "<a\b" # it was an <a …> tag end = ">" # we leave when seeing > include = #attr_rules
begin = "(?!</)(?<=>)" # we just left previous rule and is inside the actual tag content end = "(?=</)" # we leave when we see an end tag include = $self
end = "</$1>" # leave the general tag
This is probably where you got a infinite loop, I made a negative look- ahead assertion on the second inner rule, as it would otherwise fail on data like: <a></b>.
I didn’t test this, and as said, this is just one approach to a problem that does not have an obvious solution, Michael Sheets probably can tell you a lot more about the pros/cons of the various approaches.