mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
More sensible parsing of command leaders.
This commit is contained in:
parent
9eaca63c9b
commit
27a548488f
|
@ -181,14 +181,14 @@ func (fn *Form) parse(ps *parser) {
|
|||
parseSpaces(fn, ps)
|
||||
}
|
||||
leader, starter := findLeader(ps)
|
||||
if leader != "" {
|
||||
if leader != "" && starter {
|
||||
// Parse Control.
|
||||
if starter {
|
||||
fn.setControl(parseControl(ps, leader))
|
||||
} else {
|
||||
fn.setControl(parseControl(ps, leader))
|
||||
parseSpaces(fn, ps)
|
||||
} else {
|
||||
if leader != "" {
|
||||
ps.error(fmt.Errorf("bogus command leader %q ignored", leader))
|
||||
}
|
||||
} else {
|
||||
// Parse head.
|
||||
if len(fn.Assignments) > 0 && !startsCompound(ps.peek()) {
|
||||
// Assignment-only form.
|
||||
|
|
|
@ -42,9 +42,9 @@ func (ps *parser) hasPrefix(prefix string) bool {
|
|||
return strings.HasPrefix(ps.src[ps.pos:], prefix)
|
||||
}
|
||||
|
||||
// findWord look aheads a series of runes in [a-z] followed by ' ', '\t' or
|
||||
// '\n'. If the lookahead fails, it returns an empty string. It is useful for
|
||||
// looking for command leaders.
|
||||
// findWord looks ahead for [a-z]* that is also a valid compound. If the
|
||||
// lookahead fails, it returns an empty string. It is useful for looking for
|
||||
// command leaders.
|
||||
func (ps *parser) findPossibleLeader() string {
|
||||
rest := ps.src[ps.pos:]
|
||||
i := strings.IndexFunc(rest, func(r rune) bool {
|
||||
|
@ -54,12 +54,11 @@ func (ps *parser) findPossibleLeader() string {
|
|||
// The whole rest is just one possible leader.
|
||||
return rest
|
||||
}
|
||||
switch rest[i] {
|
||||
case ' ', '\t', '\n':
|
||||
return rest[:i]
|
||||
default:
|
||||
r, _ := utf8.DecodeRuneInString(rest[i:])
|
||||
if startsPrimary(r) {
|
||||
return ""
|
||||
}
|
||||
return rest[:i]
|
||||
}
|
||||
|
||||
func (ps *parser) next() rune {
|
||||
|
|
Loading…
Reference in New Issue
Block a user