scanner: small fixes
This commit is contained in:
parent
52befe2093
commit
94bd4afe4d
@ -13,12 +13,11 @@ import (
|
|||||||
// eof represents a marker rune for the end of the reader.
|
// eof represents a marker rune for the end of the reader.
|
||||||
const eof = rune(0)
|
const eof = rune(0)
|
||||||
|
|
||||||
// Lexer defines a lexical scanner
|
// Scanner defines a lexical scanner
|
||||||
type Scanner struct {
|
type Scanner struct {
|
||||||
src *bytes.Buffer
|
src *bytes.Buffer
|
||||||
srcBytes []byte
|
srcBytes []byte
|
||||||
|
|
||||||
// ch rune // current character
|
|
||||||
lastCharLen int // length of last character in bytes
|
lastCharLen int // length of last character in bytes
|
||||||
|
|
||||||
currPos Position // current position
|
currPos Position // current position
|
||||||
@ -29,9 +28,9 @@ type Scanner struct {
|
|||||||
tokEnd int // token text tail end (srcBuf index)
|
tokEnd int // token text tail end (srcBuf index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLexer returns a new instance of Lexer. Even though src is an io.Reader,
|
// NewScanner returns a new instance of Lexer. Even though src is an io.Reader,
|
||||||
// we fully consume the content.
|
// we fully consume the content.
|
||||||
func NewLexer(src io.Reader) (*Scanner, error) {
|
func NewScanner(src io.Reader) (*Scanner, error) {
|
||||||
buf, err := ioutil.ReadAll(src)
|
buf, err := ioutil.ReadAll(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -27,7 +27,7 @@ func TestBool(t *testing.T) {
|
|||||||
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := NewLexer(buf)
|
l, err := NewScanner(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ func TestIdent(t *testing.T) {
|
|||||||
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := NewLexer(buf)
|
l, err := NewScanner(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func TestString(t *testing.T) {
|
|||||||
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
fmt.Fprintf(buf, " \t%s\n", ident.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := NewLexer(buf)
|
l, err := NewScanner(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user