about summary refs log tree commit diff
path: root/pkg/lang/scanner/scanner.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-12-18 01:33:22 +0100
committerMel <einebeere@gmail.com>2022-12-18 01:33:22 +0100
commitacb34cc0edcff326654714ebb19907e51562b384 (patch)
tree0b67b3490a6394786cf4aec234ca5f6cc4d0100e /pkg/lang/scanner/scanner.go
parenta43f374ffed8ab5d64acd122702826c9c41b8954 (diff)
downloadjinx-main.tar.zst
jinx-main.zip
Skip comments in scanner HEAD main
Diffstat (limited to 'pkg/lang/scanner/scanner.go')
-rw-r--r--pkg/lang/scanner/scanner.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/pkg/lang/scanner/scanner.go b/pkg/lang/scanner/scanner.go
index eb7da89..e1f8edf 100644
--- a/pkg/lang/scanner/scanner.go
+++ b/pkg/lang/scanner/scanner.go
@@ -48,7 +48,7 @@ func (s *Scanner) scanToken() (token.Token, error) {
 		return token.Token{}, ErrScannerFinished
 	}
 
-	hadNewline, firstNewline, err := s.skipWhitespace()
+	hadNewline, firstNewline, err := s.skipNonCode()
 	if err != nil {
 		return token.Token{}, err
 	}
@@ -314,7 +314,8 @@ func (s *Scanner) scanNumber() (token.Token, error) {
 	return token.New(token.Int, loc, num), nil
 }
 
-func (s *Scanner) skipWhitespace() (bool, source.Loc, error) {
+func (s *Scanner) skipNonCode() (bool, source.Loc, error) {
+	isInComment := false
 	hadNewline := false
 	firstNewline := source.Loc{}
 
@@ -329,7 +330,13 @@ func (s *Scanner) skipWhitespace() (bool, source.Loc, error) {
 			hadNewline = true
 		}
 
-		if eof || !unicode.IsSpace(c) {
+		if isInComment {
+			if c == '\n' {
+				isInComment = false
+			}
+		} else if c == '#' {
+			isInComment = true
+		} else if eof || !unicode.IsSpace(c) {
 			break
 		}