Skip to content

Add parser plugins to API and use them during parsing

Kai-Oliver Prott requested to merge Ziharrk/ghc:parser_plugin into master

This PR adds parser plugins to the plugin API, which allow a plugin to replace the parser used by GHC. To make writing these plugins a bit easier, GHC.Parser.Lexer exports a few more definitions. These are helpful to reduce code duplication when a plugin programmer copies the parser and lexer definitions from GHC to modify them. In that case, a few definitions of the GHC Lexer can be re-used, which reduces code duplication.

This PR adds three separate test cases:

  • One to test the error message that he driver emits when more than one plugin defines a new parser o be used.
  • One to test if it is possible to use GHC's parser in a plugin.
  • One to test if it is possible to modify the accepted syntax by modifying the parser. This test adds alias as an alternative keyword for type synonyms. To do this, it copies and modifies GHC's parser and lexer as mentioned before.

Implements #22401

Merge request reports