Use record syntax for Token
This commit is contained in:
parent
64fdd430be
commit
f3e99ee76d
23
Program.cs
23
Program.cs
@ -69,7 +69,7 @@ class Program
|
||||
}
|
||||
}
|
||||
|
||||
enum TokenType
|
||||
public enum TokenType
|
||||
{
|
||||
LParen, RParen,
|
||||
LBrace, RBrace,
|
||||
@ -107,26 +107,7 @@ enum TokenType
|
||||
EOF
|
||||
}
|
||||
|
||||
class Token
|
||||
{
|
||||
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}";
|
||||
}
|
||||
}
|
||||
public record Token(TokenType type, String lexeme, Object? literal, int line);
|
||||
|
||||
class Scanner
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user