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

View File

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

View File

@ -1,31 +1,31 @@
package repl
import (
"bufio"
"fmt"
"io"
"monkey/lexer"
"monkey/token"
)
const PROMPT = ">> "
func Start(in io.Reader, out io.Writer){
scanner := bufio.NewScanner(in)
for {
fmt.Fprintf(out, PROMPT)
scanned := scanner.Scan()
if !scanned{
return
}
line := scanner.Text()
l := lexer.new(line)
for tok := l.next_token(); tok.Type != token.EOF; tok = l.next_token(){
fmt.Fprintf(out, "%+v\n", tok)
}
}
}
package repl
import (
"bufio"
"fmt"
"io"
"monkey/lexer"
"monkey/token"
)
const PROMPT = ">> "
func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
for {
fmt.Fprintf(out, PROMPT)
scanned := scanner.Scan()
if !scanned {
return
}
line := scanner.Text()
l := lexer.New(line)
for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
fmt.Fprintf(out, "%+v\n", tok)
}
}
}