From fc58f4b174a396ee1e64eb710d24e75c34c4123e Mon Sep 17 00:00:00 2001 From: Gabriel Laskar Date: Wed, 19 Jan 2022 03:39:01 +0100 Subject: [PATCH] refactor: move non generic frontend-utils code into their respective frontends --- jplag.frontend-utils/pom.xml | 6 -- .../java/de/jplag/cpp}/NewlineStream.java | 2 +- jplag.frontend.cpp/src/main/javacc/CPP.jj | 82 +++++++++---------- .../src/main/java/de/jplag/csharp/Parser.java | 1 - .../java/de/jplag/csharp}/UnicodeReader.java | 8 +- jplag.frontend.text/src/main/antlr/text.g | 8 +- .../main/java/de/jplag/text}/InputState.java | 2 +- .../src/main/java/de/jplag/text/Parser.java | 4 +- .../main/java/de/jplag/text}/ParserToken.java | 2 +- 9 files changed, 53 insertions(+), 62 deletions(-) rename {jplag.frontend-utils/src/main/java/de/jplag => jplag.frontend.cpp/src/main/java/de/jplag/cpp}/NewlineStream.java (97%) rename {jplag.frontend-utils/src/main/java/de/jplag => jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp}/UnicodeReader.java (99%) rename {jplag.frontend-utils/src/main/java/de/jplag => jplag.frontend.text/src/main/java/de/jplag/text}/InputState.java (97%) rename {jplag.frontend-utils/src/main/java/de/jplag => jplag.frontend.text/src/main/java/de/jplag/text}/ParserToken.java (98%) diff --git a/jplag.frontend-utils/pom.xml b/jplag.frontend-utils/pom.xml index 84eca4005..746cc57d3 100644 --- a/jplag.frontend-utils/pom.xml +++ b/jplag.frontend-utils/pom.xml @@ -10,10 +10,4 @@ 3.1.0-SNAPSHOT - - - antlr - antlr - - diff --git a/jplag.frontend-utils/src/main/java/de/jplag/NewlineStream.java b/jplag.frontend.cpp/src/main/java/de/jplag/cpp/NewlineStream.java similarity index 97% rename from jplag.frontend-utils/src/main/java/de/jplag/NewlineStream.java rename to jplag.frontend.cpp/src/main/java/de/jplag/cpp/NewlineStream.java index 333fd704b..903fb4f4e 100644 --- a/jplag.frontend-utils/src/main/java/de/jplag/NewlineStream.java +++ b/jplag.frontend.cpp/src/main/java/de/jplag/cpp/NewlineStream.java @@ -1,4 +1,4 @@ -package de.jplag; +package de.jplag.cpp; import java.io.IOException; import java.io.InputStream; diff --git a/jplag.frontend.cpp/src/main/javacc/CPP.jj b/jplag.frontend.cpp/src/main/javacc/CPP.jj index e8bab23e2..92dfba157 100644 --- a/jplag.frontend.cpp/src/main/javacc/CPP.jj +++ b/jplag.frontend.cpp/src/main/javacc/CPP.jj @@ -21,7 +21,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; -import de.jplag.NewlineStream; +import de.jplag.cpp.NewlineStream; public class CPPScanner implements CPPTokenConstants { private static Scanner scanner2; @@ -317,15 +317,15 @@ void token(): {} | ">=" | "<<" | ">>" -| "+" -| "-" -| "*" -| "/" -| "%" +| "+" +| "-" +| "*" +| "/" +| "%" | "++" { scanner2.add(C_ASSIGN,token); } | "--" { scanner2.add(C_ASSIGN,token); } -| "~" -| "!" +| "~" +| "!" | "auto" { scanner2.add(C_AUTO,token); } | "break" { scanner2.add(C_BREAK,token); } | "case" { scanner2.add(C_CASE,token); } @@ -373,37 +373,37 @@ void token(): {} | "volatile" { scanner2.add(C_VOLANTILE,token); } | "while" { scanner2.add(C_WHILE,token); } | "operator" { scanner2.add(C_OPERATOR,token); } -| "true" -| "false" +| "true" +| "false" | "throw" { scanner2.add(C_THROW,token); } | "NULL" { scanner2.add(C_NULL,token); } -| -| -| -| -| -| -| -| +| +| +| +| +| +| +| +| -| -| -| -| +| +| +| +| -| -| +| +| -| -| +| +| | //| var() [LOOKAHEAD(2) "(" { scanner2.add(C_FUN,token); } ] | "." -| "->" -| ".*" +| "->" +| ".*" | "->*" | } @@ -433,19 +433,19 @@ void var3(): {} void index(): {} { var() -| -| -| -| -| -| -| -| - -| -| -| -| +| +| +| +| +| +| +| +| + +| +| +| +| } diff --git a/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/Parser.java b/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/Parser.java index 695f745b7..163f01ab1 100644 --- a/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/Parser.java +++ b/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/Parser.java @@ -7,7 +7,6 @@ import antlr.Token; import de.jplag.AbstractParser; import de.jplag.TokenList; -import de.jplag.UnicodeReader; import de.jplag.csharp.grammar.CSharpLexer; import de.jplag.csharp.grammar.CSharpParser; diff --git a/jplag.frontend-utils/src/main/java/de/jplag/UnicodeReader.java b/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/UnicodeReader.java similarity index 99% rename from jplag.frontend-utils/src/main/java/de/jplag/UnicodeReader.java rename to jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/UnicodeReader.java index 0c6a07f41..02c597534 100644 --- a/jplag.frontend-utils/src/main/java/de/jplag/UnicodeReader.java +++ b/jplag.frontend.csharp-1.2/src/main/java/de/jplag/csharp/UnicodeReader.java @@ -1,7 +1,7 @@ /* * Original pseudocode : Thomas Weidenfeller * Implementation tweaked: Aki Nieminen - * + * * http://www.unicode.org/unicode/faq/utf_bom.html * BOMs: * 00 00 FE FF = UTF-32, big-endian @@ -9,12 +9,12 @@ * FE FF = UTF-16, big-endian * FF FE = UTF-16, little-endian * EF BB BF = UTF-8 - * + * * Win2k Notepad: * Unicode format = UTF-16LE */ -package de.jplag; +package de.jplag.csharp; import java.io.IOException; import java.io.InputStream; @@ -28,7 +28,7 @@ * Generic unicode text reader, which will use BOM mark to identify the encoding to be used. If BOM is not found then * use a given default encoding. UTF-8 is used if: BOM mark is not found and defaultEnc is NULL. * Usage pattern: - * + * *
  * String defaultEnc = "UTF-16BE"; // or NULL to use system default
  * FileInputStream fis = new FileInputStream(file);
diff --git a/jplag.frontend.text/src/main/antlr/text.g b/jplag.frontend.text/src/main/antlr/text.g
index 3abdd7588..cd6803420 100644
--- a/jplag.frontend.text/src/main/antlr/text.g
+++ b/jplag.frontend.text/src/main/antlr/text.g
@@ -34,8 +34,8 @@ file : ( w:WORD { parser.add(w); } | PUNCTUATION | SPECIALS )* EOF ;
 //----------------------------------------------------------------------------
 
 {
-import de.jplag.InputState;
-import de.jplag.ParserToken;
+import de.jplag.text.InputState;
+import de.jplag.text.ParserToken;
 }
 
 class TextLexer extends Lexer;
@@ -72,7 +72,7 @@ options
     }
 }
 
