# $MirOS: contrib/code/jupp/syntax/sh.jsf.in,v 1.8 2020/04/13 16:05:19 tg Exp $
#-
# JOE syntax highlight file for sh/ksh/bash

# Think about:
# $'....'
# $(...)
# ${...}

# <<EOF
#  ....
# EOF


# Always reparse from beginning
-


# Colors

=Idle
=Comment 	green
=Constant 	cyan
=Escape 	bold cyan
=Keyword 	bold
=Var		magenta
=Parenthesis	yellow
=Connect	bold green
=Bad		bold red

# Syntax

:idle Idle
	*		idlew
	" \t\n"		idle
	"#"		comment		recolor=-1
	"\\"		escape		recolor=-1
	"$"		subst		recolor=-1
	"'"		string_sq	recolor=-1
	"\""		string_dq	recolor=-1
	"\`"		string_bq	recolor=-1
	"()"		paren		noeat
	"a-z{}![].:"	ident		buffer
	"|&"		connector	recolor=-1
	"<>"		redir		noeat
	"0123456789"	redirnum	recolor=-1

:idlew Idle
	*		idlew
	" \t\n"		idle
	"\\"		escape		recolor=-1
	"$"		subst		recolor=-1
	"'"		string_sq	recolor=-1
	"\""		string_dq	recolor=-1
	"\`"		string_bq	recolor=-1
	"()"		paren		noeat
	"a-z{}![].:"	ident		buffer
	"|&"		connector	recolor=-1
	"<>"		redir		noeat
	"0123456789"	redirnum	recolor=-1

:comment Comment
	*		comment
	"\n"		idle

:escape Escape
	*		idle

:subst Var
	*		idlew
	" \t\n"		idle
	"'"		string_sq	recolor=-2
	"\""		string_dq	recolor=-2
	"("		paren		noeat recolor=-2
	"{"		subst_brack
	"a-zA-Z_"	subst_name
	"0-9*@?\-$!"	idlew

:subst_name Var
	*		idlew		noeat recolor=-1
	" \t\n"		idle		noeat recolor=-1
	"a-zA-Z0-9_"	subst_name

:subst_brack Var
	*		subst_brack
	"\\"		subst_brack_cq
	"\""		subst_brack_dq
	"\'"		subst_brack_sq
	"}"		idlew

:subst_brack_cq Var
	*		subst_brack

:subst_brack_dq Var
	*		subst_brack_dq
	"\""		subst_brack

:subst_brack_sq Var
	*		subst_brack_sq
	"\'"		subst_brack

# Simplest case: no quoting allowed
:string_sq Constant
	*		string_sq
	"\'"		idlew

# double-quote: quoting, backqoutes and substitution allowed
:string_dq Constant
	*		string_dq
	"$"		string_dq_subst	recolor=-1
	"\""		idlew
	"\\"		string_dq_esc	recolor=-1
	"`"		string_dq_bq	recolor=-1

:string_dq_subst Var
	*		string_dq	noeat recolor=-2
	"\""		idlew
	"$0-9!_\-?*@"	string_dq
	"a-zA-Z_"	string_dq_subst_name
	"{"		string_dq_subst_brack

:string_dq_subst_name Var
	*		string_dq	recolor=-1 noeat
	"a-zA-Z0-9_"	string_dq_subst_name

:string_dq_subst_brack Var
	*		string_dq_subst_brack
	"}"		string_dq

:string_dq_esc Escape
	*		string_dq	recolor=-2
	"$`\"\\"	string_dq
	"\n"		string_dq	recolor=-2

:string_dq_bq Constant
	*		string_dq_bq
	"$"		string_dq_bq_subst	recolor=-1
	"\`"		string_dq
	"\\"		string_dq_bq_esc	recolor=-1

:string_dq_bq_subst Var
	*		string_dq_bq	noeat recolor=-2
	"$0-9!_\-?*@"	string_dq_bq
	"a-zA-Z_"	string_dq_bq_subst_name
	"{"		string_dq_bq_subst_brack

:string_dq_bq_subst_name Var
	*		string_dq_bq	recolor=-1 noeat
	"a-zA-Z0-9_"	string_dq_bq_subst_name

