diff --git a/lang/parse/parse.go b/lang/parse/parse.go index ab875b32..a52abcc5 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -26,10 +26,10 @@ type parser struct { src []t.Token m *t.IDMap filename string - lastLine int32 + lastLine uint32 } -func (p *parser) line() int32 { +func (p *parser) line() uint32 { if len(p.src) != 0 { return p.src[0].Line } diff --git a/lang/token/token.go b/lang/token/token.go index 04cea4c5..95d3c370 100644 --- a/lang/token/token.go +++ b/lang/token/token.go @@ -63,7 +63,7 @@ func (m *IDMap) ByKey(k Key) string { type Token struct { ID ID - Line int32 + Line uint32 } func alpha(c byte) bool { @@ -95,7 +95,7 @@ func hasPrefix(a []byte, s string) bool { } func Tokenize(src []byte, m *IDMap, filename string) (tokens []Token, retErr error) { - line := int32(1) + line := uint32(1) loop: for i := 0; i < len(src); { c := src[i] @@ -105,6 +105,9 @@ loop: if len(tokens) > 0 && tokens[len(tokens)-1].ID.IsImplicitSemicolon() { tokens = append(tokens, Token{IDSemicolon, line}) } + if line == 1<<32-1 { + return nil, fmt.Errorf("token: too many lines in %q", filename) + } line++ } i++