Skip to content

Commit

Permalink
refactor: switch from type def to uint
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Apr 4, 2023
1 parent 6820f37 commit 7521668
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 2 additions & 7 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewScanner(fileName string) Scanner {
}

// creates a scanner.Token struct with kind, position, value, line and appends it to the scanner.Scanner.tokens array
func (s *Scanner) addToken(kind TokenKind, value string) {
func (s *Scanner) addToken(kind uint, value string) {
s.tokens = append(s.tokens, Token{
Pos: s.linePos,
Kind: kind,
Expand All @@ -68,11 +68,6 @@ func (s *Scanner) PrintTokens() {
}
}

// getter for scanner.Scanner.isAtEnd
func (s *Scanner) atEnd() bool {
return s.isAtEnd
}

// increments s.linePos by one and assigns the next char to s.curChar
func (s *Scanner) advance() {
if s.linePos+1 >= uint(len(s.curLine)) {
Expand Down Expand Up @@ -108,7 +103,7 @@ func (s *Scanner) advanceLine() {
// parses the file given to the Scanner line by line
func (s *Scanner) Parse() {
startTime := time.Now()
for !s.atEnd() {
for !s.isAtEnd {
switch s.curChar {
case '#':
s.addToken(HASH, "")
Expand Down
6 changes: 2 additions & 4 deletions scanner/tokens.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package scanner

type TokenKind uint

type Token struct {
Pos uint
Kind TokenKind
Kind uint
Line uint
Value string
}
Expand All @@ -25,7 +23,7 @@ const (
EMPTYLINE
)

var TOKEN_LOOKUP_MAP = map[TokenKind]string{
var TOKEN_LOOKUP_MAP = map[uint]string{
HASH: "HASH",
UNDERSCORE: "UNDERSCORE",
STAR: "STAR",
Expand Down

0 comments on commit 7521668

Please sign in to comment.