Skip to content

Commit bc9ad71

Browse files
committed
Finish 1.3.8
2 parents ca6510e + 9ef3fdc commit bc9ad71

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ plugins {
2525
}
2626

2727
group = "io.err0"
28-
version = "1.3.7-BETA"
28+
version = "1.3.8-BETA"
2929

3030
repositories {
3131
mavenCentral()

src/main/java/io/err0/client/core/Token.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public String getStringLiteral()
6767
return s.length() > 2 ? s.substring(1, s.length() - 2) : "";
6868
case APOS_LITERAL:
6969
return s.length() > 2 ? s.substring(1, s.length() - 2) : "";
70+
case APOS3_LITERAL:
71+
return s.length() > 6 ? s.substring(3, s.length() - 6) : "";
7072
case QUOT3_LITERAL:
7173
return s.length() > 6 ? s.substring(3, s.length() - 6) : "";
7274
case BACKTICK_LITERAL:
@@ -89,6 +91,7 @@ public int getStringQuoteWidth()
8991
case APOS_LITERAL:
9092
case BACKTICK_LITERAL:
9193
return 1;
94+
case APOS3_LITERAL:
9295
case QUOT3_LITERAL:
9396
return 3;
9497
case LONGBRACKET_LITERAL:

src/main/java/io/err0/client/core/TokenClassification.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public enum TokenClassification {
2222
COMMENT_LINE,
2323
COMMENT_BLOCK,
2424
APOS_LITERAL,
25+
APOS3_LITERAL,
2526
QUOT_LITERAL,
2627
QUOT3_LITERAL,
2728
BACKTICK_LITERAL,

src/main/java/io/err0/client/languages/PythonSourceCodeParse.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,31 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so
8888
currentToken.depth = indentNumber;
8989
currentToken.startLineNumber = lineNumber;
9090
} else if (ch == '\'') {
91+
if (i+1<l) {
92+
final char ch1 = chars[i+1];
93+
if (ch1 == '\'') {
94+
if (i+2<l) {
95+
final char ch2 = chars[i+2];
96+
if (ch2 == '\'') {
97+
// comment literal """ <<comment>> """
98+
parse.tokenList.add(currentToken.finish(lineNumber));
99+
currentToken = new Token(n++, currentToken);
100+
currentToken.type = TokenClassification.APOS3_LITERAL;
101+
currentToken.sourceCode.append(ch);
102+
currentToken.sourceCode.append(ch1);
103+
currentToken.sourceCode.append(ch2);
104+
currentToken.depth = indentNumber;
105+
currentToken.startLineNumber = lineNumber;
106+
++i;
107+
++i;
108+
109+
break;
110+
}
111+
}
112+
}
113+
}
114+
115+
// otherwise, it is an apos literal
91116
parse.tokenList.add(currentToken.finish(lineNumber));
92117
currentToken = new Token(n++, currentToken);
93118
currentToken.type = TokenClassification.APOS_LITERAL;
@@ -192,6 +217,40 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so
192217
currentToken.sourceCode.append(ch);
193218
}
194219
break;
220+
case APOS3_LITERAL:
221+
if (ch == '\'') {
222+
if (i+1<l) {
223+
final char ch1 = chars[i+1];
224+
if (ch1 == '\'') {
225+
if (i+2<l) {
226+
final char ch2 = chars[i+2];
227+
if (ch2 == '\'') {
228+
// apos string literal ''' <<comment>> '''
229+
currentToken.sourceCode.append(ch);
230+
currentToken.sourceCode.append(ch1);
231+
currentToken.sourceCode.append(ch2);
232+
parse.tokenList.add(currentToken.finish(lineNumber));
233+
currentToken = new Token(n++, currentToken);
234+
currentToken.type = TokenClassification.SOURCE_CODE;
235+
currentToken.depth = indentNumber;
236+
currentToken.startLineNumber = lineNumber;
237+
i+=2;
238+
239+
break;
240+
}
241+
}
242+
}
243+
}
244+
}
245+
// behaves like any string
246+
if (ch == '\\') {
247+
currentToken.sourceCode.append(ch);
248+
final char ch2 = chars[++i];
249+
currentToken.sourceCode.append(ch2);
250+
} else {
251+
currentToken.sourceCode.append(ch);
252+
}
253+
break;
195254
case APOS_LITERAL:
196255
if (ch == '\'') {
197256
currentToken.sourceCode.append(ch);
@@ -247,14 +306,15 @@ public static PythonSourceCodeParse lex(final CodePolicy policy, final String so
247306

248307
@Override
249308
public boolean couldContainErrorNumber(Token token) {
250-
return token.type == TokenClassification.APOS_LITERAL || token.type == TokenClassification.BACKTICK_LITERAL || token.type == TokenClassification.QUOT_LITERAL;
309+
return token.type == TokenClassification.APOS3_LITERAL || token.type == TokenClassification.APOS_LITERAL || token.type == TokenClassification.QUOT3_LITERAL || token.type == TokenClassification.QUOT_LITERAL;
251310
}
252311

253312
@Override
254313
public void classifyForErrorCode(ApiProvider apiProvider, GlobalState globalState, ProjectPolicy policy, StateItem stateItem, Token token) {
255314
if (token.classification == Token.Classification.NOT_CLASSIFIED_YET) {
256315
switch (token.type) {
257316
case APOS_LITERAL:
317+
case APOS3_LITERAL:
258318
case QUOT_LITERAL:
259319
case QUOT3_LITERAL:
260320
{
@@ -300,7 +360,7 @@ public void classifyForErrorCode(ApiProvider apiProvider, GlobalState globalStat
300360
{
301361
token.classification = Token.Classification.NOT_FULLY_CLASSIFIED;
302362
Token next = token.next();
303-
if (next != null && (next.type == TokenClassification.QUOT_LITERAL || next.type == TokenClassification.APOS_LITERAL || next.type == TokenClassification.QUOT3_LITERAL)) {
363+
if (next != null && (next.type == TokenClassification.QUOT_LITERAL || next.type == TokenClassification.APOS_LITERAL || next.type == TokenClassification.QUOT3_LITERAL || next.type == TokenClassification.APOS3_LITERAL)) {
304364
// rule 0 - this code must be followed by a string literal
305365
if (null != languageCodePolicy && languageCodePolicy.rules.size() > 0) {
306366
// classify according to rules.

src/main/java/io/err0/client/languages/RubySourceCodeParse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import io.err0.client.Main;
2121
import io.err0.client.core.*;
2222
import io.err0.client.languages.ext.RubyExtendedInformation;
23-
import jdk.nashorn.internal.parser.TokenType;
2423

2524
import java.util.LinkedList;
26-
import java.util.Queue;
2725
import java.util.regex.Matcher;
2826
import java.util.regex.Pattern;
2927

src/test/java/io/err0/client/test/Test0010Python.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void t0001InjectErrorCodes() {
5151
Main.runInsert(apiProvider, globalState, policy, driver, apiProvider.createRun(policy), new StatisticsGatherer());
5252

5353
// output the results to 01-assert
54-
//apiProvider.writeResultsTo(assertDir);
54+
// apiProvider.writeResultsTo(assertDir);
5555

5656
apiProvider.resultStorage.forEach((filename, result) -> {
5757
try {

src/test/testdata/0010/01-assert/a.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ def __init__(self, installed_apps=()):
1818
class Example:
1919

2020
def method(list=()):
21-
raise RuntimeError(", ".join("%s" % x for x in list)
21+
raise RuntimeError(", ".join("%s" % x for x in list)
22+
23+
def method2():
24+
raise RuntimeError('''[E-2] This is an error''')
25+
26+
def method3():
27+
raise RuntimeError("""[E-3] This is an error""")

src/test/testdata/0010/01/a.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ def __init__(self, installed_apps=()):
1818
class Example:
1919

2020
def method(list=()):
21-
raise RuntimeError(", ".join("%s" % x for x in list)
21+
raise RuntimeError(", ".join("%s" % x for x in list)
22+
23+
def method2():
24+
raise RuntimeError('''This is an error''')
25+
26+
def method3():
27+
raise RuntimeError("""This is an error""")

0 commit comments

Comments
 (0)