Skip to content

Commit

Permalink
[Makefile] Fix embedded ShellScript prototypes (sublimehq#2320)
Browse files Browse the repository at this point in the history
* [Makefile] Fix embedded ShellScript prototypes

Fixes sublimehq#2318

Problem Description

  The Makefile.sublime-syntax includes the Bash.sublime-syntax.

  The `scope:source.shell#prototype` is injected into the embedded
  Bash.sublime-syntax using `with_prototype` maybe as workaround for
  sublimehq/sublime_text#1062

  The `with_prototype` command ignores `meta_include_prototype: false`,
  which is heavily used by Bash.sublime-syntax to prevent the
  `prototype` context from being included into a bunch of contexts such
  as strings.

Fix Description

  As the prototype context is not included into source.shell's main
  context only, it is not necessary to inject it via `with_protoype`. Hence it is moved to the `shell-body` together with `source.shell`,
  which is suggested by the core issue as proper workaround.

Notes:

  The `prototype` context of the Bash.sublime-syntax also includes
  proper rules to pop off all contexts at eol with respect of line
  continuation. Hence those don't need to be part of the `with_proptype`
  statement as well. They are moved to just pop off the Bash's main
  context as soon as the eol is reached.

  The `source.shell.embedded` scope is applied to all embedded shell
  syntax regions.

* [Makefile] Fix embedded comment scope

Fixes an oversight with regards of the changed `source.shell.embedded`
scope, which is used for embedded ShellScript syntax.

* [Makefile] Use ST4077 syntax features

This commit uses `apply_prototype` to optionally include the prototype
if present but keep calm if it was not defined by the included syntax.

Add some tests for embedded shell scopes as well.
  • Loading branch information
deathaxe authored and mitranim committed Mar 20, 2022
1 parent 5c89900 commit c0f7039
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
27 changes: 16 additions & 11 deletions Makefile/Makefile.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,19 @@ contexts:
set:
# I don't like putting the string "source.shell" here, as the delegation
# seeps into this syntax now. But I don't see a cleaner way right now.
- meta_scope: source.shell comment.line.number-sign.shell
- meta_scope: source.shell.embedded comment.line.number-sign.shell
- include: comments-pop-on-line-end
# Otherwise, delegate to the shell syntax (with various extra prototypes).
- match: ""
set: scope:source.shell
- match: ''
set: shell-body
with_prototype:
- include: pop-on-line-end
- include: scope:source.shell#prototype
- include: line-continuation
- include: variable-substitutions

shell-body:
- meta_scope: source.shell.embedded
- include: embedded-shell
- include: pop-on-line-end

line-continuation:
- match: (\\)([ ]*)$\n?
captures:
Expand Down Expand Up @@ -523,7 +525,7 @@ contexts:
scope: keyword.other.block.end.makefile
pop: true
- match: ''
push: scope:source.shell
push: shell-body
with_prototype:
- match: (?=\))
pop: true
Expand Down Expand Up @@ -563,10 +565,9 @@ contexts:
set:
- match: '!='
scope: keyword.operator.assignment.makefile
set: scope:source.shell
set: shell-body
with_prototype:
- include: variable-substitutions
- include: pop-on-line-end
- include: textual-parenthesis-balancer
- match: (?=\s*(!|\?|\+|::?)?=)
set:
Expand All @@ -592,14 +593,18 @@ contexts:
captures:
1: meta.string.makefile string.unquoted.makefile
2: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.begin.makefile
embed: scope:source.shell
embed_scope: meta.string.makefile meta.interpolation.makefile
embed: embedded-shell
embed_scope: meta.string.makefile meta.interpolation.makefile source.shell.embedded
escape: (?!<\\)\2
escape_captures:
0: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.end.makefile
- match: ''
set: value-to-be-defined

embedded-shell:
- include: scope:source.shell
apply_prototype: true

value-to-be-defined:
- meta_content_scope: meta.string.makefile string.unquoted.makefile
- include: escape-literals
Expand Down
10 changes: 8 additions & 2 deletions Makefile/syntax_test_makefile.mak
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ sources := $($(a1)_objects:.o=.c)
# ^^ string variable
# ^ string variable keyword.other.block.end

.build/vernum: ../meta/version
sed -i.bak 's/.*automatically updated.*/version = "$(VER)" # automatically updated/' setup.py
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.body.makefile source.shell.embedded meta.function-call
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single - comment
# ^^^^^^ variable.parameter.makefile

CC=g++
#<- variable.other
# ^ keyword.operator.assignment
Expand Down Expand Up @@ -924,11 +930,11 @@ TESTTOOL = sh -c '\
# ^^^ meta.string.makefile meta.interpolation.makefile
# ^^^^^^ string.unquoted.makefile
# ^ punctuation.section.interpolation.begin.makefile
# ^ source.shell punctuation.separator.continuation.line.shell
# ^ source.shell.embedded punctuation.separator.continuation.line.shell - source.shell source.shell
if something; then
build_thisway $$1 $$2;
fi' TESTTOOL
# ^^^ meta.string.makefile meta.interpolation.makefile
# ^^^^^^^^^ meta.string.makefile string.unquoted.makefile - meta.interpolation
# ^^ source.shell keyword.control.conditional.end.shell
# ^^ source.shell.embedded keyword.control.conditional.end.shell - source.shell source.shell
# ^ punctuation.section.interpolation.end.makefile

0 comments on commit c0f7039

Please sign in to comment.