Skip to content

Commit

Permalink
feat: support additional alt/ctrl/shift special characters (#582)
Browse files Browse the repository at this point in the history
* support additional alt/ctrl/shift special characters

* add nolint
  • Loading branch information
raphamorim authored Feb 6, 2025
1 parent ba9b105 commit d9fd05f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
15 changes: 15 additions & 0 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,24 @@ func (l *Lexer) NextToken() token.Token {
case '=':
tok = l.newToken(token.EQUAL, l.ch)
l.readChar()
case ']':
tok = l.newToken(token.RIGHT_BRACKET, l.ch)
l.readChar()
case '[':
tok = l.newToken(token.LEFT_BRACKET, l.ch)
l.readChar()
case '-':
tok = l.newToken(token.MINUS, l.ch)
l.readChar()
case '%':
tok = l.newToken(token.PERCENT, l.ch)
l.readChar()
case '^':
tok = l.newToken(token.CARET, l.ch)
l.readChar()
case '\\':
tok = l.newToken(token.BACKSLASH, l.ch)
l.readChar()
case '#':
tok.Type = token.COMMENT
tok.Literal = l.readComment()
Expand Down
16 changes: 16 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Right@100ms 3
Sleep 500ms
Ctrl+C
Enter
Ctrl+@
Ctrl+\
Alt+]
Shift+[
Sleep .1
Sleep 100ms
Sleep 2
Expand Down Expand Up @@ -65,6 +69,18 @@ Wait+Screen@1m /foobar/`
{token.PLUS, "+"},
{token.STRING, "C"},
{token.ENTER, "Enter"},
{token.CTRL, "Ctrl"},
{token.PLUS, "+"},
{token.AT, "@"},
{token.CTRL, "Ctrl"},
{token.PLUS, "+"},
{token.BACKSLASH, "\\"},
{token.ALT, "Alt"},
{token.PLUS, "+"},
{token.RIGHT_BRACKET, "]"},
{token.SHIFT, "Shift"},
{token.PLUS, "+"},
{token.LEFT_BRACKET, "["},
{token.SLEEP, "Sleep"},
{token.NUMBER, ".1"},
{token.SLEEP, "Sleep"},
Expand Down
10 changes: 10 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ func (p *Parser) parseCtrl() Command {
case peek.Type == token.ENTER,
peek.Type == token.SPACE,
peek.Type == token.BACKSPACE,
peek.Type == token.MINUS,
peek.Type == token.AT,
peek.Type == token.LEFT_BRACKET,
peek.Type == token.RIGHT_BRACKET,
peek.Type == token.CARET,
peek.Type == token.BACKSLASH,
peek.Type == token.STRING && len(peek.Literal) == 1:
args = append(args, peek.Literal)
default:
Expand Down Expand Up @@ -344,6 +350,8 @@ func (p *Parser) parseAlt() Command {
p.nextToken()
if p.peek.Type == token.STRING ||
p.peek.Type == token.ENTER ||
p.peek.Type == token.LEFT_BRACKET ||
p.peek.Type == token.RIGHT_BRACKET ||
p.peek.Type == token.TAB {
c := p.peek.Literal
p.nextToken()
Expand All @@ -368,6 +376,8 @@ func (p *Parser) parseShift() Command {
p.nextToken()
if p.peek.Type == token.STRING ||
p.peek.Type == token.ENTER ||
p.peek.Type == token.LEFT_BRACKET ||
p.peek.Type == token.RIGHT_BRACKET ||
p.peek.Type == token.TAB {
c := p.peek.Literal
p.nextToken()
Expand Down
20 changes: 13 additions & 7 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ type Token struct {

// Tokens for the VHS language
const (
AT = "@"
EQUAL = "="
PLUS = "+"
PERCENT = "%"
SLASH = "/"
DOT = "."
DASH = "-"
AT = "@"
EQUAL = "="
PLUS = "+"
PERCENT = "%"
SLASH = "/"
BACKSLASH = "\\"
DOT = "."
DASH = "-"

MINUS = "-"
RIGHT_BRACKET = "]" //nolint:revive
LEFT_BRACKET = "[" //nolint:revive
CARET = "^"

EM = "EM"
MILLISECONDS = "MILLISECONDS"
Expand Down

0 comments on commit d9fd05f

Please sign in to comment.