Rename new -> New and next_token -> NextToken, because of go's weird requirement that first letter

of public methods in a package that would be used in another package must be capitalized.

git-svn-id: https://svn.tlawal.org/svn/monkey@4 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
This commit is contained in:
Tijani Lawal 2022-05-12 22:38:47 +00:00
parent fec8dd9152
commit ee8ab63809
3 changed files with 35 additions and 35 deletions

View File

@ -9,7 +9,7 @@ type Lexer struct {
current_char byte current_char byte
} }
func new(input string) *Lexer { func New(input string) *Lexer {
l := &Lexer{input: input} l := &Lexer{input: input}
l.read_char() l.read_char()
return l return l
@ -67,7 +67,7 @@ func is_digit(ch byte) bool {
return '0' <= ch && ch <= '9' return '0' <= ch && ch <= '9'
} }
func (lexer *Lexer) next_token() token.Token { func (lexer *Lexer) NextToken() token.Token {
var tok token.Token var tok token.Token
lexer.skip_whitespace() lexer.skip_whitespace()

View File

@ -114,9 +114,9 @@ func TestNextToken(t *testing.T) {
{token.EOF, ""}, {token.EOF, ""},
} }
l := new(input) l := New(input)
for i, tt := range tests { for i, tt := range tests {
tok := l.next_token() tok := l.NextToken()
if tok.Type != tt.expectedType { if tok.Type != tt.expectedType {
t.Fatalf("test[%d] - tokentype wrong. expected=%q, got=%q", i, tt.expectedType, tok.Type) t.Fatalf("test[%d] - tokentype wrong. expected=%q, got=%q", i, tt.expectedType, tok.Type)
} }

View File

@ -22,9 +22,9 @@ func Start(in io.Reader, out io.Writer){
} }
line := scanner.Text() line := scanner.Text()
l := lexer.new(line) l := lexer.New(line)
for tok := l.next_token(); tok.Type != token.EOF; tok = l.next_token(){ for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
fmt.Fprintf(out, "%+v\n", tok) fmt.Fprintf(out, "%+v\n", tok)
} }
} }