Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions grammars/shell-unix-bash.cson
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
'function-definition':
'patterns': [
{
'begin': '\\b(function)\\s+([^\\s\\\\]+)(?:\\s*(\\(\\)))?'
'begin': '(?<=^|;|&|\\s)(function)\\s+([^\\s\\\\]+)(?:\\s*(\\(\\)))?'
'beginCaptures':
'1':
'name': 'storage.type.function.shell'
Expand All @@ -249,7 +249,7 @@
]
}
{
'begin': '\\b([^\\s\\\\=]+)\\s*(\\(\\))'
'begin': '(?<=^|;|&|\\s)([^\\s\\\\=]+)\\s*(\\(\\))'
'beginCaptures':
'1':
'name': 'entity.name.function.shell'
Expand Down Expand Up @@ -280,7 +280,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.ruby.embedded.shell'
'end': '^\\t*(RUBY)\\b'
'end': '^\\t*(RUBY)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -302,7 +302,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.ruby.embedded.shell'
'end': '^(RUBY)\\b'
'end': '^(RUBY)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -324,7 +324,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.python.embedded.shell'
'end': '^\\t*(PYTHON)\\b'
'end': '^\\t*(PYTHON)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -346,7 +346,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.python.embedded.shell'
'end': '^(PYTHON)\\b'
'end': '^(PYTHON)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -368,7 +368,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.applescript.embedded.shell'
'end': '^\\t*(APPLESCRIPT)\\b'
'end': '^\\t*(APPLESCRIPT)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -390,7 +390,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.applescript.embedded.shell'
'end': '^(APPLESCRIPT)\\b'
'end': '^(APPLESCRIPT)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -412,7 +412,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.embedded.shell'
'end': '^\\t*(HTML)\\b'
'end': '^\\t*(HTML)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -434,7 +434,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.embedded.shell'
'end': '^(HTML)\\b'
'end': '^(HTML)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -456,7 +456,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.markdown.embedded.shell'
'end': '^\\t*(MARKDOWN)\\b'
'end': '^\\t*(MARKDOWN)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -478,7 +478,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.markdown.embedded.shell'
'end': '^(MARKDOWN)\\b'
'end': '^(MARKDOWN)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -500,7 +500,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.textile.embedded.shell'
'end': '^\\t*(TEXTILE)\\b'
'end': '^\\t*(TEXTILE)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -522,7 +522,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'text.html.textile.embedded.shell'
'end': '^(TEXTILE)\\b'
'end': '^(TEXTILE)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -544,7 +544,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.shell.embedded.shell'
'end': '^\\t*(\\3)\\b'
'end': '^\\t*(\\3)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -566,7 +566,7 @@
'0':
'name': 'punctuation.definition.string.shell'
'contentName': 'source.shell.embedded.shell'
'end': '^(\\3)\\b'
'end': '^(\\3)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -587,7 +587,7 @@
'captures':
'0':
'name': 'punctuation.definition.string.shell'
'end': '^\\t*(\\3)\\b'
'end': '^\\t*(\\3)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand All @@ -603,7 +603,7 @@
'captures':
'0':
'name': 'punctuation.definition.string.shell'
'end': '^(\\3)\\b'
'end': '^(\\3)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.heredoc-token.shell'
Expand Down Expand Up @@ -734,11 +734,11 @@
'keyword':
'patterns': [
{
'match': '(?<!-)\\b(then|else|elif|fi|for|in|do|done|select|case|continue|esac|while|until|return)\\b(?!-)'
'match': '(?<=^|;|&|\\s)(then|else|elif|fi|for|in|do|done|select|case|continue|esac|while|until|return)(?=\\s|;|&|$)'
'name': 'keyword.control.shell'
}
{
'match': '(?<![-/])\\b(?:export|declare|typeset|local|readonly)\\b'
'match': '(?<=^|;|&|\\s)(?:export|declare|typeset|local|readonly)(?=\\s|;|&|$)'
'name': 'storage.modifier.shell'
}
]
Expand All @@ -764,11 +764,11 @@
'loop':
'patterns': [
{
'begin': '\\b(for)\\s+(?=\\({2})'
'begin': '(?<=^|;|&|\\s)(for)\\s+(?=\\({2})'
'captures':
'1':
'name': 'keyword.control.shell'
'end': '\\b(done)\\b'
'end': '(?<=^|;|&|\\s)(done)(?=\\s|;|&|$)'
'name': 'meta.scope.for-loop.shell'
'patterns': [
{
Expand All @@ -777,7 +777,7 @@
]
}
{
'begin': '\\b(for)\\b\\s+(.+)\\s+\\b(in)\\b'
'begin': '(?<=^|;|&|\\s)(for)\\s+(.+)\\s+(in)(?=\\s|;|&|$)'
'beginCaptures':
'1':
'name': 'keyword.control.shell'
Expand All @@ -790,7 +790,7 @@
]
'3':
'name': 'keyword.control.shell'
'end': '(?<![-/])\\bdone\\b(?![-/])'
'end': '(?<=^|;|&|\\s)done(?=\\s|;|&|$)'
'endCaptures':
'0':
'name': 'keyword.control.shell'
Expand All @@ -802,11 +802,11 @@
]
}
{
'begin': '\\b(while|until)\\b'
'begin': '(?<=^|;|&|\\s)(while|until)(?=\\s|;|&|$)'
'captures':
'1':
'name': 'keyword.control.shell'
'end': '\\b(done)\\b'
'end': '(?<=^|;|&|\\s)(done)(?=\\s|;|&|$)'
'name': 'meta.scope.while-loop.shell'
'patterns': [
{
Expand All @@ -815,13 +815,13 @@
]
}
{
'begin': '\\b(select)\\s+((?:[^\\s\\\\]|\\\\.)+)\\b'
'begin': '(?<=^|;|&|\\s)(select)\\s+((?:[^\\s\\\\]|\\\\.)+)(?=\\s|;|&|$)'
'beginCaptures':
'1':
'name': 'keyword.control.shell'
'2':
'name': 'variable.other.loop.shell'
'end': '\\b(done)\\b'
'end': '(?<=^|;|&|\\s)(done)(?=\\s|;|&|$)'
'endCaptures':
'1':
'name': 'keyword.control.shell'
Expand All @@ -833,19 +833,19 @@
]
}
{
'begin': '(?<!-)\\b(case)\\b(?!-)'
'begin': '(?<=^|;|&|\\s)(case)(?=\\s|;|&|$)'
'captures':
'1':
'name': 'keyword.control.shell'
'end': '\\b(esac)\\b'
'end': '(?<=^|;|&|\\s)(esac)(?=\\s|;|&|$)'
'name': 'meta.scope.case-block.shell'
'patterns': [
{
'begin': '\\b(?:in)\\b'
'begin': '(?<=^|;|&|\\s)(in)(?=\\s|;|&|$)'
'beginCaptures':
'1':
'name': 'keyword.control.shell'
'end': '(?=\\b(?:esac)\\b)'
'end': '(?<=^|;|&|\\s)(?=(?:esac)(?:\\s|;|&|$))'
'name': 'meta.scope.case-body.shell'
'patterns': [
{
Expand All @@ -865,11 +865,11 @@
]
}
{
'begin': '(?<!-)\\b(if)\\b(?!-|\\s*=)'
'begin': '(?<=^|;|&|\\s)(if)(?=\\s|;|&|$)'
'captures':
'1':
'name': 'keyword.control.shell'
'end': '\\b(fi)\\b'
'end': '(?<=^|;|&|\\s)(fi)(?=\\s|;|&|$)'
'name': 'meta.scope.if-block.shell'
'patterns': [
{
Expand Down Expand Up @@ -936,7 +936,7 @@
'pipeline':
'patterns': [
{
'match': '\\b(time)\\b'
'match': '(?<=^|;|&|\\s)(time)(?=\\s|;|&|$)'
'name': 'keyword.other.shell'
}
{
Expand Down Expand Up @@ -1041,11 +1041,11 @@
'support':
'patterns': [
{
'match': '(?<=^|\\s)(?::|\\.)(?=\\s|;|&|$)'
'match': '(?<=^|;|&|\\s)(?::|\\.)(?=\\s|;|&|$)'
'name': 'support.function.builtin.shell'
}
{
'match': '(?<![-/])\\b(?:alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|false|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|readonly|set|shift|shopt|source|suspend|test|times|trap|true|type|ulimit|umask|unalias|unset|wait)\\b(?![-/])'
'match': '(?<=^|;|&|\\s)(?:alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|false|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|readonly|set|shift|shopt|source|suspend|test|times|trap|true|type|ulimit|umask|unalias|unset|wait)(?=\\s|;|&|$)'
'name': 'support.function.builtin.shell'
}
]
Expand Down
67 changes: 54 additions & 13 deletions spec/shell-unix-bash-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,35 @@ describe "Shell script grammar", ->
expect(tokens[0]).toEqual value: 'grep --ignore-case ', scopes: ['source.shell']
expect(tokens[1]).toEqual value: '"', scopes: ['source.shell', 'string.quoted.double.shell', 'punctuation.definition.string.begin.shell']

{tokens} = grammar.tokenizeLine('iffy')
strings = [
'iffy'
'enable-something'
'there.for'
'be+done'
'little,while'
'rest@until'
'lets:select words'
'in🚀case of stuff'
'the#fi%nal countdown'
'time⏰out'
]

expect(tokens[0]).toEqual value: 'iffy', scopes: ['source.shell']
for string in strings
{tokens} = grammar.tokenizeLine(string)

{tokens} = grammar.tokenizeLine('enable-something')
expect(tokens[0]).toEqual value: string, scopes: ['source.shell']

expect(tokens[0]).toEqual value: 'enable-something', scopes: ['source.shell']
{tokens} = grammar.tokenizeLine('this/function ()')

expect(tokens[0]).toEqual value: 'this/function', scopes: ['source.shell', 'meta.function.shell', 'entity.name.function.shell']
expect(tokens[2]).toEqual value: '()', scopes: ['source.shell', 'meta.function.shell', 'punctuation.definition.arguments.shell']

{tokens} = grammar.tokenizeLine('and,for (( this ))')

expect(tokens[0]).toEqual value: 'and,for ', scopes: ['source.shell']
expect(tokens[1]).toEqual value: '((', scopes: ['source.shell', 'string.other.math.shell', 'punctuation.definition.string.begin.shell']

{tokens} = grammar.tokenizeLine('in🚀case of stuff')

it "tokenizes herestrings", ->
delimsByScope =
Expand Down Expand Up @@ -140,16 +162,22 @@ describe "Shell script grammar", ->
expect(tokens[1][0]).toEqual value: 'stuff', scopes: ['source.shell', 'string.unquoted.heredoc.no-indent.' + scope + '.shell', 'source.' + scope + '.embedded.shell']
expect(tokens[2][0]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.no-indent.' + scope + '.shell', 'keyword.control.heredoc-token.shell']

tokens = grammar.tokenizeLines """
<<RANDOMTHING
stuff
RANDOMTHING
"""
delims = [
"RANDOMTHING"
"RUBY@1.8"
]

expect(tokens[0][0]).toEqual value: '<<', scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.operator.heredoc.shell']
expect(tokens[0][1]).toEqual value: 'RANDOMTHING', scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']
expect(tokens[1][0]).toEqual value: 'stuff', scopes: ['source.shell', 'string.unquoted.heredoc.shell']
expect(tokens[2][0]).toEqual value: 'RANDOMTHING', scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']
for delim of delims
tokens = grammar.tokenizeLines """
<<#{delim}
stuff
#{delim}
"""

expect(tokens[0][0]).toEqual value: '<<', scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.operator.heredoc.shell']
expect(tokens[0][1]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']
expect(tokens[1][0]).toEqual value: 'stuff', scopes: ['source.shell', 'string.unquoted.heredoc.shell']
expect(tokens[2][0]).toEqual value: delim, scopes: ['source.shell', 'string.unquoted.heredoc.shell', 'keyword.control.heredoc-token.shell']

it "tokenizes shebangs", ->
{tokens} = grammar.tokenizeLine('#!/bin/sh')
Expand Down Expand Up @@ -178,6 +206,19 @@ describe "Shell script grammar", ->
expect(tokens[3]).toEqual value: '}', scopes: ['source.shell', 'variable.other.bracket.shell', 'variable.other.bracket.shell', 'punctuation.definition.variable.shell']
expect(tokens[4]).toEqual value: '}', scopes: ['source.shell', 'variable.other.bracket.shell', 'punctuation.definition.variable.shell']

it "tokenizes case blocks", ->
{tokens} = grammar.tokenizeLine('case word in esac);; esac')

expect(tokens[0]).toEqual value: 'case', scopes: ['source.shell', 'meta.scope.case-block.shell', 'keyword.control.shell']
expect(tokens[1]).toEqual value: ' word ', scopes: ['source.shell', 'meta.scope.case-block.shell']
expect(tokens[2]).toEqual value: 'in', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell', 'keyword.control.shell']
expect(tokens[3]).toEqual value: ' ', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell']
expect(tokens[4]).toEqual value: 'esac', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell', 'meta.scope.case-clause.shell', 'meta.scope.case-pattern.shell']
expect(tokens[5]).toEqual value: ')', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell', 'meta.scope.case-clause.shell', 'meta.scope.case-pattern.shell', 'punctuation.definition.case-pattern.shell']
expect(tokens[6]).toEqual value: ';;', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell', 'meta.scope.case-clause.shell', 'punctuation.terminator.case-clause.shell']
expect(tokens[7]).toEqual value: ' ', scopes: ['source.shell', 'meta.scope.case-block.shell', 'meta.scope.case-body.shell']
expect(tokens[8]).toEqual value: 'esac', scopes: ['source.shell', 'meta.scope.case-block.shell', 'keyword.control.shell']

describe "indentation", ->
editor = null

Expand Down