【问题标题】:Full list of sublime text heredoc tags?崇高文本heredoc标签的完整列表?
【发布时间】:2020-11-21 02:49:54
【问题描述】:

我注意到sublime text automatically recognises certain heredoc tags 并相应地突出了语法。

这是一个简单的例子,第一个 heredoc 知道根据 SQL 突出显示语法,但第二个不知道,即使它的内容相同。因此可以推断 sublime '知道'第一个是 SQL 因为heredoc标签是SQL)。

问题:可用的 heredoc 标签的完整列表是什么?

注意:这是在 ruby​​ heredoc 中,但我想它可能也适用于其他语言,尽管我无法确认。

【问题讨论】:

    标签: ruby sublimetext3


    【解决方案1】:

    这是正在使用的语法定义的函数(在您的情况下,是 Ruby 语法)。或者,如果您愿意的话,这不是在任何地方都可以使用的东西,一种语言必须专门支持它。

    因此,此类 heredocs 的列表确实受限于一个已知列表,为了了解您需要查看相关语言的语法定义。

    对于 Ruby(自 build 3211 起),该列表为 HTMLSQLCSSJS(或 JAVASCRIPT)和 RUBY。在构建 4092 中,语法还包括 SH(或 SHELL)。所有其他人(例如您上面的DOC,都是“普通的”)。

    如果您想更深入地了解它的工作原理,请使用命令面板中的View Package File,打开Ruby/Ruby.sublime-syntax 以查看与语言匹配的规则。如果你搜索heredoc,你会看到一个context,它包含了所有匹配的规则,一般看起来是这样的(在build 3211中;在build 4092中更高级):

        # heredoc with embedded SQL and indented terminator
        - match: '(<<[-~]"?((?:[_\w]+_|)SQL)\b"?)'
          scope: punctuation.definition.string.begin.ruby
          push: [heredoc-sql, trailing-heredoc-start]
    

    在这种情况下,规则说后面跟着 SQL 的 heredoc 说明符应该 push 一个名为 heredoc-sql 的上下文,它就在下面:

      heredoc-sql:
        - meta_scope: string.unquoted.embedded.sql.ruby
        - meta_content_scope: text.sql.embedded.ruby
        - match: ^\s*\2$
          scope: punctuation.definition.string.end.ruby
          pop: true
        - include: scope:source.sql
        - include: interpolated-ruby
        - include: escaped-char
    

    这里的include: scope:source.sql 是说该语言应该切换到SQL 模式的魔法酱。上面带有pop 的规则是导致它“退出”heredoc 并返回到Ruby 的原因。

    使用这个公式,可以进行语法修改以包含 Sublime 支持的其他语言。这在 Sublime Text "4" 构建中可能更容易实现,其中语法系统增强之一是扩展语法定义的能力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-13
      • 2015-11-19
      • 1970-01-01
      • 2014-02-07
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多