0

给定以下树:

style_element [0, 0] - [1, 8]
  start_tag [0, 0] - [0, 19]
    tag_name [0, 1] - [0, 6]
    attribute [0, 7] - [0, 18]
      attribute_name [0, 7] - [0, 11]
      quoted_attribute_value [0, 12] - [0, 18]
        attribute_value [0, 13] - [0, 17]
  raw_text [1, 0] - [1, 0]
  end_tag [1, 0] - [1, 8]
    ERROR [1, 2] - [1, 7]
    tag_name [1, 2] - [1, 7]
style_element [3, 0] - [4, 8]
  start_tag [3, 0] - [3, 19]
    tag_name [3, 1] - [3, 6]
    attribute [3, 7] - [3, 13]
      attribute_name [3, 7] - [3, 13]
    attribute [3, 14] - [3, 18]
      attribute_name [3, 14] - [3, 18]
  raw_text [4, 0] - [4, 0]
  end_tag [4, 0] - [4, 8]
    tag_name [4, 2] - [4, 7]
style_element [6, 0] - [7, 8]
  start_tag [6, 0] - [6, 12]
    tag_name [6, 1] - [6, 6]
    attribute [6, 7] - [6, 11]
      attribute_name [6, 7] - [6, 11]
  raw_text [7, 0] - [7, 0]
  end_tag [7, 0] - [7, 8]
    tag_name [7, 2] - [7, 7]
style_element [9, 0] - [10, 8]
  start_tag [9, 0] - [9, 7]
    tag_name [9, 1] - [9, 6]
  raw_text [10, 0] - [10, 0]
  end_tag [10, 0] - [10, 8]
    tag_name [10, 2] - [10, 7]
style_element [12, 0] - [13, 8]
  start_tag [12, 0] - [12, 14]
    tag_name [12, 1] - [12, 6]
    attribute [12, 7] - [12, 13]
      attribute_name [12, 7] - [12, 13]
  raw_text [13, 0] - [13, 0]
  end_tag [13, 0] - [13, 8]
    tag_name [13, 2] - [13, 7]
style_element [15, 0] - [16, 8]
  start_tag [15, 0] - [15, 14]
    tag_name [15, 1] - [15, 6]
    attribute [15, 7] - [15, 13]
      attribute_name [15, 7] - [15, 13]
  raw_text [16, 0] - [16, 0]
  end_tag [16, 0] - [16, 8]
    tag_name [16, 2] - [16, 7]

这是通过解析此代码产生的:

<style lang="scss" scoped>
</style>

<style scoped lang>
</style>

<style lang>
</style>

<style>
</style>

<style scoped>
</style>

<style module>
</style>

当样式标签缺少属性lang时,我想将其突出显示为 css。以上包含一些需要考虑的情况。只有最后三个应该突出显示为 css

到目前为止,我想出了这个查询:

((style_element (start_tag (attribute (attribute_name) @_attr (#not-eq? @_attr "lang"))) (raw_text) @css))

但不幸的是,这也突出显示<style lang="scss" scoped>,因为它包含一个与 lang 不匹配的属性。此标记包含 lang 属性,因此不应匹配。

如何修改上述查询,使其仅匹配没有 lang 属性的样式标签?

4

0 回答 0