Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 2, 2023
1 parent 6dd09d7 commit 3afcf44
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ object Scanner {
"false" -> TokenKind.KW_BOOLEAN,
)

def readIdent: PartialFunction[Unit, Unit] = {
val readIdent: PartialFunction[Unit, Unit] = {
case _ if remaining.head.isLetter =>
val (letters, rest) = remaining.span(ch => ch.isLetterOrDigit || ch == '_')

keywords.get(letters) match {
case Some(kind) =>
// we matched a keyword, return it.
add(kind(letters))

case None =>
// normal ident
add(TokenKind.IDENT(letters))
Expand All @@ -103,7 +104,7 @@ object Scanner {
remaining = rest
}

def readPunctuation: PartialFunction[Unit, Unit] = simpleTokens(
val readPunctuation: PartialFunction[Unit, Unit] = simpleTokens(
"." -> TokenKind.DOT,
"," -> TokenKind.COMMA,
"#" -> TokenKind.HASH,
Expand All @@ -115,7 +116,7 @@ object Scanner {
"=" -> TokenKind.EQ,
)

def readOne: PartialFunction[Unit, Unit] = readIdent.orElse(readPunctuation)
val readOne: PartialFunction[Unit, Unit] = readIdent.orElse(readPunctuation)

// split "whitespace" string into chains of contiguous newlines OR whitespace characters.
def whitespaceChains(
Expand Down

0 comments on commit 3afcf44

Please sign in to comment.