Use record syntax for Token

This commit is contained in:
Brandon Dyck 2023-06-08 08:16:32 -06:00
parent 64fdd430be
commit f3e99ee76d

View File

@ -69,7 +69,7 @@ class Program
} }
} }
enum TokenType public enum TokenType
{ {
LParen, RParen, LParen, RParen,
LBrace, RBrace, LBrace, RBrace,
@ -107,26 +107,7 @@ enum TokenType
EOF EOF
} }
class Token public record Token(TokenType type, String lexeme, Object? literal, int line);
{
public readonly TokenType type;
public readonly String lexeme;
public readonly Object? literal;
public readonly int line;
public Token(TokenType type, String lexeme, Object? literal, int line)
{
this.type = type;
this.lexeme = lexeme;
this.literal = literal;
this.line = line;
}
public override string ToString()
{
return $"{type} {lexeme} {literal}";
}
}
class Scanner class Scanner
{ {