-WORD 
+WORD
 options { paraphrase = "an identifier"; } :
   (( '0'..'9') | ('A'..'Z') | ('a'..'z') |
    ('\300' .. '\326') | ('\330' .. '\366') | ('\370' .. '\377'))+ ;
@@ -84,7 +84,7 @@ PUNCTUATION : (	'!' | '"' | '\'' | '(' | ')' | ',' | '-' | '.' |
 SPECIALS : ('#' | '$' | '%' | '&' | '+' | '<' | '=' | '*' |
 	    '/' | '>' | '@' | '\\' | '^' | '_' | '|' | '~' |
 	    ('\241' .. '\252') | ('\254' .. '\263') | ('\265' .. '\272') |
-	    ('\274' .. '\276') | '\327' | '\367' | ('\200' .. '\237') ) ; 
+	    ('\274' .. '\276') | '\327' | '\367' | ('\200' .. '\237') ) ;
 
 // Whitespace -- ignored
 SPACE : ( ' '
diff --git a/jplag.frontend-utils/src/main/java/de/jplag/InputState.java b/jplag.frontend.text/src/main/java/de/jplag/text/InputState.java
similarity index 97%
rename from jplag.frontend-utils/src/main/java/de/jplag/InputState.java
rename to jplag.frontend.text/src/main/java/de/jplag/text/InputState.java
index 1b6d247aa..e13985527 100644
--- a/jplag.frontend-utils/src/main/java/de/jplag/InputState.java
+++ b/jplag.frontend.text/src/main/java/de/jplag/text/InputState.java
@@ -1,4 +1,4 @@
-package de.jplag;
+package de.jplag.text;
 
 import java.io.InputStream;
 import java.io.Reader;
diff --git a/jplag.frontend.text/src/main/java/de/jplag/text/Parser.java b/jplag.frontend.text/src/main/java/de/jplag/text/Parser.java
index ec82bbec5..1840bc3c7 100644
--- a/jplag.frontend.text/src/main/java/de/jplag/text/Parser.java
+++ b/jplag.frontend.text/src/main/java/de/jplag/text/Parser.java
@@ -6,8 +6,6 @@
 
 import antlr.Token;
 import de.jplag.AbstractParser;
-import de.jplag.InputState;
-import de.jplag.ParserToken;
 import de.jplag.TokenConstants;
 import de.jplag.TokenList;
 
@@ -45,7 +43,7 @@ private boolean parseFile(File dir, String file) {
             inputState = new InputState(inputStream);
             TextLexer lexer = new TextLexer(inputState);
             lexer.setFilename(file);
-            lexer.setTokenObjectClass("de.jplag.ParserToken");
+            lexer.setTokenObjectClass("de.jplag.text.ParserToken");
 
             // Create a parser that reads from the scanner
             TextParser parser = new TextParser(lexer);
diff --git a/jplag.frontend-utils/src/main/java/de/jplag/ParserToken.java b/jplag.frontend.text/src/main/java/de/jplag/text/ParserToken.java
similarity index 98%
rename from jplag.frontend-utils/src/main/java/de/jplag/ParserToken.java
rename to jplag.frontend.text/src/main/java/de/jplag/text/ParserToken.java
index 35c82bdc3..52cf2eeb6 100644
--- a/jplag.frontend-utils/src/main/java/de/jplag/ParserToken.java
+++ b/jplag.frontend.text/src/main/java/de/jplag/text/ParserToken.java
@@ -1,4 +1,4 @@
-package de.jplag;
+package de.jplag.text;
 
 import antlr.Token;