Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Golang frontend #500

Merged
merged 26 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
419e9b0
Add Go frontend
robinmaisch May 31, 2022
b9b3f0c
Reformat GoTokenConstants
robinmaisch Jun 1, 2022
9413618
Rename package and artifactId 'go' to 'golang'
robinmaisch Jun 27, 2022
52176ac
Merge branch 'master-remote' into golang
robinmaisch Jul 1, 2022
3fa91a4
Rename 'go' to 'golang', add 'golang' to top level README
robinmaisch Jul 1, 2022
10fad30
Add many more tokens, add tests and README
robinmaisch Jul 8, 2022
a913633
Add interface tokens, clean up test
robinmaisch Jul 10, 2022
7a4babd
Remove magic numbers
robinmaisch Jul 10, 2022
d75c16b
Reformat code
robinmaisch Jul 10, 2022
87909b8
Add GoTokenUtils
robinmaisch Jul 10, 2022
382d349
Remove code smells detected by sonarcloud
robinmaisch Jul 10, 2022
4ff0ddf
Add link to README
robinmaisch Jul 15, 2022
1bd2b11
Unify equivalent GolangTokenConstants
robinmaisch Jul 18, 2022
ada7208
Make Golang frontends more consistent to others -- continued
robinmaisch Jul 20, 2022
d43ce72
Merge branch 'master' into golang
robinmaisch Jul 29, 2022
2d77c5c
Reformat code
robinmaisch Jul 29, 2022
066acd0
Merge branch 'master-remote' into golang
robinmaisch Jul 30, 2022
c73f4d2
Implement feedback from revision; remove duplicate dependency
robinmaisch Aug 1, 2022
6d8eb4f
Implement feedback from SonarCloud
robinmaisch Aug 1, 2022
f4379ac
Reformat code
robinmaisch Aug 1, 2022
bb77c0f
Merge branch 'master-remote' into golang
robinmaisch Aug 3, 2022
71aedef
Adapt frontend to interface changes
robinmaisch Aug 3, 2022
3936f20
Add documentation, move GoTokenTestUtils
robinmaisch Aug 3, 2022
8c2d774
Remove redundant method implementations
robinmaisch Aug 3, 2022
8322793
Reformat code
robinmaisch Aug 3, 2022
743a06f
Remove Language::numberOfTokens
robinmaisch Aug 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Usage: JPlag [ options ] [ <root-dir> ... ] [ -new <new-dir> ... ] [ -old <old-d

named arguments:
-h, --help show this help message and exit
-l {java,python3,cpp,csharp,rlang,kotlin,char,text,scheme} Select the language to parse the submissions (default: java)
-l {java,python3,cpp,csharp,golang,kotlin,rlang,char,text,scheme} Select the language to parse the submissions (default: java)
-bc BC Path of the directory containing the base code (common framework used in all submissions)
-v {quiet,long} Verbosity of the logging (default: quiet)
-d Debug parser. Non-parsable files will be stored (default: false)
Expand Down
4 changes: 0 additions & 4 deletions jplag.cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
<groupId>de.jplag</groupId>
<artifactId>jplag</artifactId>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>jplag</artifactId>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>frontend-utils</artifactId>
Comment on lines 15 to 17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dependency to golang here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's something we can also do later

Expand Down
29 changes: 29 additions & 0 deletions jplag.frontend.golang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# JPlag Go language frontend

The JPlag Go frontend allows the use of JPlag with submissions in Go. <br>
It is based on the [Golang ANTLR4 grammar](https://github.com/antlr/grammars-v4/tree/master/golang), licensed under BSD-3.

### Go specification compatibility

The underlying grammar definition does not specify which version of Go it is built on. This is what we know:
- Number literal prefixes, a feature of go1.13, are included.
- Generics, a feature of go1.18, are _not_ included.
- Between go1.13 and go1.18, there were no changes to the syntax. So, the grammar should be fully compatible with go1.17, released in mid-2021.

If the grammar is updated to a more recent<a href="#footnote-1"><sup>1</sup></a> syntax definition, this module should surely be updated as well.

### Token Extraction

The choice of tokens is intended to be similar to the Java or C# frontends. Specifically, among others, it includes a range of nesting structures (class and method declarations, control flow expressions) as well as variable declaration, object creation, assignment, and control flow altering keywords. <br>
Blocks are distinguished by their context, i.e. there are separate `TokenConstants` for `if` blocks, `for` blocks, class bodies, method bodies, array constructors, and the like.

More syntactic elements of Go may turn out to be helpful to include in the future, especially those that are newly introduced.

### Usage

To use the Go frontend, add the `-l golang` flag in the CLI, or use a `JPlagOption` object set to `LanguageOption.GO_LANG` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).

<br>

#### Footnotes
<section id="footnote-1"><sup>1 </sup>The grammar files are taken from grammar-v4, with the most recent modifiactions in <a href="https://github.com/antlr/grammars-v4/tree/51ecccf87b75e96177287367b96cfa99e9f304b8/golang">commit 51ecccf</a> from April 2022.</section>
robinmaisch marked this conversation as resolved.
Show resolved Hide resolved
45 changes: 45 additions & 0 deletions jplag.frontend.golang/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.jplag</groupId>
<artifactId>aggregator</artifactId>
<version>${revision}</version>
</parent>
<artifactId>golang</artifactId>

<dependencies>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>frontend-utils</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>frontend-testutils</artifactId>
<version>${revision}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
robinmaisch marked this conversation as resolved.
Show resolved Hide resolved
Loading