Skip to content

Commit

Permalink
use scope:source.* instead of {lang}.sublime-syntax, remove markdown,…
Browse files Browse the repository at this point in the history
… and make interpolated expressions stand out more
  • Loading branch information
blake-regalia committed May 9, 2018
1 parent 1e64ef0 commit 646e0e4
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 114 deletions.
179 changes: 80 additions & 99 deletions ecmascript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,30 @@ variables:
syntaxDirectiveHead: '(\s*syntax\s*:\s*)'
syntaxDirectiveTail: '\s*(\*\/)\s*((({{identifier}})))?(?=\s*`)'

syntaxDirective_SQL: '[Ss](?:ql|QL){{syntaxDirectiveTail}}'
syntaxDirective_HTML: '[Hh](?:tml|TML){{syntaxDirectiveTail}}'
syntaxDirective_CSS: '[Cc](?:ss|SS){{syntaxDirectiveTail}}'
syntaxDirective_DOT: '[Dd](?:ot|OT){{syntaxDirectiveTail}}'
syntaxDirective_GLSL: '[Gg](?:lsl|LSL){{syntaxDirectiveTail}}'
syntaxDirective_HTML: '[Hh](?:tml|TML){{syntaxDirectiveTail}}'
syntaxDirective_JS: '[Jj](?:ava|AVA)?[Ss](?:cript|CRIPT)?{{syntaxDirectiveTail}}'
syntaxDirective_JSON: '[Jj](?:son|SON){{syntaxDirectiveTail}}'
syntaxDirective_GLSL: '[Gg](?:lsl|LSL){{syntaxDirectiveTail}}'
syntaxDirective_DOT: '[Dd](?:ot|OT){{syntaxDirectiveTail}}'
syntaxDirective_SHELL: '(?:[Bb](?:ash|ASH)|[Ss](?:hell|HELL)){{syntaxDirectiveTail}}'
syntaxDirective_SQL: '[Ss](?:ql|QL){{syntaxDirectiveTail}}'
syntaxDirective_XML: '[Xx](?:ml|ML){{syntaxDirectiveTail}}'
syntaxDirective_YAML: '[Yy](?:aml|AML){{syntaxDirectiveTail}}'
syntaxDirective_MARKDOWN: '[Mm](?:[Dd]|ark[Dd]own|ARKDOWN){{syntaxDirectiveTail}}'

