[TxMt] C bundle: Functions with multi-line argument lists

Allan Odgaard throw-away-1 at macromates.com
Mon Jun 11 19:58:57 UTC 2007


On 11. Jun 2007, at 21:28, Steve King wrote:

> On Mon, 11 Jun 2007, Allan Odgaard wrote:
>> So the problem boils down to, given just the first line of a  
>> construct, can you say what the construct is? In C you sometimes  
>> can’t, in most other languages you generally can.
> How about scanning the file backwards from the insertion point to  
> find the start of a multi-line construct whenever the parser finds  
> itself in ambiguous territory?

It would need to scan *forward* to settle the ambiguity. But this is  
where performance drops, cause if we need to scan 20 lines forward to  
get the current state, any editing in the next 20 lines would need to  
scan backwards to the point where the ambiguity was seen (since any  
edit in these 20 lines could change the outcome of what we did 20  
lines ago).

> How does it currently handle things like double-quoted strings or '/ 
> *' comments spanning lines?

The example grammar in the manual does double-quoted strings: http:// 
macromates.com/textmate/manual/language_grammars#example_grammar

Seeing a /* is not a problem because we know with 100% certainty that  
this starts a comment (if we are in a state that allows comments). As  
said the problem is with C functions where we do not know if “int”  
starts a function, nor if “int foo” does, nor if “int foo(” does,  
etc. -- we only know it when we have seen the entire thing, but since  
the look-ahead is limited to the rest of the current line, it will  
not be able to tell.

That said, people who use “simple” C should probably be able to write  
a rule for multi-line functions, just some C++ might cause a false  
positive, or some of the more esoteric flavors of function  
declarations will go unmatched.





More information about the textmate mailing list