A demo to show how to use ANTLR to parse gitconfig file.
Generate ANTLR Java files,
./mvnw clean package
then run the tests to verify the result.
./mvnw test
Please pay attention to the src/test/java/org/example/GitConfigListenerImplTest.java
for assert details.
Referring INF file grammar
and git configuration docs, I
complete GitConfig.g4
.
Then I use ANTLR maven plugin to generate Java files, and
implement GitConfigListenerImpl
to parse the gitconfig file.
Unlike INF files, I need to support the following gitconfig dialects:
- subsection header:
[remote "origin"]
- deprecated subsection header:
[remote.origin]
- colon
:
in the section value:url = https://example.com/git
(Maybe INF file spec is really supported it, but I didn’t see it in the INF file grammar mentioned above)
Welcome to add more gitconfig syntax I was missing through Github issue, and I will update it ASAP.