2016-10-15 06:52:21 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file runs the highlighter on a specified file
|
|
|
|
# i.e. parses the file with the highlighter. Outputs
|
|
|
|
# running time (stderr) and resulting region_highlight
|
|
|
|
# (file parse.out, or $2 if given).
|
|
|
|
#
|
2016-10-15 07:06:52 +00:00
|
|
|
# Can be also run in line-wise mode on own input (-o
|
|
|
|
# option in $1), no region_highlight file then.
|
|
|
|
#
|
2016-10-15 06:52:21 +00:00
|
|
|
|
|
|
|
[[ -z "$ZSH_VERSION" ]] && exec /usr/bin/env zsh -f -c "source \"$0\" \"$1\" \"$2\" \"$3\""
|
|
|
|
|
|
|
|
ZERO="${(%):-%N}"
|
|
|
|
|
|
|
|
if [[ -e "${ZERO}/../hsmw-highlight" ]]; then
|
|
|
|
source "${ZERO}/../hsmw-highlight"
|
|
|
|
elif [[ -e "../hsmw-highlight" ]]; then
|
|
|
|
source "../hsmw-highlight"
|
|
|
|
elif [[ -e "${ZERO}/hsmw-highlight" ]]; then
|
|
|
|
source "${ZERO}/hsmw-highlight"
|
|
|
|
elif [[ -e "./hsmw-highlight" ]]; then
|
|
|
|
source "./hsmw-highlight"
|
|
|
|
else
|
|
|
|
print -u2 "Could not find hsmw-highlight, aborting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-10-15 07:56:08 +00:00
|
|
|
zmodload zsh/zprof
|
2016-10-15 07:33:14 +00:00
|
|
|
autoload is-at-least
|
|
|
|
|
2016-10-30 06:45:14 +00:00
|
|
|
setopt interactive_comments
|
|
|
|
|
2016-10-15 07:06:52 +00:00
|
|
|
# Own input?
|
parse.zsh: Sophisticated own input on -oo
Running time: 2.8915790000
num calls time self name
-----------------------------------------------------------------------------------
1) 350 2884,07 8,24 100,00% 1716,24 4,90 59,51% -hsmw-highlight-process
2) 2800 753,47 0,27 26,12% 753,47 0,27 26,12% -hsmw-highlight-string
3) 2450 191,31 0,08 6,63% 131,09 0,05 4,55% -hsmw-highlight-check-path
4) 3850 93,37 0,02 3,24% 93,37 0,02 3,24% -hsmw-highlight-expand-path
5) 1400 66,66 0,05 2,31% 66,66 0,05 2,31% (anon)
6) 8400 54,86 0,01 1,90% 54,86 0,01 1,90% -hsmw-highlight-is-redirection
7) 1400 39,59 0,03 1,37% 39,59 0,03 1,37% -hsmw-highlight-main-type
8) 700 10,83 0,02 0,38% 10,83 0,02 0,38% -hsmw-highlight-check-assign
2016-10-16 06:37:07 +00:00
|
|
|
if [[ "$1" = "-o" || "$1" = "-oo" ]]; then
|
2016-10-15 07:06:52 +00:00
|
|
|
typeset -a input
|
parse.zsh: Sophisticated own input on -oo
Running time: 2.8915790000
num calls time self name
-----------------------------------------------------------------------------------
1) 350 2884,07 8,24 100,00% 1716,24 4,90 59,51% -hsmw-highlight-process
2) 2800 753,47 0,27 26,12% 753,47 0,27 26,12% -hsmw-highlight-string
3) 2450 191,31 0,08 6,63% 131,09 0,05 4,55% -hsmw-highlight-check-path
4) 3850 93,37 0,02 3,24% 93,37 0,02 3,24% -hsmw-highlight-expand-path
5) 1400 66,66 0,05 2,31% 66,66 0,05 2,31% (anon)
6) 8400 54,86 0,01 1,90% 54,86 0,01 1,90% -hsmw-highlight-is-redirection
7) 1400 39,59 0,03 1,37% 39,59 0,03 1,37% -hsmw-highlight-main-type
8) 700 10,83 0,02 0,38% 10,83 0,02 0,38% -hsmw-highlight-check-assign
2016-10-16 06:37:07 +00:00
|
|
|
if [[ "$1" = "-o" ]]; then
|
|
|
|
input+=( "./parse.zsh ../hsmw-highlight parse2.out" )
|
|
|
|
input+=( "rm -f parse*.out" )
|
|
|
|
input+=( "./mh-parse.zsh ../hsmw-highlight > out" )
|
|
|
|
input+=( "if [[ -o multibyte ]]; then echo multibyte is set; fi" )
|
|
|
|
input+=( "[[ \"a\" = *[[:alpha:]_-][[:alpha:]]# ]] && echo yes" )
|
|
|
|
input+=( 'git tag -a v0.98 -m "Syntax highlighting of the history entries"' )
|
|
|
|
input+=( 'func() { echo "a" >! phist2.db; echo "b" >>! phist2.db; fc -Rap "phist2.db"; list=( ${history[@]} ); echo "${history[1]}"; }' )
|
|
|
|
else
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
input+=( 'typeset -a list\n() {\necho "a" >! phist2.db\necho "b" >>! phist2.db\nfc -Rap "phist2.db"\nlist=( ${history[@]} )\necho "${history[2]}"\necho "${history[1]}"\necho "${#history}";\ninteger size="${#history}"\nsize+=1\necho "$size" / "${history[$size]}"\nlist=( "${history[$size]}" ${history[@]} )\n}' )
|
|
|
|
fi
|
2016-10-15 07:06:52 +00:00
|
|
|
|
|
|
|
typeset -a long_input
|
|
|
|
integer i
|
|
|
|
for (( i=1; i<= 50; i ++ )); do
|
|
|
|
long_input+=( "${input[@]}" )
|
|
|
|
done
|
|
|
|
|
|
|
|
typeset -F SECONDS
|
|
|
|
SECONDS=0
|
|
|
|
|
|
|
|
-hsmw-highlight-init
|
*highlight: Optimization – save options outside main highlighting fun
Lower 18xx are being seen, like below:
Running time: 1.8632000000
num calls time self name
-----------------------------------------------------------------------------------
1) 350 1855,72 5,30 100,00% 1376,89 3,93 74,19% -hsmw-highlight-process
2) 2800 342,38 0,12 18,45% 342,38 0,12 18,45% -hsmw-highlight-string
3) 2450 80,16 0,03 4,32% 80,16 0,03 4,32% -hsmw-highlight-check-path
4) 1400 38,99 0,03 2,10% 38,99 0,03 2,10% -hsmw-highlight-main-type
5) 350 9,83 0,03 0,53% 9,83 0,03 0,53% -hsmw-highlight-stack-pop
6) 350 7,47 0,02 0,40% 7,47 0,02 0,40% -hsmw-highlight-path-separators
7) 1 0,07 0,07 0,00% 0,07 0,07 0,00% -hsmw-highlight-fill-option-variables
8) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init
2016-10-25 14:17:39 +00:00
|
|
|
|
|
|
|
local right_brace_is_recognised_everywhere
|
|
|
|
integer path_dirs_was_set multi_func_def ointeractive_comments
|
|
|
|
-hsmw-highlight-fill-option-variables
|
|
|
|
|
2016-10-15 07:06:52 +00:00
|
|
|
local line
|
|
|
|
for line in "${long_input[@]}"; do
|
|
|
|
reply=( )
|
|
|
|
-hsmw-highlight-process "$line"
|
|
|
|
done
|
|
|
|
|
|
|
|
print "Running time: $SECONDS"
|
2016-10-15 07:56:08 +00:00
|
|
|
zprof | head
|
2016-10-15 07:06:52 +00:00
|
|
|
# File input?
|
|
|
|
elif [[ -r "$1" ]]; then
|
2016-10-15 06:52:21 +00:00
|
|
|
# Load from given file
|
|
|
|
local buf="$(<$1)"
|
|
|
|
|
|
|
|
typeset -F SECONDS
|
|
|
|
SECONDS=0
|
|
|
|
|
|
|
|
reply=( )
|
|
|
|
-hsmw-highlight-init
|
*highlight: Optimization – save options outside main highlighting fun
Lower 18xx are being seen, like below:
Running time: 1.8632000000
num calls time self name
-----------------------------------------------------------------------------------
1) 350 1855,72 5,30 100,00% 1376,89 3,93 74,19% -hsmw-highlight-process
2) 2800 342,38 0,12 18,45% 342,38 0,12 18,45% -hsmw-highlight-string
3) 2450 80,16 0,03 4,32% 80,16 0,03 4,32% -hsmw-highlight-check-path
4) 1400 38,99 0,03 2,10% 38,99 0,03 2,10% -hsmw-highlight-main-type
5) 350 9,83 0,03 0,53% 9,83 0,03 0,53% -hsmw-highlight-stack-pop
6) 350 7,47 0,02 0,40% 7,47 0,02 0,40% -hsmw-highlight-path-separators
7) 1 0,07 0,07 0,00% 0,07 0,07 0,00% -hsmw-highlight-fill-option-variables
8) 1 0,01 0,01 0,00% 0,01 0,01 0,00% -hsmw-highlight-init
2016-10-25 14:17:39 +00:00
|
|
|
|
|
|
|
local right_brace_is_recognised_everywhere
|
|
|
|
integer path_dirs_was_set multi_func_def ointeractive_comments
|
|
|
|
-hsmw-highlight-fill-option-variables
|
|
|
|
|
2016-10-15 06:52:21 +00:00
|
|
|
-hsmw-highlight-process "$buf"
|
|
|
|
|
|
|
|
print "Running time: $SECONDS"
|
2016-10-15 07:56:08 +00:00
|
|
|
zprof | head
|
2016-10-15 06:52:21 +00:00
|
|
|
|
|
|
|
# This output can be diffed to detect changes in operation
|
|
|
|
if [[ -z "$2" ]]; then
|
2016-10-16 06:30:41 +00:00
|
|
|
print -rl -- "${reply[@]}" >! out.parse
|
2016-10-15 06:52:21 +00:00
|
|
|
else
|
|
|
|
print -rl -- "${reply[@]}" >! "$2"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
print -u2 "Usage: ./mh-parse.zsh {to-parse file} [region_highlight output file]"
|
|
|
|
exit 2
|
|
|
|
else
|
|
|
|
print -u2 "Unreadable to-parse file \`$1', aborting"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
# vim:ft=zsh
|