Hi,
I'm working on a grammar for Io (www.iolanguage.com) and I've got a basic one working. I notice that in the other languages I've looked at, typing a "{" , getting the auto-paired "}" , and hitting return with the cursor in the middle, gets you a new line and the indentation decreased. Like so:
before: if(true) {}
hit return: if(true) {
}
Now, in Io, matching parens serve as block delimiters (effectively anyway). So you could have this statement:
if(true) then ( // do something )
So, I'd like to have the same behavior for parens as one gets for braces, but I can't seem to locate where this is enacted. As far as I can tell, there is no key in the grammar or language preferences to auto-expand this sequence, but I'm new to all this.
Does anyone know if this is part of the language definition system that I can control?
Thanks in advance, John
John Clayton --------------------------------------------------------------------- http://www.fivesquaresoftware.com john@fivesquaresoftware.com --------------------------------------------------------------------- CatSlapper - Manage and install multiple Tomcats
On 17/2/2006, at 21:58, John Clayton wrote:
I'm working on a grammar for Io [...]
There actually already is an Io bundle at the repository [1] (you need svn to check it out).
[...] I'd like to have the same behavior for parens as one gets for braces, but I can't seem to locate where this is enacted.
The current Io bundle does this. For the records though, the way it is achieved is by having the language grammar match empty parenthesis and have it assign a scope name to that construct (for example meta.empty-parenthesis.io).
What this then allows us is to overload keys when the caret is inside empty parenthesis, by for example using scope selector source.io meta.empty-parenthesis.io.
If you look at the existing Io bundle, you will see that there is a snippet with this scope, key equivalent set to return, and the body of the snippet is: “\n\t$0\n”, which is the sequence of text we want to have inserted, when pressing return inside empty parenthesis.
[1] http://anon:anon@macromates.com/svn/Bundles/trunk/Bundles/ Io.tmbundle/
On Feb 17, 2006, at 9:26 PM, Allan Odgaard wrote:
The current Io bundle does this. For the records though, the way it is achieved is by having the language grammar match empty parenthesis and have it assign a scope name to that construct (for example meta.empty-parenthesis.io).
But the same effect with curly braces instead of parentheses does not need any extra stuff like that, does it? How is that done, and why can't we use the same for parens?
Haris
On 18/2/2006, at 6:20, Charilaos Skiadas wrote:
The current Io bundle does this. For the records though, the way it is achieved is by having the language grammar match empty parenthesis and have it assign a scope name to that construct (for example meta.empty-parenthesis.io).
But the same effect with curly braces instead of parentheses does not need any extra stuff like that, does it? How is that done, and why can't we use the same for parens?
Ah no, the curly brace automation is hardcoded.
It could be changed to also be specified by overloading return -- I like that latter part of it. But having to put in all those language grammar rules, I'm not too fond of. One option is the talked about possibility of making a “base” language grammar for source code that all others include, but this is only of limited use, e.g. as mentioned on IRC yesterday, it would be nice to match Doxygen keywords and maybe Subversion magic words as well, but this happens in comments (well, the latter could likely be in strings), so each language would still need to have some knowledge about this (i.e. where to include the svn or Doxygen language grammar).
Adding to this, there is also the problem where a construct is both matched for behavior altering and for styling, or where it is matched simply to make the language parse correctly. For example LaTeX do parse { and }, although in this case it wouldn't conflict, because the potential base grammar would only match them, when nothing was in between.
Thanks, Alan, that's sweet, I had actually started from the one in the Io project source. There are a few changes that I could add back from what I was working on (like adding 'then', 'else', ''elseif' to keyword.control.io) if you'd be interested.
Now, fire up the moon.
John
On Feb 17, 2006, at 7:26 PM, Allan Odgaard wrote:
On 17/2/2006, at 21:58, John Clayton wrote:
I'm working on a grammar for Io [...]
There actually already is an Io bundle at the repository [1] (you need svn to check it out).
[...] I'd like to have the same behavior for parens as one gets for braces, but I can't seem to locate where this is enacted.
The current Io bundle does this. For the records though, the way it is achieved is by having the language grammar match empty parenthesis and have it assign a scope name to that construct (for example meta.empty-parenthesis.io).
What this then allows us is to overload keys when the caret is inside empty parenthesis, by for example using scope selector source.io meta.empty-parenthesis.io.
If you look at the existing Io bundle, you will see that there is a snippet with this scope, key equivalent set to return, and the body of the snippet is: “\n\t$0\n”, which is the sequence of text we want to have inserted, when pressing return inside empty parenthesis.
[1] http://anon:anon@macromates.com/svn/Bundles/trunk/Bundles/ Io.tmbundle/
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Actually, I don't have subversion installed at the moment, I snagged it off the source browser. Anyway, I put together a bundle from what I got there and the parens thing didn't actually work. Maybe grabbing it that way is bad ... Can you verify it still works (I'm testing this on TM 1.5 (906))? If so, maybe you could send me a zip of the entire bundle and I'll try it that way?
The grammar I did also fixes some issues with comment recognition and folding and I can send you the entire thing if you want to look at it/ diff it/ check it in.
Best, John
John Clayton --------------------------------------------------------------------- http://www.fivesquaresoftware.com john@fivesquaresoftware.com --------------------------------------------------------------------- CatSlapper - Manage and install multiple Tomcats
On Feb 18, 2006, at 9:37 AM, Allan Odgaard wrote:
On 18/2/2006, at 7:15, John Clayton wrote:
[...] There are a few changes that I could add back from what I was working on
Yes, please do -- just send a diff of your stuff. Should be easy to get now that you have the svn checkout.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 19/2/2006, at 1:21, John Clayton wrote:
Actually, I don't have subversion installed at the moment, I snagged it off the source browser. Anyway, I put together a bundle from what I got there and the parens thing didn't actually work. Maybe grabbing it that way is bad ... Can you verify it still works
Works fine for me.
If so, maybe you could send me a zip of the entire bundle and I'll try it that way?