package shlex
type fishFormat struct {}
func (fishFormat ) Classifier () tokenClassifier {
t := newBaseClassifier (escapeRunes )
t .addWordbreaks ("|;<>&?()" )
return t
}
func (fishFormat ) ClassifyOperator (raw string ) WordbreakType {
switch raw {
case "|" :
return WORDBREAK_PIPE
case "|&" , "&|" :
return WORDBREAK_PIPE_WITH_STDERR
case ">|" :
return WORDBREAK_PIPE
case ";" :
return WORDBREAK_LIST_SEQUENTIAL
case "&&" :
return WORDBREAK_LIST_AND
case "||" :
return WORDBREAK_LIST_OR
case "&" :
return WORDBREAK_LIST_ASYNC
case ">" , ">?" :
return WORDBREAK_REDIRECT_OUTPUT
case ">>" , ">>?" :
return WORDBREAK_REDIRECT_OUTPUT_APPEND
case "&>" , "&>?" :
return WORDBREAK_REDIRECT_OUTPUT_BOTH
case "&>>" , "&>>?" :
return WORDBREAK_REDIRECT_OUTPUT_BOTH_APPEND
case "<" , "<>&" , "<?" :
return WORDBREAK_REDIRECT_INPUT
case "<>" :
return WORDBREAK_REDIRECT_INPUT_OUTPUT
case ">&" :
return WORDBREAK_REDIRECT_INPUT_DUPLICATE
default :
return WORDBREAK_UNKNOWN
}
}
func (fishFormat ) KeywordOperators () map [string ]WordbreakType {
return map [string ]WordbreakType {
"and" : WORDBREAK_LIST_AND ,
"or" : WORDBREAK_LIST_OR ,
}
}
func (fishFormat ) NonEscapingQuoteEscapes () bool { return true }
func (fishFormat ) NonEscapingQuoteBackslashEscapes () bool { return true }
func (fishFormat ) EscapeNotBareword () bool { return true }
func (fishFormat ) EscapeNotInEscapingQuote () bool { return false }
func (fishFormat ) EscapingQuoteEscapeChars () map [rune ]bool {
return fishDoubleQuoteEscapes
}
var fishDoubleQuoteEscapes = map [rune ]bool {
'"' : true ,
'$' : true ,
'\\' : true ,
'\n' : true ,
}
func (fishFormat ) QuoteWord (s string ) string { return fishQuoteWord (s ) }
func (fishFormat ) TripleQuoteSupport () bool { return false }
func (fishFormat ) RawPrefixSupport () bool { return false }
func (fishFormat ) IsLineContinuation (r rune ) bool {
return r == '\n' || r == '\r'
}
func (fishFormat ) PostProcess (tokens TokenSlice ) TokenSlice {
result := make (TokenSlice , 0 , len (tokens ))
for _ , t := range tokens {
if t .Type == WORDBREAK_TOKEN && t .Value == "(" {
t .WordbreakType = WORDBREAK_SUBSTITUTION_OPEN
}
if t .Type == WORDBREAK_TOKEN && t .Value == ")" {
t .WordbreakType = WORDBREAK_SUBSTITUTION_CLOSE
}
result = append (result , t )
}
return result
}
func (fishFormat ) Variable (word Token ) (Variable , bool ) {
return variableRef (word , variableRules {
expands : func (state LexerState ) bool { return state != QUOTING_STATE },
barewordEscapes : true ,
nameStart : isPosixNameStart ,
nameRune : isPosixNameRune ,
})
}
func (fishFormat ) IsBareWord (s string ) bool {
return bareWordRe .MatchString (s )
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .