From 75c722ddc648d6f3184119b6ebd63894692980b3 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Fri, 5 Jan 2024 12:52:03 -0500 Subject: [PATCH] refactor: remove stutter in lexer.NewLexer and parser.NewParser --- command.go | 4 ++-- evaluator.go | 4 ++-- lexer/lexer.go | 4 ++-- lexer/lexer_test.go | 4 ++-- main.go | 4 ++-- parser/parser.go | 8 ++++---- parser/parser_test.go | 24 ++++++++++++------------ 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/command.go b/command.go index 3449da70a..2436ff6b5 100644 --- a/command.go +++ b/command.go @@ -457,8 +457,8 @@ func ExecuteSourceTape(c parser.Command, v *VHS) { return } - l := lexer.NewLexer(string(tape)) - p := parser.NewParser(l) + l := lexer.New(string(tape)) + p := parser.New(l) cmds := p.Parse() diff --git a/evaluator.go b/evaluator.go index 4b15b505f..30a023644 100644 --- a/evaluator.go +++ b/evaluator.go @@ -18,8 +18,8 @@ type EvaluatorOption func(*VHS) // Evaluate takes as input a tape string, an output writer, and an output file // and evaluates all the commands within the tape string and produces a GIF. func Evaluate(ctx context.Context, tape string, out io.Writer, opts ...EvaluatorOption) []error { - l := lexer.NewLexer(tape) - p := parser.NewParser(l) + l := lexer.New(tape) + p := parser.New(l) cmds := p.Parse() errs := p.Errors() diff --git a/lexer/lexer.go b/lexer/lexer.go index 993f8553d..349123d2b 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -12,8 +12,8 @@ type Lexer struct { column int } -// NewLexer returns a new lexer for tokenizing the input string. -func NewLexer(input string) *Lexer { +// New returns a new lexer for tokenizing the input string. +func New(input string) *Lexer { l := &Lexer{input: input, line: 1, column: 0} l.readChar() return l diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 846856ee4..fa9c8205d 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -73,7 +73,7 @@ Sleep 2` {NUMBER, "2"}, } - l := NewLexer(input) + l := New(input) for i, tt := range tests { tok := l.NextToken() @@ -299,7 +299,7 @@ func TestLexTapeFile(t *testing.T) { {SHOW, "Show"}, } - l := NewLexer(string(input)) + l := New(string(input)) for i, tt := range tests { tok := l.NextToken() diff --git a/main.go b/main.go index 60ea073e6..117c1af0c 100644 --- a/main.go +++ b/main.go @@ -215,8 +215,8 @@ var ( continue } - l := lexer.NewLexer(string(b)) - p := parser.NewParser(l) + l := lexer.New(string(b)) + p := parser.New(l) _ = p.Parse() errs := p.Errors() diff --git a/parser/parser.go b/parser/parser.go index 7afd3a3d1..dc2e796b8 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -105,8 +105,8 @@ type Parser struct { peek Token } -// NewParser returns a new Parser. -func NewParser(l *lexer.Lexer) *Parser { +// New returns a new Parser. +func New(l *lexer.Lexer) *Parser { p := &Parser{l: l, errors: []Error{}} // Read two tokens, so cur and peek are both set. @@ -610,8 +610,8 @@ func (p *Parser) parseSource() Command { return cmd } - srcLexer := lexer.NewLexer(srcTape) - srcParser := NewParser(srcLexer) + srcLexer := lexer.New(srcTape) + srcParser := New(srcLexer) // Check not nested source srcCmds := srcParser.Parse() diff --git a/parser/parser_test.go b/parser/parser_test.go index 698a9b6b7..914797edf 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -51,8 +51,8 @@ Sleep 3` {Type: SLEEP, Args: "3s"}, } - l := lexer.NewLexer(input) - p := NewParser(l) + l := lexer.New(input) + p := New(l) cmds := p.Parse() @@ -80,8 +80,8 @@ Type "echo 'Hello, World!'" Enter Foo Sleep Bar` - l := lexer.NewLexer(input) - p := NewParser(l) + l := lexer.New(input) + p := New(l) _ = p.Parse() @@ -187,8 +187,8 @@ func TestParseTapeFile(t *testing.T) { {Type: SHOW, Options: "", Args: ""}, } - l := lexer.NewLexer(string(input)) - p := NewParser(l) + l := lexer.New(string(input)) + p := New(l) cmds := p.Parse() @@ -252,8 +252,8 @@ func TestParseCtrl(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - l := lexer.NewLexer(tc.tape) - p := NewParser(l) + l := lexer.New(tc.tape) + p := New(l) cmd := p.parseCtrl() if tc.wantErr { @@ -296,8 +296,8 @@ func (st *parseSourceTest) run(t *testing.T) { } } - l := lexer.NewLexer(st.tape) - p := NewParser(l) + l := lexer.New(st.tape) + p := New(l) _ = p.Parse() @@ -379,8 +379,8 @@ type parseScreenshotTest struct { } func (st *parseScreenshotTest) run(t *testing.T) { - l := lexer.NewLexer(st.tape) - p := NewParser(l) + l := lexer.New(st.tape) + p := New(l) _ = p.Parse()