| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Demo of word evaluation.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # test/gold/word-eval.sh <function name>
|
| 7 | #
|
| 8 | # Bug with the current algorithm: IFS=\\
|
| 9 | #
|
| 10 | # 2025-05: There is also a sorting issue, dependent on locale:
|
| 11 | #
|
| 12 | # bin/hello_preamble.sh vs. bin/hello-test.sh - which comes first?
|
| 13 |
|
| 14 | set -- 'a*b' 'c d'
|
| 15 | typeset -a myarray
|
| 16 | myarray=('w x' 'y*z', 'bin')
|
| 17 | space=' '
|
| 18 | glob='*h b*' # anything that ends with h, then anything that begins with b
|
| 19 |
|
| 20 | #spec/bin/argv.py -"$@"-$space-"$space-${myarray[@]}"/$glob
|
| 21 | for item in -"$@"-$space-"$space-${myarray[@]}"/$glob; do
|
| 22 | echo "$item"
|
| 23 | done
|
| 24 |
|
| 25 | # ['-a b', 'c d-', '- -w x', 'y z,', 'bin/opypy-osh', 'bin/osh', 'bin/sh', 'benchmarks', 'bin', 'build']
|
| 26 |
|
| 27 | # I have a single word.
|
| 28 | # I evaluate all the parts:
|
| 29 | #
|
| 30 | # "$@" -> ArrayPartValue
|
| 31 | # $space -> StringPartValue
|
| 32 | # "$space" -> StringPartValue
|
| 33 | # $myarray -> ArrayPartValue
|
| 34 | # $glob -> StringPartValue
|
| 35 | #
|
| 36 | # Then I _MakeWordFrames. Each frame is (frag, list)
|
| 37 |
|
| 38 | # (frag, do_split_elide)
|
| 39 | #
|
| 40 | # [ ('-a b', False) ]
|
| 41 | # [ ('c d', False), ('-', False), (' ', True), ('-', False), (' ', False),
|
| 42 | # ('-', False), ('w x', False) ]
|
| 43 | # [ ('y z', False) ]
|
| 44 | # [ ('bin', False), ('*h b*', True) ]
|
| 45 |
|
| 46 |
|
| 47 | # Then for each frame, do _EvalWordFrame. Respect the boolean, and do
|
| 48 | # glob.GlobEscape or self.splitter.Escape(frag)
|
| 49 |
|
| 50 | # '-a b'
|
| 51 | # -> Glob escape
|
| 52 | # '-a b'
|
| 53 | # -> Split EScape
|
| 54 | # '-a\ b'
|
| 55 |
|
| 56 | # 'c\ d-'
|
| 57 | # '-'
|
| 58 |
|
| 59 | # Possible fix to IFS='\' problem: do globbing and splitting in two completely
|
| 60 | # separate steps. The Split() function should respect [(frag, bool do_split) ...]
|
| 61 | #
|
| 62 | # If not splitting, then it's easy to emit the span.
|
| 63 |
|
| 64 |
|