Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_prototype syntax test failures #101

Closed
keith-hall opened this issue Sep 5, 2017 · 1 comment · Fixed by #103
Closed

with_prototype syntax test failures #101

keith-hall opened this issue Sep 5, 2017 · 1 comment · Fixed by #103

Comments

@keith-hall
Copy link
Collaborator

I've finally had chance to investigate #59 a little bit, and found something interesting.

Let's say we have a file testdata/Packages/ASP/HTML-ASP2.sublime-syntax with the following contents (it's basically a cut down version of the full HTML-ASP syntax, that doesn't reference ASP itself and can serve as a(n almost minimal) complete verifiable example):

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: HTML (ASP)2
file_extensions:
  - asp2
scope: text.html.asp2
contexts:
  main:
    - include: html

  asp_punctuation_begin:
    - match: '<%'
      scope: punctuation.section.embedded.begin.asp
      push:
        - match: '(?=\S)'
          set: [close_embedded_asp, begin_embedded_asp]

  html:
    - match: ''
      set:
        - include: scope:text.html.basic
      with_prototype:
        - include: asp_punctuation_begin

  begin_embedded_asp:
    - meta_content_scope: source.asp.embedded.html
    - match: '(?=%>)'
      pop: true

  close_embedded_asp:
    - match: '%>'
      scope: punctuation.section.embedded.end.asp
      pop: true

and the following corresponding syntax test (testdata/Packages/ASP/syntax_test_asp2.asp2):

' SYNTAX TEST "Packages/User/HTML-ASP2.sublime-syntax"
<html><% example <%
' ^^^ meta.tag.structure.any.html entity.name.tag.structure.any.html
'     ^^ punctuation.section.embedded.begin.asp
'        ^^^^^^^^^^^ source.asp.embedded.html - punctuation

and execute syntest with RUST_BACKTRACE=1 cargo run --example syntest testdata/Packages/ASP/syntax_test_asp2.asp2 testdata/Packages/

The output is:

loading syntax definitions from testdata/Packages/
Testing file testdata/Packages/ASP/syntax_test_asp2.asp2
The test file references syntax definition file: Packages/ASP/HTML-ASP2.sublime-syntax
  Assertion selector "source.asp.embedded.html - punctuation" from line 5 failed against line 2, column range 17-19 (with text "<%") has scope [<text.html.asp2>, <source.asp.embedded.html>, <punctuation.section.embedded.begin.asp>]
Ok(FailedAssertions(2, 16))
exiting with code 1

but in ST, if we look at the scopes, we see the <% which had a failure in syntect has no special scopes applied to it.
image

so we can conclude that the with_prototype is being applied in syntect to the begin_embedded_asp context, but isn't in ST. I suspect there is a general rule that the with_prototype shouldn't apply to nested contexts pushed by matches made in itself, if that makes sense.

i.e. estimated rough sequence of events:

  • the anonymous context inside the html context is pushed onto the stack, with the asp_punctuation_begin context in the with_prototype
  • eventually the <% match pattern from that context is hit, and it pushes a new anonymous context - this context should no longer have the asp_punctuation_begin with_prototype applied to it
  • the begin_embedded_asp context replaces the anonymous context at the top of the stack
  • because syntect is still applying the with_prototype, the <% after example gets matched unexpectedly/incorrectly and scoped.
@trishume
Copy link
Owner

trishume commented Sep 5, 2017

Interesting, thanks for figuring this out. Not applying with_prototypes within themselves makes sense as a rule. I wonder how hard this will be to fix, I haven't looked at the relevant code in a while, it might be easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants