From af8b34737150ebb9c921b7c115b524b5ad49e18d Mon Sep 17 00:00:00 2001 From: Ben Gould Date: Tue, 25 Jul 2023 14:59:17 +0100 Subject: [PATCH 1/2] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 454e51e..4fc4867 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,7 +25,7 @@ plugins { } group = "io.err0" -version = "1.3.7-BETA" +version = "1.3.8-BETA" repositories { mavenCentral() From 9ef3fdc650a2735098b665240c900f85e1cfa551 Mon Sep 17 00:00:00 2001 From: Ben Gould Date: Tue, 25 Jul 2023 15:04:02 +0100 Subject: [PATCH 2/2] Bug fix python """ and ''' strings. --- src/main/java/io/err0/client/core/Token.java | 3 + .../err0/client/core/TokenClassification.java | 1 + .../languages/PythonSourceCodeParse.java | 64 ++++++++++++++++++- .../client/languages/RubySourceCodeParse.java | 2 - .../io/err0/client/test/Test0010Python.java | 2 +- src/test/testdata/0010/01-assert/a.py | 8 ++- src/test/testdata/0010/01/a.py | 8 ++- 7 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/err0/client/core/Token.java b/src/main/java/io/err0/client/core/Token.java index 08828e3..e5fc287 100644 --- a/src/main/java/io/err0/client/core/Token.java +++ b/src/main/java/io/err0/client/core/Token.java @@ -67,6 +67,8 @@ public String getStringLiteral() return s.length() > 2 ? s.substring(1, s.length() - 2) : ""; case APOS_LITERAL: return s.length() > 2 ? s.substring(1, s.length() - 2) : ""; + case APOS3_LITERAL: + return s.length() > 6 ? s.substring(3, s.length() - 6) : ""; case QUOT3_LITERAL: return s.length() > 6 ? s.substring(3, s.length() - 6) : ""; case BACKTICK_LITERAL: @@ -89,6 +91,7 @@ public int getStringQuoteWidth() case APOS_LITERAL: case BACKTICK_LITERAL: return 1; + case APOS3_LITERAL: case QUOT3_LITERAL: return 3; case LONGBRACKET_LITERAL: diff --git a/src/main/java/io/err0/client/core/TokenClassification.java b/src/main/java/io/err0/client/core/TokenClassification.java index cc3c552..8de4759 100644 --- a/src/main/java/io/err0/client/core/TokenClassification.java +++ b/src/main/java/io/err0/client/core/TokenClassification.java @@ -22,6 +22,7 @@ public enum TokenClassification { COMMENT_LINE, COMMENT_BLOCK, APOS_LITERAL, + APOS3_LITERAL, QUOT_LITERAL, QUOT3_LITERAL, BACKTICK_LITERAL, diff --git a/src/main/java/io/err0/client/languages/PythonSourceCodeParse.java b/src/main/java/io/err0/client/languages/PythonSourceCodeParse.java index 0bae368..651b41e 100644 --- a/src/main/java/io/err0/client/languages/PythonSourceCodeParse.java +++ b/src/main/java/io/err0/client/languages/PythonSourceCodeParse.java @@ -88,6 +88,31 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so currentToken.depth = indentNumber; currentToken.startLineNumber = lineNumber; } else if (ch == '\'') { + if (i+1> """ + parse.tokenList.add(currentToken.finish(lineNumber)); + currentToken = new Token(n++, currentToken); + currentToken.type = TokenClassification.APOS3_LITERAL; + currentToken.sourceCode.append(ch); + currentToken.sourceCode.append(ch1); + currentToken.sourceCode.append(ch2); + currentToken.depth = indentNumber; + currentToken.startLineNumber = lineNumber; + ++i; + ++i; + + break; + } + } + } + } + + // otherwise, it is an apos literal parse.tokenList.add(currentToken.finish(lineNumber)); currentToken = new Token(n++, currentToken); currentToken.type = TokenClassification.APOS_LITERAL; @@ -192,6 +217,40 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so currentToken.sourceCode.append(ch); } break; + case APOS3_LITERAL: + if (ch == '\'') { + if (i+1> ''' + currentToken.sourceCode.append(ch); + currentToken.sourceCode.append(ch1); + currentToken.sourceCode.append(ch2); + parse.tokenList.add(currentToken.finish(lineNumber)); + currentToken = new Token(n++, currentToken); + currentToken.type = TokenClassification.SOURCE_CODE; + currentToken.depth = indentNumber; + currentToken.startLineNumber = lineNumber; + i+=2; + + break; + } + } + } + } + } + // behaves like any string + if (ch == '\\') { + currentToken.sourceCode.append(ch); + final char ch2 = chars[++i]; + currentToken.sourceCode.append(ch2); + } else { + currentToken.sourceCode.append(ch); + } + break; case APOS_LITERAL: if (ch == '\'') { currentToken.sourceCode.append(ch); @@ -247,7 +306,7 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so @Override public boolean couldContainErrorNumber(Token token) { - return token.type == TokenClassification.APOS_LITERAL || token.type == TokenClassification.BACKTICK_LITERAL || token.type == TokenClassification.QUOT_LITERAL; + return token.type == TokenClassification.APOS3_LITERAL || token.type == TokenClassification.APOS_LITERAL || token.type == TokenClassification.QUOT3_LITERAL || token.type == TokenClassification.QUOT_LITERAL; } @Override @@ -255,6 +314,7 @@ public void classifyForErrorCode(ApiProvider apiProvider, GlobalState globalStat if (token.classification == Token.Classification.NOT_CLASSIFIED_YET) { switch (token.type) { case APOS_LITERAL: + case APOS3_LITERAL: case QUOT_LITERAL: case QUOT3_LITERAL: { @@ -300,7 +360,7 @@ public void classifyForErrorCode(ApiProvider apiProvider, GlobalState globalStat { token.classification = Token.Classification.NOT_FULLY_CLASSIFIED; Token next = token.next(); - if (next != null && (next.type == TokenClassification.QUOT_LITERAL || next.type == TokenClassification.APOS_LITERAL || next.type == TokenClassification.QUOT3_LITERAL)) { + if (next != null && (next.type == TokenClassification.QUOT_LITERAL || next.type == TokenClassification.APOS_LITERAL || next.type == TokenClassification.QUOT3_LITERAL || next.type == TokenClassification.APOS3_LITERAL)) { // rule 0 - this code must be followed by a string literal if (null != languageCodePolicy && languageCodePolicy.rules.size() > 0) { // classify according to rules. diff --git a/src/main/java/io/err0/client/languages/RubySourceCodeParse.java b/src/main/java/io/err0/client/languages/RubySourceCodeParse.java index e26fea0..01ed29c 100644 --- a/src/main/java/io/err0/client/languages/RubySourceCodeParse.java +++ b/src/main/java/io/err0/client/languages/RubySourceCodeParse.java @@ -20,10 +20,8 @@ import io.err0.client.Main; import io.err0.client.core.*; import io.err0.client.languages.ext.RubyExtendedInformation; -import jdk.nashorn.internal.parser.TokenType; import java.util.LinkedList; -import java.util.Queue; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/test/java/io/err0/client/test/Test0010Python.java b/src/test/java/io/err0/client/test/Test0010Python.java index b63b3bd..27f9559 100644 --- a/src/test/java/io/err0/client/test/Test0010Python.java +++ b/src/test/java/io/err0/client/test/Test0010Python.java @@ -51,7 +51,7 @@ public void t0001InjectErrorCodes() { Main.runInsert(apiProvider, globalState, policy, driver, apiProvider.createRun(policy), new StatisticsGatherer()); // output the results to 01-assert - //apiProvider.writeResultsTo(assertDir); + // apiProvider.writeResultsTo(assertDir); apiProvider.resultStorage.forEach((filename, result) -> { try { diff --git a/src/test/testdata/0010/01-assert/a.py b/src/test/testdata/0010/01-assert/a.py index 459b8cb..21e5f7a 100644 --- a/src/test/testdata/0010/01-assert/a.py +++ b/src/test/testdata/0010/01-assert/a.py @@ -18,4 +18,10 @@ def __init__(self, installed_apps=()): class Example: def method(list=()): - raise RuntimeError(", ".join("%s" % x for x in list) \ No newline at end of file + raise RuntimeError(", ".join("%s" % x for x in list) + + def method2(): + raise RuntimeError('''[E-2] This is an error''') + + def method3(): + raise RuntimeError("""[E-3] This is an error""") \ No newline at end of file diff --git a/src/test/testdata/0010/01/a.py b/src/test/testdata/0010/01/a.py index b432bf8..1abebe5 100644 --- a/src/test/testdata/0010/01/a.py +++ b/src/test/testdata/0010/01/a.py @@ -18,4 +18,10 @@ def __init__(self, installed_apps=()): class Example: def method(list=()): - raise RuntimeError(", ".join("%s" % x for x in list) \ No newline at end of file + raise RuntimeError(", ".join("%s" % x for x in list) + + def method2(): + raise RuntimeError('''This is an error''') + + def method3(): + raise RuntimeError("""This is an error""") \ No newline at end of file