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

Feature/antlr language utils #1159

Merged
merged 10 commits into from
Jul 1, 2023
Merged

Feature/antlr language utils #1159

merged 10 commits into from
Jul 1, 2023

Conversation

TwoOfTwelve
Copy link
Contributor

Adds a new maven module, containing a common parser implementation for all antlr languages.
Part of #983

@tsaglam
Copy link
Member

tsaglam commented Jun 30, 2023

@TwoOfTwelve, you need to adapt the coverage pom in order for us to see the coverage correctly:
https://github.com/jplag/JPlag/blob/3986f58f2f355f00cac3e87a6e16f82183ad530b/coverage-report/pom.xml

@sonarqubecloud
Copy link

[JPlag Plagiarism Detector] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

38.5% 38.5% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@sonarqubecloud
Copy link

[JPlag Plagiarism Detector] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

96.1% 96.1% Coverage
0.0% 0.0% Duplication

Copy link
Member

@tsaglam tsaglam left a comment

Choose a reason for hiding this comment

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

Looks good. Maybe we can see with the typescript module how intuitive the system is (@Kr0nox just FYI) and then tweak it if required.

@tsaglam tsaglam merged commit afbbb12 into develop Jul 1, 2023
@tsaglam tsaglam deleted the feature/antlr-language-utils branch July 1, 2023 07:34
@tsaglam tsaglam added enhancement Issue/PR that involves features, improvements and other changes major Major issue/feature/contribution/change language PR / Issue deals (partly) with new and/or existing languages for JPlag labels Jul 5, 2023
@Kr0nox
Copy link
Member

Kr0nox commented Jul 11, 2023

@TwoOfTwelve Is there a way two tokens for the same RuleContext get added in the desired order?

this.createRangeMapping(FunctionDeclarationContext.class, ASSIGNMENT);
this.createStartStopMapping(FunctionDeclarationContext.class, METHOD_BEGIN, METHOD_END);

In this case ASSIGNMENT always gets added after Method_BEGIN. This is also the case if these two calls are swapped

@TwoOfTwelve
Copy link
Contributor Author

Currently, that is not possible. Can you check if this patch fixes the problem?

Index: language-antlr-utils/src/main/java/de/jplag/antlr/AbstractAntlrListener.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/language-antlr-utils/src/main/java/de/jplag/antlr/AbstractAntlrListener.java b/language-antlr-utils/src/main/java/de/jplag/antlr/AbstractAntlrListener.java
--- a/language-antlr-utils/src/main/java/de/jplag/antlr/AbstractAntlrListener.java	(revision e5aeec5e7aa858e0dd1d416eaf3b30dd9b536bb4)
+++ b/language-antlr-utils/src/main/java/de/jplag/antlr/AbstractAntlrListener.java	(date 1689066637596)
@@ -25,7 +25,6 @@
 public class AbstractAntlrListener implements ParseTreeListener {
     private final List<ContextTokenBuilder<ParserRuleContext>> startMappings;
     private final List<ContextTokenBuilder<ParserRuleContext>> endMappings;
-    private final List<ContextTokenBuilder<ParserRuleContext>> rangeMappings;
 
     private final List<TerminalTokenBuilder> terminalMapping;
 
@@ -46,7 +45,6 @@
 
         this.startMappings = new ArrayList<>();
         this.endMappings = new ArrayList<>();
-        this.rangeMappings = new ArrayList<>();
 
         this.terminalMapping = new ArrayList<>();
 
@@ -78,8 +76,6 @@
     @Override
     public void enterEveryRule(ParserRuleContext rule) {
         this.startMappings.stream().filter(mapping -> mapping.matches(rule)).forEach(mapping -> mapping.createToken(rule, variableRegistry));
-
-        this.rangeMappings.stream().filter(mapping -> mapping.matches(rule)).forEach(mapping -> mapping.createToken(rule, variableRegistry));
     }
 
     @Override
@@ -166,7 +162,7 @@
     protected <T extends ParserRuleContext> ContextTokenBuilder<T> createRangeMapping(Class<T> antlrType, TokenType jplagType,
             Predicate<T> condition) {
         ContextTokenBuilder<T> builder = initTypeBuilder(antlrType, jplagType, condition, ContextTokenBuilderType.RANGE);
-        this.rangeMappings.add((ContextTokenBuilder<ParserRuleContext>) builder);
+        this.startMappings.add((ContextTokenBuilder<ParserRuleContext>) builder);
         return builder;
     }

@Kr0nox
Copy link
Member

Kr0nox commented Jul 11, 2023

Yes that solves the issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue/PR that involves features, improvements and other changes language PR / Issue deals (partly) with new and/or existing languages for JPlag major Major issue/feature/contribution/change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants