Using external parsers with gmaster

Monday, March 19, 2018 1 Comments

gmaster comes pre-built with support for C#, C, C++, VB.Net and Java. But, you are not limited to these five languages; there are ways to develop and install support for additional languages.

We originally developed the external parser support for SemanticMerge, (which is now a key piece in gmaster), so you can check this guide we wrote explaining how to add new languages.

Users have already contributed parsers for Delphi, F#, Go, and a few others.

In this blogpost, I'm going to cover how to install an external parser in gmaster to add semantic support for new languages. For this demonstration, I chose the F# parser.

A semantic diff between two revisions of a F# file

You can refer to the documentation above to learn how to code your own external parser.

Configure gmaster to use an external parser

To install an external parser, you must follow these steps:

  1. Create a file named externalparsers.conf inside gmaster's configuration directory. If you installed gmaster at the default location, the configuration directory is %LOCALAPPDATA%\gmaster\config.
  2. Add to it the configuration of your external parser(s). This is what my configuration file looks like:
    External parsers configuration file

    The format of this configuration file is quite simple. One parser per line, each line including the extension of the file (including the dot), followed by an equal sign, and the full path of the executable, without quotation marks. For example:

    .<extension>=<executable path>

    The same format works if your parser is, for example, written in Java. You could have something like this:

    .myext=java -jar D:\myparser.jar
  3. Once you have your configuration ready, you must restart gmaster for the changes to take effect.

Diffing F# code

Now, every time gmaster tries to open a F# file revision to show its semantic diff, it will first check the externalparsers.conf configuration file. Then, it will execute the parser, et voilá! You are ready to diff your code semantically:

A semantic visual diff inside gmaster
Tip: Remember that you can undock the diff window to make it as big as you want, as I did for the screenshot.

Merging F# code

And here is what a modified-modified conflict looks like in SemanticMerge, correctly detected thanks to the external parser:

A semantic merge using the external parser

Wrapping up

That's all for today. If you have suggestions, doubts or problems, please don't hesitate to leave a comment, or ping us on Twitter at @gmasterscm.

Happy merging!

We develop gmaster, a Git GUI with semantic superpowers. It parses the code to really understand how it was refactored and then diff it and merge it as a human would do, matching methods instead of lines.

If you want to try it, download it from here.

We are also the developers of SemanticMerge and Plastic SCM, a full-featured version control.

1 comment: