You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
2 years ago
|
package shell
|
||
|
|
||
|
type SubshellParameters struct{}
|
||
|
|
||
|
func (p *SubshellParameters) SubParsers() []Parser {
|
||
|
return []Parser{
|
||
|
&BaseParser{
|
||
|
parameters: &StatementParameters{},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (p *SubshellParameters) Supports(charsBefore []rune, r rune) bool {
|
||
|
if r == '(' {
|
||
|
return len(charsBefore) == 0 ||
|
||
|
countBackslashSuffixes(charsBefore)%2 == 0
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (p *SubshellParameters) ShouldLeave(charsBefore []rune, r rune) bool {
|
||
|
if r == ')' {
|
||
|
return len(charsBefore) == 0 ||
|
||
|
countBackslashSuffixes(charsBefore)%2 == 0
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (p *SubshellParameters) MakeToken() Token {
|
||
|
return &Subshell{}
|
||
|
}
|
||
|
|
||
|
type Subshell struct {
|
||
|
BaseToken
|
||
|
}
|
||
|
|
||
|
type Backtick struct {
|
||
|
Subshell
|
||
|
}
|
||
|
|
||
|
type BacktickParameters struct {
|
||
|
SubshellParameters
|
||
|
}
|
||
|
|
||
|
func (p *BacktickParameters) Supports(charsBefore []rune, r rune) bool {
|
||
|
if r == '`' {
|
||
|
return len(charsBefore) == 0 ||
|
||
|
countBackslashSuffixes(charsBefore)%2 == 0
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (p *BacktickParameters) ShouldLeave(charsBefore []rune, r rune) bool {
|
||
|
if r == '`' {
|
||
|
return len(charsBefore) == 0 ||
|
||
|
countBackslashSuffixes(charsBefore)%2 == 0
|
||
|
}
|
||
|
|
||
|
return false
|
||
|
}
|