Hi,

I've noted a number of issues with the bourne shell syntax highlighting,
and have finally got around to coding a patch to fix them.

1. "while" highlighting broken after function definitions:
> foo() { }; while true; do :; done

2. "while" highlighting whole predicate unnecessarily:
> while pgrep vim; do :; done

3. Marking escaped quotes as errors after parameter dereference
operators:
> echo ${foo+\"yes\"}
> echo ${foo+\'yes\'}

4. Escaping close parens broken in case matches:
> case x in \));; esac

5. Escaping quotes broken in lots of places:
echo \"hello\"
echo \'hello\'
echo \`hello\`

My motivation - and primary testcase - has been GNU Libtool
(/usr/bin/libtool), which has over 7500 lines of fairly complex sh
constructs.  With the attached patch it seems to get highlighted quite
well.

Ed Catmur

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

--- vim71/runtime/syntax/sh.vim	2007/10/20 19:35:31	1.1
+++ vim71/runtime/syntax/sh.vim	2007/10/20 21:46:17
@@ -71,7 +71,7 @@ syn case match
 " Clusters: [EMAIL PROTECTED] clusters {{{1
 "==================================
 syn cluster shCaseEsacList	contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq
-syn cluster shCaseList	[EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
+syn cluster shCaseList	[EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shCtrlSeq
 syn cluster shColonList	[EMAIL PROTECTED]
 syn cluster shCommandSubList	contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq
 syn cluster shCurlyList	contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
@@ -81,7 +81,7 @@ syn cluster shDerefVarList	contains=shDe
 syn cluster shEchoList	contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq
 syn cluster shExprList1	contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
 syn cluster shExprList2	[EMAIL PROTECTED],@shCaseList,shTest
-syn cluster shFunctionList	[EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq
+syn cluster shFunctionList	[EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq
 if exists("b:is_kornshell") || exists("b:is_bash")
  syn cluster shFunctionList	add=shDblBrace,shDblParen
 endif
@@ -182,7 +182,6 @@ else
  syn region shFor	matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2	[EMAIL PROTECTED],shDblParen skipwhite nextgroup=shCurlyIn
 endif
 if exists("b:is_kornshell") || exists("b:is_bash")
- syn cluster shCaseList add=shRepeat
  syn region shRepeat   matchgroup=shLoop   start="\<while\>" end="\<in\>" end="\<do\>"me=e-2	[EMAIL PROTECTED],shDblParen,shDblBrace
  syn region shRepeat   matchgroup=shLoop   start="\<until\>" end="\<in\>" end="\<do\>"me=e-2	[EMAIL PROTECTED],shDblParen,shDblBrace
  syn region shCaseEsac matchgroup=shConditional start="\<select\>" matchgroup=shConditional end="\<in\>" end="\<do\>" [EMAIL PROTECTED]
@@ -195,9 +194,9 @@ syn match  shComma     contained	","
 
 " Case: case...esac {{{1
 " ====
-syn match   shCaseBar	contained skipwhite "[^|"`'()]\{-}|"hs=e		nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
+syn match   shCaseBar	contained skipwhite "\([^|"`'()\\]\|\\.\)\{-}|"hs=e		nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
 syn match   shCaseStart	contained skipwhite skipnl "("			nextgroup=shCase,shCaseBar
-syn region  shCase	contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t]\|\\.\)\{-})"ms=s,hs=e  end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment
+syn region  shCase	contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t\\]\|\\.\)\{-})"ms=s,hs=e  end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment
 if g:sh_fold_enabled
  syn region  shCaseEsac	fold matchgroup=shConditional start="\<case\>" end="\<esac\>"	[EMAIL PROTECTED]
 else
@@ -209,14 +208,14 @@ if exists("b:is_bash")
 else
  syn region  shCaseExSingleQuote	matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
 endif
-syn region  shCaseSingleQuote	matchgroup=shOperator start=+'+ end=+'+		contains=shStringSpecial		skipwhite skipnl nextgroup=shCaseBar	contained
-syn region  shCaseDoubleQuote	matchgroup=shOperator start=+"+ skip=+\\\\\|\\.+ end=+"+	[EMAIL PROTECTED],shStringSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
-syn region  shCaseCommandSub	start=+`+ skip=+\\\\\|\\.+ end=+`+		[EMAIL PROTECTED]		skipwhite skipnl nextgroup=shCaseBar	contained
+syn region  shCaseSingleQuote	matchgroup=shOperator start=+\\\@<!'+ end=+'+		contains=shStringSpecial		skipwhite skipnl nextgroup=shCaseBar	contained
+syn region  shCaseDoubleQuote	matchgroup=shOperator start=+\\\@<!"+ skip=+\\\\\|\\.+ end=+"+	[EMAIL PROTECTED],shStringSpecial	skipwhite skipnl nextgroup=shCaseBar	contained
+syn region  shCaseCommandSub	start=+\\\@<!`+ skip=+\\\\\|\\.+ end=+`+		[EMAIL PROTECTED]		skipwhite skipnl nextgroup=shCaseBar	contained
 
 " Misc: {{{1
 "======
 syn match   shWrapLineOperator "\\$"
-syn region  shCommandSub   start="`" skip="\\\\\|\\." end="`" [EMAIL PROTECTED]
+syn region  shCommandSub   start="\\\@<!`" skip="\\\\\|\\." end="`" [EMAIL PROTECTED]
 
 " $() and $(()): {{{1
 " $(..) is not supported by sh (Bourne shell).  However, apparently
@@ -247,7 +246,7 @@ if exists("b:is_bash")
 
 syn match   shSource	"^\.\s"
 syn match   shSource	"\s\.\s"
-syn region  shColon	start="^\s*:" end="$\|" end="#"me=e-1 [EMAIL PROTECTED]
+syn region  shColon	start="^\s*:" end="$\|" end="[^\\]#"me=e-1 [EMAIL PROTECTED]
 
 " String And Character Constants: {{{1
 "================================
@@ -263,8 +262,8 @@ if exists("b:is_bash")
 else
  syn region  shExSingleQuote	matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+	contains=shStringSpecial
 endif
-syn region  shSingleQuote	matchgroup=shOperator start=+'+ end=+'+		contains=shStringSpecial,@Spell
-syn region  shDoubleQuote	matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+	[EMAIL PROTECTED],shStringSpecial,@Spell
+syn region  shSingleQuote	matchgroup=shOperator start=+\\\@<!'+ end=+'+		contains=shStringSpecial,@Spell
+syn region  shDoubleQuote	matchgroup=shOperator start=+\\\@<!"+ skip=+\\"+ end=+"+	[EMAIL PROTECTED],shStringSpecial,@Spell
 syn match   shStringSpecial	"[^[:print:]]"	contained
 syn match   shStringSpecial	"\%(\\\\\)*\\[\\"'`$()#]"
 syn match   shSpecial	"[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]"
