"""Provides lexical unit for a parsed AaC definition."""fromattrimportattrib,attrs,validatorsfromaac.in_out.pathsimportis_same_filefromaac.context.source_locationimportSourceLocation
[docs]@attrs(eq=False)classLexeme:"""A lexical unit for a parsed AaC definition. Attributes: location (SourceLocation): The location at which the object was found. source (str): The source in which the object was found. value (str): The value of the parsed object. """location:SourceLocation=attrib(validator=validators.instance_of(SourceLocation))source:str=attrib(validator=validators.instance_of(str))value:str=attrib(validator=validators.instance_of(str))def__init__(self,location:SourceLocation,source:str,value:str):""" An init constructor for the Lexeme Class. Args: location (SourceLocation): The position in the source file. source (str): The source file. value (str): The value stored in the lexeme. """self.location=locationself.source=sourceself.value=value
[docs]def__eq__(self,__o)->bool:"""Return whether this Lexeme is the same as __o."""return(isinstance(__o,Lexeme)andself.value==__o.valueandself.location==__o.locationandis_same_file(self.source,__o.source))
[docs]def__str__(self)->str:"""Return a string representation of this Lexeme."""returnf"{self.value} at {self.location} in {self.source}"