From f6367792f2d2cf7da810476202bc2235a41dd6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 29 Oct 2023 01:35:05 +0200 Subject: [PATCH] Try to enhance 'sh' highlighting. [GB.HIGHLIGHT] * NEW: Try to enhance 'sh' highlighting. Bash syntax is really cumbersome, so it will never be perfect. --- comp/src/gb.highlight/.src/Main.module | 3 +- comp/src/gb.highlight/highlight/sh.highlight | 40 ++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/comp/src/gb.highlight/.src/Main.module b/comp/src/gb.highlight/.src/Main.module index fc8485882..642973f78 100644 --- a/comp/src/gb.highlight/.src/Main.module +++ b/comp/src/gb.highlight/.src/Main.module @@ -18,6 +18,7 @@ Public Sub Main() 'TextHighlighter.Register("~/gambas/git/master/app/src/gambas3/highlight/conflict.highlight") 'File.Save("~/test.html", TextHighlighter["conflict"].ToHTML(File.Load("test/conflict.txt"))) 'File.Save("~/test.html", TextHighlighter["javascript"].ToHTML(File.Load("~/asap/omogen/master/src/kernel/guygle.cgi/javascript/selectr.js"))) - File.Save("~/test.html", TextHighlighter["webpage"].ToHTML(File.Load(Application.Path &/ ".hidden/test/Webpage1.webpage"))) + 'File.Save("~/test.html", TextHighlighter["webpage"].ToHTML(File.Load(Application.Path &/ ".hidden/test/Webpage1.webpage"))) + File.Save("~/test.html", TextHighlighter["sh"].ToHTML(File.Load("~/gambas/git/master/comp/src/gb.desktop/xdg-utils/xdg-open"))) End diff --git a/comp/src/gb.highlight/highlight/sh.highlight b/comp/src/gb.highlight/highlight/sh.highlight index d7934ed53..c13f446f4 100644 --- a/comp/src/gb.highlight/highlight/sh.highlight +++ b/comp/src/gb.highlight/highlight/sh.highlight @@ -1,21 +1,47 @@ +escape{Normal}: + match /\\./ +shebang{Preprocessor}: + from /^#!/ comment: + from /^#/ from /#\s/ number: match /[+-]?[0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)?/ match /0x[0-9a-fA-F]+/ -string: - from " to " +string.simple{String}: from ' to ' escape: - match /\\[fnrtv0'"\\]/ - match /\\c[A-Za-z]/ + match /\\./ +string.double{String}: + from " to " + escape: + match /\\[$`'"\\]/ + expansion{Datatype}: + match /\$[A-Za-z0-9_]+/ + expansion.brace{Datatype}: + from ${ to } with sh + command{Datatype}: + from ` to ` with sh +string.ansi{String}: + from $' to ' + match /\\[abeEfnrtv\\'"?]/ + match /\\[0-7]{3}/ match /\\x[0-9a-fA-F]{2}/ match /\\u[0-9a-fA-F]{4}/ - match /\\u{[0-9a-fA-F]+}/ + match /\\u[0-9a-fA-F]{8}/ + match /\\c[a-zA-Z]/ +expansion{Datatype}: + match /\$[A-Za-z0-9_]+/ +expansion.brace{Datatype}: + from ${ to } with sh +command{Datatype}: + from ` to ` with sh keyword: - word function do else test for to in fi if elif then return exit while until done break continue select case esac + keyword function do else test for to in fi if elif then return exit while until done break continue select case esac operator: symbol -gt -lt -ge -ne -le -eq - symbol { } $ # [ ] <<< . + << = >> == - ~ += ( , != * -= &= ;; ) < % & ]; @ ! ; > | ? ^ : <= / ` + symbol { } $ # [ ] <<< . + << = >> == - ~ += ( , != * -= &= ;; ) < % & ]; @ ! ; > | ? ^ : <= / function: keyword echo read cd which rm cp mv rmdir cat grep awk tr sed sleep clear sudo su source eval export time date pwd set unset chown chmod exec alias unalias bg bind builtin caller command compgen complete compopt declare dirs disown enable fc fg getopts hash help history jobs kill let local logout mapfile popd printf pushd readarray readonly shift shopt suspend test times trap type typeset ulimit umask wait +identifier: + match /[A-Za-z_][A-Za-z_0-9]*/