fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a53db7256
master
1# localization: skip(private) 2function __fish_tokenizer_state --description"Print the state of the tokenizer at the end of the given string" 3# Go through the token char-by-char in a state machine. 4# The states are: 5# - normal - no quoting is active (the starting state) 6# - single - open single-quote 7# - double - open double 8# - escaped - open \\ - the next character is non-special 9# - single-escaped - open \\ inside single-quotes 10# - double-escaped - open \\ inside double-quotes 11 12argparse --min-args1 --max-args1 i/initial-state= --$argv 13or return 1 14 15set -l state normal 16if set -q _flag_initial_state 17set state$_flag_initial_state 18end 19 20for charin ( string split --"" $argv [ 1 ]) 21switch $char 22case "'" # single-quote 23switch $state 24case normal single-escaped 25set state single 26case single 27set state normal 28end 29case '"' # double-quote 30switch $state 31case normal double-escaped 32set state double 33case double 34set state normal 35end 36case \\ # backslash escapes the next character 37switch $state 38case double 39set state double-escaped 40case double-escaped 41set state double 42case single 43set state single-escaped 44case single-escaped 45set state single 46case normal 47set state escaped 48case escaped 49set state normal 50end 51case "*" # Any other character 52switch $state 53case escaped 54set state normal 55case single-escaped 56set state single 57case double-escaped 58set state double 59end 60end 61end 62 63echo $state 64end