Skip to content

Commit

Permalink
chore: a Tab token
Browse files Browse the repository at this point in the history
  • Loading branch information
saffage committed May 9, 2024
1 parent 18b1d90 commit 57501b9
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 131 deletions.
2 changes: 1 addition & 1 deletion internal/jet/jet.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func process(
fileid config.FileID,
isRepl bool,
) {
toks, scanErrors := scanner.Scan(buffer, fileid, scanner.SkipWhitespace)
toks, scanErrors := scanner.Scan(buffer, fileid, scanner.SkipWhitespace|scanner.SkipComments)

if len(scanErrors) > 0 {
for _, err := range scanErrors {
Expand Down
3 changes: 2 additions & 1 deletion parser/handle_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (p *Parser) next() {
p.next()
}

if p.flags&SkipWhitespace != 0 && p.tok.Kind == token.Whitespace {
if p.flags&SkipWhitespace != 0 &&
(p.tok.Kind == token.Whitespace || p.tok.Kind == token.Tab) {
p.next()
}

Expand Down
9 changes: 8 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func (s *Scanner) Next() token.Token {
Data: s.TakeWhile(func(c byte) bool { return c == ' ' }),
}

case s.Match('\t'):
tok = token.Token{
Kind: token.Tab,
Data: string(s.Advance()),
}

case token.IsIdentifierStartChar(s.Peek()):
identifier := s.TakeWhile(token.IsIdentifierChar)

Expand Down Expand Up @@ -199,7 +205,8 @@ func (s *Scanner) Next() token.Token {
tok.End = s.PrevPos()
}

if s.flags&SkipWhitespace != 0 && tok.Kind == token.Whitespace {
if s.flags&SkipWhitespace != 0 &&
(tok.Kind == token.Whitespace || tok.Kind == token.Tab) {
return s.Next()
} else if s.flags&SkipIllegal != 0 && tok.Kind == token.Illegal {
return s.Next()
Expand Down
1 change: 1 addition & 0 deletions token/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
EOF // end of file
Comment // comment
Whitespace // whitespace
Tab // horizontal tabulation
NewLine // new line

Ident // identifier
Expand Down
129 changes: 65 additions & 64 deletions token/kind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 65 additions & 64 deletions token/kind_user_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57501b9

Please sign in to comment.