Created
September 9, 2016 14:21
-
-
Save casimir/23c4e708d2b11d480c2c8b39555e430f to your computer and use it in GitHub Desktop.
ERE → BRE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Check with the examples from the spec (http://vimdoc.sourceforge.net/htmldoc/options.html#modeline) | |
# ./test_re.sh 'vi:noai:sw=3 ts=6' '/\* vim: set ai tw=75: \*/' '# kak: se ft=sh' | |
old_parse() { | |
printf %s\\n "$1" | gsed -r \ | |
-e 's/^(.+\s\w+:\s?(set?)?\s)//' \ | |
-e 's/:?\s[^a-zA-Z0-9_=-]+$//' \ | |
-e 's/:/ /g' | |
} | |
new_parse() { | |
printf %s\\n "$2" | $1 \ | |
-e 's/^[^:]\{1,\}://' \ | |
-e 's/[ \t]*set\{0,1\}[ \t]//' \ | |
-e 's/:[^a-zA-Z0-9_=-]*$//' \ | |
-e 's/:/ /g' | |
} | |
check() { | |
echo $(old_parse "$1") | |
echo $(new_parse sed "$1") | |
echo $(new_parse gsed "$1") | |
} | |
for arg in "$@"; do | |
printf '> "%s"\n' "$arg" | |
echo ===== | |
check "$arg" | |
echo ===== | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment