BenjaminSchaaf / sbnf

A BNF-style language for writing sublime-syntax files
MIT License
58 stars 6 forks source link

Unexpected redundant scopes for recursive patterns #13

Closed mitranim closed 1 year ago

mitranim commented 3 years ago

Consider the following over-simplified syntax that supports only comments inside [], nestable:

main = (~comment)*;
comment{comment} = `[` (~comment)* ~`]`;

The first comment level has 1 comment scope as expected, but every additional level gets another +2:

[comment0 [comment1]]
^^^^^^^^^ comment
          ^^^^^^^^^^ comment comment comment
                    ^ comment
AmjadHD commented 2 years ago

FWIW, this is the generated sublime-syntax:

%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
version: 2
name: 
scope: source.
contexts:
  # Rule: comment
  comment|0:
    - meta_content_scope: comment
    - match: '\['
      scope: comment comment # <- double scope
      push: [comment|meta, comment|0] # <- no need for comment|meta
    - match: '\]'
      scope: comment
      pop: true
  # Meta scope context for comment
  comment|meta:
    - meta_content_scope: comment
    - match: ''
      pop: true
  # Rule: main
  main:
    - match: '\['
      scope: comment
      push: comment|0

Removing the meta scope:

main = (~comment)*;
comment = `[` (~comment)* ~`]`;

generates:

%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
version: 2
name: 
scope: source.
contexts:
  # Rule: comment
  comment|0:
    - match: '\['
      push: comment|0
    - match: '\]'
      pop: true
  # Rule: main
  main:
    - match: '\['
      push: comment|0