Skip to content

Commit

Permalink
[ShellScript] Add coproc keyword (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols authored and wbond committed Jun 18, 2018
1 parent e6a53b8 commit 4cfa7b9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ShellScript/Bash.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,35 @@ contexts:
captures:
1: storage.type.function.shell
push: [funcdef-body, funcdef-parens, funcdef-name]
- match: \bcoproc{{keyword_boundary_end}}
scope: keyword.other.coproc.shell
push: [cmd-post, cmd-args, coproc-body]

funcdef-bt:
- match: '{{is_function}}'
captures:
1: storage.type.function.shell
push: [funcdef-body-bt, funcdef-parens, funcdef-name]
- match: \bcoproc{{keyword_boundary_end}}
scope: keyword.other.coproc.shell
push: [cmd-post, cmd-args-bt, coproc-body]

coproc-body:
- match: \s*(?=\S+\s*\{)
set:
- meta_content_scope: entity.name.function.coproc.shell
- match: (?=\s*\{)
set:
- match: \{
scope: punctuation.section.braces.begin.shell
set:
- meta_scope: meta.function.coproc.shell
- match: \}
scope: punctuation.section.braces.end.shell
pop: true
- include: main
- match: ""
set: main-with-pop-at-end

funcdef-name:
- match: \s*
Expand Down
40 changes: 40 additions & 0 deletions ShellScript/test/syntax_test_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,46 @@ case $1 in
*)
_G_unquoted_arg=$1 ;;
esac
coproc sed s/^/foo/
# <- keyword.other.coproc
# ^^^ variable.function
coproc ls thisfiledoesntexist; read; 2>&1
# <- keyword.other.coproc
# ^^ meta.function-call variable.function
# ^ keyword.operator
# ^^^^ support.function
# ^ keyword.operator
# ^ constant.numeric.integer.decimal.file-descriptor
# ^^ keyword.operator.assignment.redirection
# ^ constant.numeric.integer.decimal.file-descriptor
coproc awk '{print "foo" $0;fflush()}'
# <- keyword.other.coproc
# ^^^ variable.function
# ^ string.quoted.single punctuation.definition.string.begin
# ^ string.quoted.single punctuation.definition.string.end
{ coproc tee { tee logfile ;} >&3 ;} 3>&1
# <- punctuation.definition.compound.braces.begin
# ^^^^^^ keyword.other.coproc
# ^^^ entity.name.function.coproc
# ^ punctuation.section.braces.begin
# ^^^ variable.function
# ^ punctuation.section.braces.end
# ^^ keyword.operator.assignment.redirection
# ^ constant.numeric.integer.decimal.file-descriptor
# ^ punctuation.definition.compound.braces.end
# ^ constant.numeric.integer.decimal.file-descriptor
# ^^ keyword.operator.assignment.redirection
# ^ constant.numeric.integer.decimal.file-descriptor
coproc foobar {
# ^^^^^^ entity.name.function.coproc
read
# <- meta.function.coproc meta.function-call
}

# <- - meta.function
exec >&${tee[1]} 2>&1
# ^^ keyword.operator.assignment.redirection
# ^ meta.group.expansion.parameter punctuation.definition.variable

###################
# Misc. operators #
Expand Down

0 comments on commit 4cfa7b9

Please sign in to comment.