Skip to content

Embed rewriting not perfect #222

@keith-hall

Description

@keith-hall

After the latest fixes, I tried updating the submodules, and can see we still have some syntax test failures, this time relating to embed...escape:

FAILED testdata/Packages\Java\syntax_test_java.java: 817
FAILED testdata/Packages\Markdown\syntax_test_markdown.md: 61

We get the same failures in Sublime Text, when rewriting the embed...escape rules to with_prototype like syntect's yaml_load is doing, so the good news is that syntects parser is working correctly:

JavaDoc.sublime-syntax:

--- Shipped Packages/Java/JavaDoc.sublime-syntax    2018-10-11 19:11:54
+++ Packages/Java/JavaDoc.sublime-syntax    2018-10-30 11:28:20
@@ -20,11 +20,12 @@
     - meta_include_prototype: false
     - match: /\*\*
       scope: comment.block.documentation.javadoc punctuation.definition.comment.begin.javadoc
-      embed: contents
-      embed_scope: comment.block.documentation.javadoc text.html.javadoc
-      escape: \*/
-      escape_captures:
-        0: comment.block.documentation.javadoc punctuation.definition.comment.end.javadoc
+      push:
+        - [{ meta_include_prototype: false }, { meta_content_scope: 'comment.block.documentation.javadoc text.html.javadoc' }, { match: '\*/', scope: comment.block.documentation.javadoc punctuation.definition.comment.end.javadoc, pop: true }]
+        - contents
+      with_prototype:
+        - match: (?=\*/)
+          pop: true

Markdown.sublime-syntax:

--- Shipped Packages/Markdown/Markdown.sublime-syntax   2018-10-11 19:11:54
+++ Packages/Markdown/Markdown.sublime-syntax   2018-10-30 09:44:46
@@ -1106,12 +1106,12 @@ contexts:
         0: meta.code-fence.definition.begin.html-php.markdown-gfm
         2: punctuation.definition.raw.code-fence.begin.markdown
         5: constant.other.language-name.markdown
-      embed: scope:embedding.php
-      embed_scope: markup.raw.code-fence.html-php.markdown-gfm
-      escape: '{{code_fence_escape}}'
-      escape_captures:
-        0: meta.code-fence.definition.end.html-php.markdown-gfm
-        1: punctuation.definition.raw.code-fence.end.markdown
+      push:
+        - [{ meta_include_prototype: false }, { meta_content_scope: 'markup.raw.code-fence.html-php.markdown-gfm' }, { match: '{{code_fence_escape}}', captures: { 0: meta.code-fence.definition.end.html-php.markdown-gfm, 1: punctuation.definition.raw.code-fence.end.markdown }, pop: true }]
+        - scope:embedding.php
+      with_prototype:
+        - match: (?={{code_fence_escape}})
+          pop: true
     - match: |-
          (?x)
           {{fenced_code_block_start}}

For Java(Doc), the workaround suggested at #160 (comment) works.

For Markdown, the following syntax test is enough to see the problem:

| SYNTAX TEST "Packages/Markdown/Markdown.sublime-syntax"
```html+php
<div></div>
|^^^ entity.name.tag.block.any.html
<?php
|^^^^ punctuation.section.embedded.begin.php
var_dump(expression);
| ^^^^^^ support.function.var.php
```
|^^ punctuation.definition.raw.code-fence.end.markdown

Everything except the last line's assertions pass. Adding ?> before the closing backticks/code fence allows the backticks to be correctly recognized as the closing code fence instead of PHP interpolated string punctuation, but we will need a solution so that the way syntect handles embed actions will work 100% correctly in all situations.

Altering the PHP Source syntax definition can help to work around it, which (although obviously not a solution,) suggests that, for some reason, the with_prototype (rewritten from the embed in the Markdown syntax definition) is not being considered at this point (in both Sublime and syntect):

--- Shipped Packages/PHP/PHP Source.sublime-syntax  2018-10-11 19:11:54
+++ Packages/PHP/PHP Source.sublime-syntax  2018-10-30 13:36:58
@@ -109,6 +109,8 @@
         - include: statements
 
   expressions:
+    - match: (?=```)
+      pop: true
     - include: comments
     - match: (?i)\b((?:require|include)(?:_once)?)\b\s*
       captures:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions