Use record syntax for Token
This commit is contained in:
		
							
								
								
									
										23
									
								
								Program.cs
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Program.cs
									
									
									
									
									
								
							@@ -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
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user