Skip to content

Commit

Permalink
refactor: remove stutter in lexer.NewLexer and parser.NewParser
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jan 5, 2024
1 parent ef950cc commit 75c722d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Sleep 2`
{NUMBER, "2"},
}

l := NewLexer(input)
l := New(input)

for i, tt := range tests {
tok := l.NextToken()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 75c722d

Please sign in to comment.