[TxMt] C based grammars broken for embedding (restricting $base reference) [TM1 & TM2]

Adam Strzelecki ono at java.pl
Thu Dec 29 23:45:12 UTC 2011


Since C grammar is intended to be the base for other grammars such as C++ or Obj-C it uses `include = '$base'` instead of `include = '$self'` for all recursive sub-block parsing to point back to original grammar (if possible). This works perfectly well for standalone C or C++ file, however when trying to embed C source into other language we get a problem, i.e. for Ruby grammar:

# trying to embed something into Ruby
variable = <<-C
/* we are parsed by C grammar here */
enum {
  /* ooops this comment isn't parsed anymore by C grammar but Ruby again! */
}
C

Problem is on '{' which starts new C block, that does `include = '$base'`. Unfortunately $base is Ruby here not C. Same if we change C into CPP in the example above, $base is still Ruby.

I can see two solutions here:
(1) caller should be able to block/change $base i.e. using some new keyword:

{ safeInclude = 'source.c'; }
or
{ base = 'source.c'; include = 'source.c'; }

(2) callee should be able to specify language grammars that are allowed to be base for it.

Or maybe there's already some undocumented solution?

Cheers,
-- 
Adam Strzelecki



More information about the textmate mailing list