diff --git a/command.go b/command.go index 0fea13ebc..341b4850f 100644 --- a/command.go +++ b/command.go @@ -50,6 +50,18 @@ var CommandFuncs = map[parser.CommandType]CommandFunc{ token.ESCAPE: ExecuteKey(input.Escape), token.PAGEUP: ExecuteKey(input.PageUp), token.PAGEDOWN: ExecuteKey(input.PageDown), + token.F1: ExecuteKey(input.F1), + token.F2: ExecuteKey(input.F2), + token.F3: ExecuteKey(input.F3), + token.F4: ExecuteKey(input.F4), + token.F5: ExecuteKey(input.F5), + token.F6: ExecuteKey(input.F6), + token.F7: ExecuteKey(input.F7), + token.F8: ExecuteKey(input.F8), + token.F9: ExecuteKey(input.F9), + token.F10: ExecuteKey(input.F10), + token.F11: ExecuteKey(input.F11), + token.F12: ExecuteKey(input.F12), token.HIDE: ExecuteHide, token.REQUIRE: ExecuteRequire, token.SHOW: ExecuteShow, diff --git a/command_test.go b/command_test.go index 102d26082..9e6ccd5ec 100644 --- a/command_test.go +++ b/command_test.go @@ -8,12 +8,12 @@ import ( ) func TestCommand(t *testing.T) { - const numberOfCommands = 27 + const numberOfCommands = 39 if len(parser.CommandTypes) != numberOfCommands { t.Errorf("Expected %d commands, got %d", numberOfCommands, len(parser.CommandTypes)) } - const numberOfCommandFuncs = 27 + const numberOfCommandFuncs = 39 if len(CommandFuncs) != numberOfCommandFuncs { t.Errorf("Expected %d commands, got %d", numberOfCommandFuncs, len(CommandFuncs)) } diff --git a/examples/fixtures/all.tape b/examples/fixtures/all.tape index cfd9e75fc..084464024 100644 --- a/examples/fixtures/all.tape +++ b/examples/fixtures/all.tape @@ -57,6 +57,14 @@ PageDown PageDown 2 PageDown@1 3 +F1 +F1 2 +F1@1 3 + +F12 +F12 2 +F12@1 3 + Enter Enter 2 Enter@1 3 diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 1383dfe77..78a3befd3 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -218,6 +218,20 @@ func TestLexTapeFile(t *testing.T) { {token.AT, "@"}, {token.NUMBER, "1"}, {token.NUMBER, "3"}, + {token.F1, "F1"}, + {token.F1, "F1"}, + {token.NUMBER, "2"}, + {token.F1, "F1"}, + {token.AT, "@"}, + {token.NUMBER, "1"}, + {token.NUMBER, "3"}, + {token.F12, "F12"}, + {token.F12, "F12"}, + {token.NUMBER, "2"}, + {token.F12, "F12"}, + {token.AT, "@"}, + {token.NUMBER, "1"}, + {token.NUMBER, "3"}, {token.ENTER, "Enter"}, {token.ENTER, "Enter"}, {token.NUMBER, "2"}, diff --git a/parser/parser.go b/parser/parser.go index 470bae4d8..1b9e3f7ac 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -36,6 +36,18 @@ var CommandTypes = []CommandType{ //nolint: deadcode token.LEFT, token.PAGEUP, token.PAGEDOWN, + token.F1, + token.F2, + token.F3, + token.F4, + token.F5, + token.F6, + token.F7, + token.F8, + token.F9, + token.F10, + token.F11, + token.F12, token.RIGHT, token.SET, token.OUTPUT, @@ -147,7 +159,19 @@ func (p *Parser) parseCommand() Command { token.RIGHT, token.UP, token.PAGEUP, - token.PAGEDOWN: + token.PAGEDOWN, + token.F1, + token.F2, + token.F3, + token.F4, + token.F5, + token.F6, + token.F7, + token.F8, + token.F9, + token.F10, + token.F11, + token.F12: return p.parseKeypress(p.cur.Type) case token.SET: return p.parseSet() diff --git a/parser/parser_test.go b/parser/parser_test.go index c82c7f652..5648d2407 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -153,6 +153,12 @@ func TestParseTapeFile(t *testing.T) { {Type: token.PAGEDOWN, Options: "", Args: "1"}, {Type: token.PAGEDOWN, Options: "", Args: "2"}, {Type: token.PAGEDOWN, Options: "1s", Args: "3"}, + {Type: token.F1, Options: "", Args: "1"}, + {Type: token.F1, Options: "", Args: "2"}, + {Type: token.F1, Options: "1s", Args: "3"}, + {Type: token.F12, Options: "", Args: "1"}, + {Type: token.F12, Options: "", Args: "2"}, + {Type: token.F12, Options: "1s", Args: "3"}, {Type: token.ENTER, Options: "", Args: "1"}, {Type: token.ENTER, Options: "", Args: "2"}, {Type: token.ENTER, Options: "1s", Args: "3"}, diff --git a/token/token.go b/token/token.go index 5c8b0f6d1..772dc4b95 100644 --- a/token/token.go +++ b/token/token.go @@ -44,6 +44,18 @@ const ( HOME = "HOME" INSERT = "INSERT" PAGEDOWN = "PAGEDOWN" + F1 = "F1" + F2 = "F2" + F3 = "F3" + F4 = "F4" + F5 = "F5" + F6 = "F6" + F7 = "F7" + F8 = "F8" + F9 = "F9" + F10 = "F10" + F11 = "F11" + F12 = "F12" PAGEUP = "PAGEUP" SLEEP = "SLEEP" SPACE = "SPACE" @@ -116,6 +128,18 @@ var Keywords = map[string]Type{ "Up": UP, "PageUp": PAGEUP, "PageDown": PAGEDOWN, + "F1": F1, + "F2": F2, + "F3": F3, + "F4": F4, + "F5": F5, + "F6": F6, + "F7": F7, + "F8": F8, + "F9": F9, + "F10": F10, + "F11": F11, + "F12": F12, "Tab": TAB, "Escape": ESCAPE, "End": END, @@ -168,6 +192,7 @@ func IsCommand(t Type) bool { switch t { case TYPE, SLEEP, UP, DOWN, RIGHT, LEFT, PAGEUP, PAGEDOWN, + F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, ENTER, BACKSPACE, DELETE, TAB, ESCAPE, HOME, INSERT, END, CTRL, SOURCE, SCREENSHOT, COPY, PASTE: return true