syntaxDirective: >-
(?x)
((\/\*)){{syntaxDirectiveHead}}
(?= {{syntaxDirective_SQL}}
(?= {{syntaxDirective_CSS}}
| {{syntaxDirective_DOT}}
| {{syntaxDirective_GLSL}}
| {{syntaxDirective_HTML}}
| {{syntaxDirective_CSS}}
| {{syntaxDirective_JS}}
| {{syntaxDirective_JSON}}
| {{syntaxDirective_GLSL}}
| {{syntaxDirective_DOT}}
| {{syntaxDirective_SHELL}}
| {{syntaxDirective_SQL}}
| {{syntaxDirective_XML}}
| {{syntaxDirective_YAML}}
| {{syntaxDirective_MARKDOWN}}
)
contexts:
Expand Down Expand Up @@ -5523,13 +5521,20 @@ contexts:
- match: '\\[`\$\{]'
scope: constant.character.escape.es
- match: '\\\n'
scope: constant.character.escape.pointless.es
scope: constant.character.escape.es

This comment has been minimized.

Copy link
@bathos

bathos May 10, 2018

Owner

good catch

- include: string_COMMON_ESCAPES
- match: '((\$\{))'
scope: meta.interpolation.interpolated.es
captures:
1: entity.quasi.element.js punctuation.quasi.element.begin.js # ^BS
2: punctuation.definition.string.interpolated.element.begin.es
push: [ syntax_ELEMENT, expression ]
push:
- - meta_include_prototype: false
- meta_content_scope: meta.interpolation.interpolated.es
- match: '{{PLA_anything}}'
pop: true
- - include: syntax_ELEMENT
- - include: expression

syntax_ELEMENT:
- match: '((\}))'
Expand All @@ -5548,62 +5553,62 @@ contexts:
syntax_DIRECTIVE:
- meta_scope: comment.block.es
- meta_include_prototype: false
- match: '{{syntaxDirective_SQL}}'
- match: '{{syntaxDirective_CSS}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_SQL, syntax_SQL_OPEN ]
- match: '{{syntaxDirective_HTML}}'
set: [ syntax_meta_CSS, syntax_CSS_OPEN ]
- match: '{{syntaxDirective_DOT}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_HTML, syntax_HTML_OPEN ]
- match: '{{syntaxDirective_CSS}}'
set: [ syntax_meta_DOT, syntax_DOT_OPEN ]
- match: '{{syntaxDirective_GLSL}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_CSS, syntax_CSS_OPEN ]
- match: '{{syntaxDirective_JS}}'
set: [ syntax_meta_GLSL, syntax_GLSL_OPEN ]
- match: '{{syntaxDirective_HTML}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_JS, syntax_JS_OPEN ]
- match: '{{syntaxDirective_JSON}}'
set: [ syntax_meta_HTML, syntax_HTML_OPEN ]
- match: '{{syntaxDirective_JS}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_JSON, syntax_JSON_OPEN ]
- match: '{{syntaxDirective_GLSL}}'
set: [ syntax_meta_JS, syntax_JS_OPEN ]
- match: '{{syntaxDirective_JSON}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_GLSL, syntax_GLSL_OPEN ]
- match: '{{syntaxDirective_DOT}}'
set: [ syntax_meta_JSON, syntax_JSON_OPEN ]
- match: '{{syntaxDirective_SHELL}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_DOT, syntax_DOT_OPEN ]
- match: '{{syntaxDirective_SHELL}}'
set: [ syntax_meta_SHELL, syntax_SHELL_OPEN ]
- match: '{{syntaxDirective_SQL}}'
captures:
1: punctuation.definition.comment.end.es
2: entity.quasi.tag.name.js # ^BS
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_SHELL, syntax_SHELL_OPEN ]
set: [ syntax_meta_SQL, syntax_SQL_OPEN ]
- match: '{{syntaxDirective_XML}}'
captures:
1: punctuation.definition.comment.end.es
Expand All @@ -5618,59 +5623,70 @@ contexts:
3: variable.other.readwrite.tag.es
4: punctuation.definition.string.interpolated.begin.es
set: [ syntax_meta_YAML, syntax_YAML_OPEN ]
# - match: '{{syntaxDirective_MARKDOWN}}'
# captures:
# 1: punctuation.definition.comment.end.es
# 2: entity.quasi.tag.name.js # ^BS
# 3: variable.other.readwrite.tag.es
# 4: punctuation.definition.string.interpolated.begin.es
# set: [ syntax_meta_MARKDOWN, syntax_MARKDOWN_OPEN ]

# SQL SYNTAX ###################################################################
# CSS SYNTAX ###################################################################

syntax_meta_SQL:
- meta_content_scope: meta.interpolation.syntax.sql
syntax_meta_CSS:
- meta_content_scope: meta.interpolation.syntax.css
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_SQL_OPEN:
syntax_CSS_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/SQL/SQL.sublime-syntax
set: scope:source.css
with_prototype:
- include: syntax_AFTER_OPEN

# HTML SYNTAX ##################################################################
# DOT (GRAPHVIZ) SYNTAX ########################################################

syntax_meta_HTML:
- meta_content_scope: meta.interpolation.syntax.html
syntax_meta_DOT:
- meta_content_scope: meta.interpolation.syntax.dot
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_HTML_OPEN:
syntax_DOT_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/HTML/HTML.sublime-syntax
set: scope:source.dot
with_prototype:
- include: syntax_AFTER_OPEN

# GLSL SYNTAX ###################################################################

# CSS SYNTAX ###################################################################
syntax_meta_GLSL:
- meta_content_scope: meta.interpolation.syntax.glsl
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_meta_CSS:
- meta_content_scope: meta.interpolation.syntax.css
syntax_GLSL_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: scope:source.glsl
with_prototype:
- include: syntax_AFTER_OPEN

