Skip to content

Commit

Permalink
Split StringTemplate from HTML (#5192)
Browse files Browse the repository at this point in the history
* Split StringTemplates from HTML

Was originally added in #1117 as a HTML variant, but per #4979 language variants should be split.

Default to using default HTML grammar.

Will add a heuristic to differentiate from Smalltalk if needed.

* Fix StringTemplate name and colour

* Rename StringTemplate sample

* Add StringTemplate grammar to index

Uses `atom/language-html`; not ideal as ST-unique syntax isn't matched

* Add .st heuristic

* Add .st heuristic test

* Fix syntax error in heuristics tester

* Generalise part of Smalltalk .st heuristic

* Further fix to Smalltalk heuristic

* Fix unescaped character

* Remove single quote

* Replace StringTemplate grammar module

Using dangmarm/stringtemplate-lang now

* Update StringTemplate grammar link

dangmarm/stringtemplate-lang

* Replace tm_scope

`source.stringtemplate`

* Register StringTemplate tm_scope

* Add grammar license info

* Revert "Replace StringTemplate grammar module"

This reverts commit 7c3bce2.

* Revert StringTemplate grammar addition

* Minor fix to heuristic

* Replace raw space with Regex space char

* Allow whitespace at start of doc

* Add ^ and ' as Smalltalk characters

* Escape ' properly

* More accurate regex

* Change regex from \w+ to \w*

* Add other delimiters to StringTemplate heuristic

* Use grammar added in Alhadis/language-etc@f41e1a4

* Updated cached license data

Co-authored-by: Nixinova <Nixinova@users.noreply.github.com>
Co-authored-by: John Gardner <gardnerjohng@gmail.com>
  • Loading branch information
3 people authored Mar 19, 2021
1 parent 6c1726b commit fa41e7e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ vendor/grammars/language-etc:
- source.sieve
- source.smpl
- source.ssh-config
- source.string-template
- source.tags
- source.ucd.nameslist
- source.ucd.unidata
Expand Down
6 changes: 6 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ disambiguations:
rules:
- language: SubRip Text
pattern: '^(\d{2}:\d{2}:\d{2},\d{3})\s*(-->)\s*(\d{2}:\d{2}:\d{2},\d{3})$'
- extensions: ['.st']
rules:
- language: StringTemplate
pattern: '\$\w+[($]|(.)!\s*.+?\s*!\1|<!\s*.+?\s*!>|\[!\s*.+?\s*!\]|\{!\s*.+?\s*!\}'
- language: Smalltalk
pattern: '\A\s*[\[{(^"''\w#]|[a-zA-Z_]\w*\s*:=\s*[a-zA-Z_]\w*|class\s*>>\s*[a-zA-Z_]\w*|^[a-zA-Z_]\w*\s+[a-zA-Z_]\w*:|^Class\s*{|if(?:True|False):\s*\['
- extensions: ['.t']
rules:
- language: Perl
Expand Down
11 changes: 10 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,6 @@ HTML:
- ".htm"
- ".html.hl"
- ".inc"
- ".st"
- ".xht"
- ".xhtml"
language_id: 146
Expand Down Expand Up @@ -5523,6 +5522,16 @@ Stata:
tm_scope: source.stata
ace_mode: text
language_id: 358
StringTemplate:
type: markup
color: "#3fb34f"
extensions:
- ".st"
tm_scope: source.string-template
ace_mode: html
codemirror_mode: htmlmixed
codemirror_mime_type: text/html
language_id: 89855901
Stylus:
type: markup
color: "#ff6347"
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions test/test_heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,13 @@ def test_srt_by_heuristics
})
end

def test_st_by_heuristics
assert_heuristics({
"StringTemplate" => all_fixtures("StringTemplate", "*.st"),
"Smalltalk" => all_fixtures("Smalltalk", "*.st")
})
end

def test_t_by_heuristics
# Turing not fully covered.
assert_heuristics({
Expand Down
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Standard ML:** [textmate/standard-ml.tmbundle](https://github.com/textmate/standard-ml.tmbundle)
- **Starlark:** [MagicStack/MagicPython](https://github.com/MagicStack/MagicPython)
- **Stata:** [pschumm/Stata.tmbundle](https://github.com/pschumm/Stata.tmbundle)
- **StringTemplate:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc)
- **Stylus:** [billymoon/Stylus](https://github.com/billymoon/Stylus)
- **SubRip Text:** [314eter/atom-language-srt](https://github.com/314eter/atom-language-srt)
- **SugarSS:** [hudochenkov/Syntax-highlighting-for-PostCSS](https://github.com/hudochenkov/Syntax-highlighting-for-PostCSS)
Expand Down
2 changes: 1 addition & 1 deletion vendor/licenses/git_submodule/language-etc.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: language-etc
version: 89c235bee8cc50157eac5527b6e3f466566d8630
version: fc2856e02b7926cf1e7e485319dd383c2adb7851
type: git_submodule
homepage: https://github.com/Alhadis/language-etc
license: isc
Expand Down

0 comments on commit fa41e7e

Please sign in to comment.