Skip to content

Commit

Permalink
Finish 1.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
amb1ent committed Jul 25, 2023
2 parents ca6510e + 9ef3fdc commit bc9ad71
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
}

group = "io.err0"
version = "1.3.7-BETA"
version = "1.3.8-BETA"

repositories {
mavenCentral()
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/err0/client/core/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/err0/client/core/TokenClassification.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum TokenClassification {
COMMENT_LINE,
COMMENT_BLOCK,
APOS_LITERAL,
APOS3_LITERAL,
QUOT_LITERAL,
QUOT3_LITERAL,
BACKTICK_LITERAL,
Expand Down
64 changes: 62 additions & 2 deletions src/main/java/io/err0/client/languages/PythonSourceCodeParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<l) {
final char ch1 = chars[i+1];
if (ch1 == '\'') {
if (i+2<l) {
final char ch2 = chars[i+2];
if (ch2 == '\'') {
// comment literal """ <<comment>> """
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;
Expand Down Expand Up @@ -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<l) {
final char ch1 = chars[i+1];
if (ch1 == '\'') {
if (i+2<l) {
final char ch2 = chars[i+2];
if (ch2 == '\'') {
// apos string literal ''' <<comment>> '''
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);
Expand Down Expand Up @@ -247,14 +306,15 @@ 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
public void classifyForErrorCode(ApiProvider apiProvider, GlobalState globalState, ProjectPolicy policy, StateItem stateItem, Token token) {
if (token.classification == Token.Classification.NOT_CLASSIFIED_YET) {
switch (token.type) {
case APOS_LITERAL:
case APOS3_LITERAL:
case QUOT_LITERAL:
case QUOT3_LITERAL:
{
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/err0/client/test/Test0010Python.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/test/testdata/0010/01-assert/a.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ def __init__(self, installed_apps=()):
class Example:

def method(list=()):
raise RuntimeError(", ".join("%s" % x for x in list)
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""")
8 changes: 7 additions & 1 deletion src/test/testdata/0010/01/a.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ def __init__(self, installed_apps=()):
class Example:

def method(list=()):
raise RuntimeError(", ".join("%s" % x for x in list)
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""")

0 comments on commit bc9ad71

Please sign in to comment.