The safety of the lexing process is ensured by ‘Megaparsec’, which provides robust error handling and syntax checking. During the lexing part, Megaparsec ensures the input strictly follows the defined grammar. If the syntax is incorrect, the lexer fails gracefully by producing a clear and descriptive error message, preventing the program from continuing with an invalid input. If the syntax is valid, the lexer successfully returns a well-structured list of tokens that can safely be passed to the parser.
Since the Lexer always produces a clean and valid list of tokens, the Parser does not include any additional safety checks on its input. However, it makes sure that no more than one main function was defined.