implement cmap for command line mapping
This commit is contained in:
1 parent
0969514f10
commit
3fd1222e4f
7 files changed
+191
-97
No files matched your search
@@ -4,6 +4,7 @@ package main
|
||||
//
|
||||
// Expr = SetExpr
|
||||
// | MapExpr
|
||||
// | CMapExpr
|
||||
// | CmdExpr
|
||||
// | CallExpr
|
||||
// | ExecExpr
|
||||
@@ -13,6 +14,8 @@ package main
|
||||
//
|
||||
// MapExpr = 'map' <keys> Expr ';'
|
||||
//
|
||||
// CMapExpr = 'cmap' <key> <cmd> ';'
|
||||
//
|
||||
// CmdExpr = 'cmd' <name> Expr ';'
|
||||
//
|
||||
// CallExpr = <name> <args> ';'
|
||||
@@ -54,6 +57,13 @@ type mapExpr struct {
|
||||
|
||||
func (e *mapExpr) String() string { return fmt.Sprintf("map %s %s", e.keys, e.expr) }
|
||||
|
||||
type cmapExpr struct {
|
||||
key string
|
||||
cmd string
|
||||
}
|
||||
|
||||
func (e *cmapExpr) String() string { return fmt.Sprintf("cmap %s %s", e.key, e.cmd) }
|
||||
|
||||
type cmdExpr struct {
|
||||
name string
|
||||
expr expr
|
||||
@@ -147,6 +157,24 @@ func (p *parser) parseExpr() expr {
|
||||
}
|
||||
|
||||
result = &mapExpr{keys, expr}
|
||||
case "cmap":
|
||||
var cmd string
|
||||
|
||||
s.scan()
|
||||
key := s.tok
|
||||
|
||||
s.scan()
|
||||
if s.typ != tokenSemicolon {
|
||||
if s.typ != tokenIdent {
|
||||
p.err = fmt.Errorf("expected command: %s", s.tok)
|
||||
}
|
||||
cmd = s.tok
|
||||
s.scan()
|
||||
}
|
||||
|
||||
s.scan()
|
||||
|
||||
result = &cmapExpr{key, cmd}
|
||||
case "cmd":
|
||||
var expr expr
|
||||
|
||||
|
||||
Reference in new issue
Block a user