[TxMt] punctuation.whitespace.function-call.leading.c

Joachim Mårtensson joachimm at etek.chalmers.se
Fri Feb 8 18:23:52 UTC 2008


So I guess I should explain why I added the leading spaces scope to the
grammar.

TextMate syntax parser works as follows,

for each line there will be a bunch of rules (the regexes in the language
files), that needs to be tested, these rules vary depending on scope and
other stuff.

the way that textmate knows which rule "wins" depends on the following,

first the start position if there is a tie the order in which the rules
are defined, determines the winner.

So how does this affect the C grammar?
the way that I differentiate between function definitions and function
calls in the C grammar, is that I start a new Scope when I encounter
{...}, inside the braces rule I place an identical rule to the function
definition matcher. Since these rules are identical there will be a tie
when looking at just the start postion of the match, so order will
determine. Outside of {...} the function-call rule will not win since it
isn't even defined there.

So what is the problem?
In short C++, there are a few constructs in C++ that looks like this

void foo(){
	std::string myString("hello world");
}

Since we want to differentiate between function-calls and variable
initialization such as the one above, we need a rule that matches those,
for technical reasons that rule needs to match the leading spaces. Trouble
is, this will make the rule win over the function-call rule, as the
leading spaces will ensure a "headstart". It does not matter that it has
lower precedence than the function-call rule.

Hopefully this explains things, If anyone can think of a better solution
please mail ideas.

To Hans and everyone interested:
Hans, I assume that you have defined a "super" grammar that includes the C
and Objective-C ones, in that case the problem is that your additional
rules gets included at the root level, and that is included after the
function-call matching inside {...}, this will probably be solvable once
Allan adds injections. Anyway perhaps you could send your grammar file and
we can decide on a format so that leading spaces will get scoped
uniformly.

Joachim Mårtensson




More information about the textmate mailing list