@@ -275,7 +274,7 @@ syn match   shSpecial	"^\%(\\\\\)*\\[\\"
 syn cluster    shCommentGroup	contains=shTodo,@Spell
 syn keyword    shTodo	contained	COMBAK FIXME TODO XXX
 syn match      shComment	"^\s*\zs#.*$"	[EMAIL PROTECTED]
-syn match      shComment	"#.*$"	[EMAIL PROTECTED]
+syn match      shComment	"\\\@<!#.*$"	[EMAIL PROTECTED]
 
 " Here Documents: {{{1
 " =========================================
@@ -399,9 +398,8 @@ if exists("b:is_bash") || exists("b:is_k
  syn region shDerefPattern	contained	start="{" end="}"	contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
  syn match  shDerefEscape	contained	'\%(\\\\\)*\\.'
 endif
-syn region shDerefString	contained	matchgroup=shOperator start=+'+ end=+'+		contains=shStringSpecial
-syn region shDerefString	contained	matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+	[EMAIL PROTECTED],shStringSpecial
-syn match  shDerefString	contained	"\\["']"
+syn region shDerefString	contained	matchgroup=shOperator start=+\\\@<!'+ end=+'+		contains=shStringSpecial
+syn region shDerefString	contained	matchgroup=shOperator start=+\\\@<!"+ skip=+\\"+ end=+"+	[EMAIL PROTECTED],shStringSpecial
 
 if exists("b:is_bash")
  " bash : ${parameter:offset}
@@ -541,7 +539,6 @@ hi def link shFunctionKey		Function
 hi def link shFunctionName		Function
 hi def link shNumber		Number
 hi def link shOperator		Operator
-hi def link shRepeat		Repeat
 hi def link shSet		Statement
 hi def link shSetList		Identifier
 hi def link shShellVariables		PreProc

Raspunde prin e-mail lui