# HTML SYNTAX ##################################################################

syntax_meta_HTML:
- meta_content_scope: meta.interpolation.syntax.html
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_CSS_OPEN:
syntax_HTML_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/CSS/CSS.sublime-syntax
# We don't want to risk loading an HTML syntax that uses
# `embed: scope:source.js` since that would cause recursion
set: Packages/HTML/HTML.sublime-syntax
with_prototype:
- include: syntax_AFTER_OPEN

Expand All @@ -5686,7 +5702,7 @@ contexts:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/JavaScript/JavaScript.sublime-syntax
set: scope:source.js
with_prototype:
# We must also compete with the 'tagged-template' rule in the default
# JavaScript.sublime-syntax so that we can pop out
Expand All @@ -5709,55 +5725,39 @@ contexts:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/JavaScript/JSON.sublime-syntax
with_prototype:
- include: syntax_AFTER_OPEN

# GLSL SYNTAX ###################################################################

syntax_meta_GLSL:
- meta_content_scope: meta.interpolation.syntax.glsl
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_GLSL_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: "Packages/OpenGL Shading Language (GLSL)/GLSL.sublime-syntax"
set: scope:source.json
with_prototype:
- include: syntax_AFTER_OPEN

# DOT (GRAPHVIZ) SYNTAX ########################################################
# SHELL (BASH) SYNTAX ##########################################################

syntax_meta_DOT:
- meta_content_scope: meta.interpolation.syntax.dot
syntax_meta_SHELL:
- meta_content_scope: meta.interpolation.syntax.shell
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_DOT_OPEN:
syntax_SHELL_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/Graphviz/DOT.sublime-syntax
set: scope:source.shell
with_prototype:
- include: syntax_AFTER_OPEN

# SHELL (BASH) SYNTAX ##########################################################
# SQL SYNTAX ###################################################################

syntax_meta_SHELL:
- meta_content_scope: meta.interpolation.syntax.shell
syntax_meta_SQL:
- meta_content_scope: meta.interpolation.syntax.sql
- meta_include_prototype: false
- match: '{{PLA_anything}}'
pop: true

syntax_SHELL_OPEN:
syntax_SQL_OPEN:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/ShellScript/Shell-Unix-Generic.sublime-syntax
set: scope:source.sql
with_prototype:
- include: syntax_AFTER_OPEN

Expand All @@ -5773,7 +5773,7 @@ contexts:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/XML/XML.sublime-syntax
set: scope:text.xml
with_prototype:
- include: syntax_AFTER_OPEN

Expand All @@ -5789,25 +5789,6 @@ contexts:
- meta_include_prototype: false
- match: '`'
scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
set: Packages/YAML/YAML.sublime-syntax
set: scope:source.yaml
with_prototype:
- include: syntax_AFTER_OPEN

# MARKDOWN SYNTAX ##############################################################

# Disabled for now: for reasons I’m unsure of, nesting markdown leads to errors
# being thrown.

# syntax_meta_MARKDOWN:
# - meta_content_scope: meta.interpolation.syntax.markdown
# - meta_include_prototype: false
# - match: '{{PLA_anything}}'
# pop: true

# syntax_MARKDOWN_OPEN:
# - meta_include_prototype: false
# - match: '`'
# scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
# set: Packages/Markdown/Markdown.sublime-syntax
# with_prototype:
# - include: syntax_AFTER_OPEN

1 comment on commit 646e0e4

@blake-regalia
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of these changes:

  • Alphabetized syntax defs
  • Removed Markdown -- too much trouble for too little gain
  • Use scope:source.* instead of {lang}.sublime-syntax so that user's preferred syntax plugins load rather than the Sublime defaults (except for HTML and JavaScript to avoid possible recursion)
  • Added scope meta.interpolation.interpolated.es to make interpolated expressions stand out a bit more from syntax-highlighted code (again, only reflected in Excelsior. Feel free to change the colors, my designer skills aren't the best!)

Please sign in to comment.