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:
parent
fec8dd9152
commit
ee8ab63809
@ -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()
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
62
repl/repl.go
62
repl/repl.go
@ -1,31 +1,31 @@
|
|||||||
package repl
|
package repl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"monkey/lexer"
|
"monkey/lexer"
|
||||||
"monkey/token"
|
"monkey/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PROMPT = ">> "
|
const PROMPT = ">> "
|
||||||
|
|
||||||
func Start(in io.Reader, out io.Writer){
|
func Start(in io.Reader, out io.Writer) {
|
||||||
scanner := bufio.NewScanner(in)
|
scanner := bufio.NewScanner(in)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fmt.Fprintf(out, PROMPT)
|
fmt.Fprintf(out, PROMPT)
|
||||||
scanned := scanner.Scan()
|
scanned := scanner.Scan()
|
||||||
if !scanned{
|
if !scanned {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user