2018-04-11 02:05:46 -04:00
|
|
|
{
|
|
|
|
package bootcommand
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Input <- expr:Expr EOF {
|
|
|
|
return expr, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr <- l:( Wait / CharToggle / Special / Literal)+ {
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Wait = ExprStart "wait" duration:( Duration / Integer )? ExprEnd {
|
|
|
|
var d time.Duration
|
|
|
|
switch t := duration.(type) {
|
|
|
|
case time.Duration:
|
|
|
|
d = t
|
|
|
|
case int64:
|
|
|
|
d = time.Duration(t) * time.Second
|
|
|
|
default:
|
|
|
|
d = time.Second
|
|
|
|
}
|
|
|
|
return &waitExpression{d}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
CharToggle = ExprStart lit:(Literal) t:(On / Off) ExprEnd {
|
|
|
|
return &literal{lit.(*literal).s, t.(KeyAction)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Special = ExprStart s:(SpecialKey) t:(On / Off)? ExprEnd {
|
2018-04-13 17:41:17 -04:00
|
|
|
l := strings.ToLower(string(s.([]byte)))
|
2018-04-11 02:05:46 -04:00
|
|
|
if t == nil {
|
2018-04-13 17:41:17 -04:00
|
|
|
return &specialExpression{l, KeyPress}, nil
|
2018-04-11 02:05:46 -04:00
|
|
|
}
|
2018-04-13 17:41:17 -04:00
|
|
|
return &specialExpression{l, t.(KeyAction)}, nil
|
2018-04-11 02:05:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Number = '-'? Integer ( '.' Digit+ )? {
|
|
|
|
return string(c.text), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer = '0' / NonZeroDigit Digit* {
|
|
|
|
return strconv.ParseInt(string(c.text), 10, 64)
|
|
|
|
}
|
|
|
|
|
|
|
|
Duration = ( Number TimeUnit )+ {
|
|
|
|
return time.ParseDuration(string(c.text))
|
|
|
|
}
|
|
|
|
|
|
|
|
On = "on"i {
|
|
|
|
return KeyOn, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Off = "off"i {
|
|
|
|
return KeyOff, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
Literal = . {
|
|
|
|
r, _ := utf8.DecodeRune(c.text)
|
|
|
|
return &literal{r, KeyPress}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ExprEnd = ">"
|
|
|
|
ExprStart = "<"
|
|
|
|
SpecialKey = "bs"i / "del"i / "enter"i / "esc"i / "f10"i / "f11"i / "f12"i
|
|
|
|
/ "f1"i / "f2"i / "f3"i / "f4"i / "f5"i / "f6"i / "f7"i / "f8"i / "f9"i
|
|
|
|
/ "return"i / "tab"i / "up"i / "down"i / "spacebar"i / "insert"i / "home"i
|
|
|
|
/ "end"i / "pageUp"i / "pageDown"i / "leftAlt"i / "leftCtrl"i / "leftShift"i
|
|
|
|
/ "rightAlt"i / "rightCtrl"i / "rightShift"i / "leftSuper"i / "rightSuper"i
|
|
|
|
/ "left"i / "right"i
|
|
|
|
|
|
|
|
NonZeroDigit = [1-9]
|
|
|
|
Digit = [0-9]
|
|
|
|
TimeUnit = ("ns" / "us" / "µs" / "ms" / "s" / "m" / "h")
|
|
|
|
|
|
|
|
_ "whitespace" <- [ \n\t\r]*
|
|
|
|
|
|
|
|
EOF <- !.
|