Skip to content

Commit fc05ea0

Browse files
committed
Use pattern matching for the one-byte structural symbols in the self-hosted compiler
1 parent 8097a10 commit fc05ea0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/comp/fe/lexer.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ fn next_token(stdio_reader rdr) -> token.token {
6060
}
6161

6262
// One-byte structural symbols.
63-
if (c == ';') { ret token.SEMI(); }
64-
if (c == '.') { ret token.DOT(); }
65-
if (c == '(') { ret token.LPAREN(); }
66-
if (c == ')') { ret token.RPAREN(); }
67-
if (c == '{') { ret token.LBRACE(); }
68-
if (c == '}') { ret token.RBRACE(); }
69-
if (c == '[') { ret token.LBRACKET(); }
70-
if (c == ']') { ret token.RBRACKET(); }
71-
if (c == '@') { ret token.AT(); }
72-
if (c == '#') { ret token.POUND(); }
63+
alt (c) {
64+
case (';') { ret token.SEMI(); }
65+
case ('.') { ret token.DOT(); }
66+
case ('(') { ret token.LPAREN(); }
67+
case (')') { ret token.RPAREN(); }
68+
case ('{') { ret token.LBRACE(); }
69+
case ('}') { ret token.RBRACE(); }
70+
case ('[') { ret token.LBRACKET(); }
71+
case (']') { ret token.RBRACKET(); }
72+
case ('@') { ret token.AT(); }
73+
case ('#') { ret token.POUND(); }
74+
}
7375

7476
log "lexer stopping at ";
7577
log c;

0 commit comments

Comments
 (0)