无法在 TextMate 中进行自定义语法突出显示

发布于 2024-09-04 03:26:33 字数 1024 浏览 11 评论 0原文

我试图在 TextMate 中突出显示自定义语言。但是,以下定义不会突出显示 PHP 插入(我确实为我的 *.serpent 文件选择了它):

{ scopeName = 'source.serpent';
 fileTypes = ( 'serpent' );
 patterns = (
  { begin = '<\?';
   end = '\?>';
   patterns = ( { include = 'source.php'; } );
  },
 );
}

如果我选择 PHP 语言,则 PHP 部分会突出显示。

可能是什么原因?应该有效吗?

我也在考虑用 <% %> 插入红宝石分隔符,但它不适用于最简单的设置。


更新

显然,这只是 PHP 的问题。以下语言定义在我的文本中突出显示了 Ruby 和 Serpent 语言,但没有突出显示 PHP 插入!这里有什么问题吗?

{   scopeName = 'source.phpruby.serpent';
    fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
    patterns = (
        {   begin = '<\?(php|=)?';
            end = '\?>';
            patterns = ( { include = 'source.php'; } );
        },
        {   begin = '<%';
            end = '%>';
            patterns = ( { include = 'source.ruby'; } );
        },
        {   include = 'source.serpent'; },
    );
}

我通过在我的模式中用 #language 替换 source.php 并从 PHP 语言复制存储库来使其工作。

I am trying to highlight a custom language in TextMate. However, the following definition does not highlight PHP insertions (I do select it for my *.serpent files):

{ scopeName = 'source.serpent';
 fileTypes = ( 'serpent' );
 patterns = (
  { begin = '<\?';
   end = '\?>';
   patterns = ( { include = 'source.php'; } );
  },
 );
}

If I select PHP language, then the PHP parts are highlighted.

What can be the reason? Should it work?

I was also considering ruby insertions with <% %> delimiters, but it doesn't work with the simplest setup.


Update

Apparently, it is an issue of PHP only. The following language definition highlights Ruby and Serpent languages in my text, but not PHP insertions! What is wrong here?

{   scopeName = 'source.phpruby.serpent';
    fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
    patterns = (
        {   begin = '<\?(php|=)?';
            end = '\?>';
            patterns = ( { include = 'source.php'; } );
        },
        {   begin = '<%';
            end = '%>';
            patterns = ( { include = 'source.ruby'; } );
        },
        {   include = 'source.serpent'; },
    );
}

I have made it working by replacing source.php with #language in my patterns and by copying the repository from PHP language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2024-09-11 03:26:33

2010 年 7 月 9 日星期五 08:02,Allan
奥德加德
写道:

我们使 PHP 语法本身匹配
构造,所以用你的
语法,这些位已被消耗
通过包含语法,以及
因此包含的 PHP 语法将是
无操作。

我们这样做的原因是
PHP 语法可以工作
当用作根语法时,因为
很多用户坚持使用它
方式,尽管我们努力教育
;)

1
http://wiki.macromates.com/Troubleshooting/PHPSyntaxHighlight

在大神的帮助下,我理解了我的错误,并能够做出一个有效的(至少突出显示!)定义:

{   scopeName = 'source.phpruby.serpent';
    fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
    patterns = (
        {   begin = '<\?(php|=|)';
            end = '\?>';
            include = 'source.php';
        },
        {   begin = '<%';
            end = '%>';
            patterns = ( { include = 'source.ruby'; } );
        },
        {   include = 'source.serpent'; },
    );
}

On Fri, Jul 9, 2010 at 08:02, Allan
Odgaard

wrote:

We made the PHP grammar itself match
the construct, so with your
grammar, those bits have been consumed
by the including grammar, and the
included PHP grammar will therefor be
a no-op.

The reason we made it this way was so
that the PHP grammar can sort of work
when used as the root grammar, since
lots of users insist on using it that
way, despite our efforts¹ to educate
;)

¹
http://wiki.macromates.com/Troubleshooting/PHPSyntaxHighlight

With the help of the God, I understood my mistake and was able to make a working (at least highlighting!) definition:

{   scopeName = 'source.phpruby.serpent';
    fileTypes = ( 'serpent', 'serpent.php', 'serpent.erb' );
    patterns = (
        {   begin = '<\?(php|=|)';
            end = '\?>';
            include = 'source.php';
        },
        {   begin = '<%';
            end = '%>';
            patterns = ( { include = 'source.ruby'; } );
        },
        {   include = 'source.serpent'; },
    );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文