:string_dq_bq_subst_brack Var
	*		string_dq_bq_subst_brack
	"}"		string_dq_bq

:string_dq_bq_esc Escape
	*		string_dq_bq	recolor=-2
	"$`\"\\"	string_dq_bq
	"\n"		string_dq_bq	recolor=-2


# backquote
:string_bq Constant
	*		string_bq
	"$"		string_bq_subst	recolor=-1
	"\`"		idlew
	"\\"		string_bq_esc	recolor=-1

# escape in backquote
:string_bq_esc Escape
	*		string_bq	recolor=-2
	"$`\"\\"	string_bq
	"\n"		string_bq	recolor=-2

# Substitution in a backquote
:string_bq_subst Var
	*		string_bq	noeat recolor=-2
	"$0-9!_\-?*@"	string_bq
	"a-zA-Z_"	string_bq_subst_name
	"{"		string_bq_subst_brack

:string_bq_subst_name Var
	*		string_bq	recolor=-1 noeat
	"a-zA-Z0-9_"	string_bq_subst_name

:string_bq_subst_brack Var
	*		string_bq_subst_brack
	"}"		string_bq


:paren Parenthesis
	*		idle		noeat
	"("		paren
	")"		paren

:bad Bad
	*		idle

:ident Idle
	*		idlew		noeat
	"()"		bad		noeat recolor=-1
	"a-z{}![].:"	ident
	" \t\n&|;<>"	idle		noeat strings
	"!"		kw
	"{"		kw
	"}"		kw
	"[["		kw
	"]]"		kw
	"["		kw
	"]"		kw
# primary keywords
	"case"		kw
	"do"		kw
	"done"		kw
	"elif"		kw
	"else"		kw
	"esac"		kw
	"fi"		kw
	"for"		kw
	"if"		kw
	"in"		kw
	"then"		kw
	"until"		kw
	"while"		kw
# I think these are basically keywords too
	"break"		kw
	"continue"	kw
	"return"	kw
	"eval"		kw
	"exec"		kw
	"exit"		kw
	"test"		kw	# doesn't have to be a shell command
# variable management
	"shift"		kw
	"unset"		kw
	"export"	kw
	"readonly"	kw
# input
	"read"		kw
# job control (not likely to be used in scripts)
	"bg"		kw
	"fg"		kw
	"jobs"		kw
	"suspend"	kw
# job control (useful in scripts)
	"kill"		kw
	"wait"		kw
# environment control
	"cd"		kw
	"chdir"		kw
	"pwd"		kw
	"ulimit"	kw
	"umask"		kw
# signal handling
	"trap"		kw
# misc shell control
	"hash"		kw
	"type"		kw
	"times"		kw
	"set"		kw
# shell builtins
	"echo"		kw
	"getopts"	kw
	"login"		kw	# not bash (logout is)
	"newgrp"	kw	# not in bash
	"stop"		kw	# not in bash (suspends a process)
# additional ksh builtins
	"select"	kw
	"function"	kw
	"time"		kw
	"."		kw
	":"		kw
	"alias"		kw
	"autoload"	kw
	"cat"		kw
	"command"	kw
	"extproc"	kw
	"false"		kw
	"fc"		kw
	"functions"	kw
	"history"	kw
	"integer"	kw
	"let"		kw
	"local"		kw
	"mknod"		kw
	"nameref"	kw
	"nohup"		kw
	"print"		kw
	"r"		kw
	"realpath"	kw
	"rename"	kw
	"sleep"		kw
	"true"		kw
	"typeset"	kw
	"unalias"	kw
	"whence"	kw
# additional bash builtins
	"source"	kw
	"bind"		kw
	"builtin"	kw
	"compgen"	kw
	"complete"	kw
	"declare"	kw
	"dirs"		kw
	"disown"	kw
	"enable"	kw
	"help"		kw
	"logout"	kw
	"popd"		kw
	"printf"	kw
	"pushd"		kw
	"shopt"		kw
done

:kw Keyword
	*		idlew	noeat

:connector Connect
	*		idle	noeat
	"|&"		connector

:redirnum Connect
	*		idlew	noeat recolor=-2
	"<>"		redir

:redir Connect
	*		idle	noeat
	"<>&0123456789p-" redir
