Skip to content

Commit

Permalink
Version 1.8
Browse files Browse the repository at this point in the history
Added more Dim support StatementFactory#buildVariableInitStatements
Added more TODO comments in StatementFactory
Updated DataType enum
VBSAnalyzer now logs VariableInit classes
VariableInit now has getName & setName methods
  • Loading branch information
OpticFusion1 committed Sep 26, 2022
1 parent 03daccb commit 823515c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>optic_fusion1</groupId>
<artifactId>Kitsune</artifactId>
<version>1.7.1</version>
<version>1.8</version>

<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Sub SubName( param1, param2 ) || Sub SubName(param1,param2) // Or other variants
*/
// TODO: Implement support for storing the values that variables get set to
// TODO: Implement support for parsing operators (=, +, -, /, *, %)
// TODO: Implement support for parsing things like Array(1,2) Array ()
// TODO: Implement support for parsing function calls like reader.ReadFromFile WScript.Arguments(0) or WScript.Echo "Found barcode with type '" & reader.GetFoundBarcodeType(i) & "' and value '" & reader.GetFoundBarcodeValue(i) & "'"
public class StatementFactory {

/*
Expand Down Expand Up @@ -72,9 +74,18 @@ public static VariableInit buildVariableInitStatements(int index, String lineTri
VariableInit vinit = new VariableInit();
vinit.setText(lineTrimmed);
vinit.setLineNumber(index);
// TODO: Make private static final Pattern for this
Pattern pattern;
Matcher matcher = null;
Matcher matcher;
if (lineTrimmed.contains(":") && lineTrimmed.contains("=")) {
// TODO: Check to see if this REGEX Pattern can be improved
pattern = Pattern.compile("Dim (.*) : (.*) = (.*)", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(lineTrimmed);
matcher.find();
vinit.setName(matcher.group(1));
vinit.getVariables().add(matcher.group(3));
return vinit;
}
// TODO: Make private static final Pattern for this
if (lineTrimmed.contains("As")) {
pattern = Pattern.compile("Dim(.+?)As", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(lineTrimmed);
Expand Down Expand Up @@ -180,7 +191,7 @@ public static ConstStatement buildConstStatements(int index, String lineTrimmed)
return statement;
}

private static final Pattern COMMENT_PATTERN = Pattern.compile("' ? (.*)");
private static final Pattern COMMENT_PATTERN = Pattern.compile("'(.*)");

public static Comment buildComments(int index, String lineTrimmed) {
Matcher matcher = COMMENT_PATTERN.matcher(lineTrimmed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

public enum DataType {

// TODO: Look to see if there's any other DataTypes that should be added to this
STRING("String"),
INT("Int"),
VAR("var"),
ByVal("ByVal"),
ByRef("ByRef"),
BY_VAL("ByVal"),
BY_REF("ByRef"),
SINGLE("Single"),
EMPTY("");

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public class VariableInit extends Statement {

private String name;
private DataType variableType;
private List<String> variables = new ArrayList<>();

Expand All @@ -25,4 +26,12 @@ public void setVariableType(DataType variableType) {
this.variableType = variableType;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import optic_fusion1.kitsune.parser.vbs.domain.MsgBoxStatement;
import optic_fusion1.kitsune.parser.vbs.domain.SetStatement;
import optic_fusion1.kitsune.parser.vbs.domain.Statement;
import optic_fusion1.kitsune.parser.vbs.domain.VariableInit;
import optic_fusion1.kitsune.tool.impl.analyze.analyzer.Analyzer;

public class VBSAnalyzer extends Analyzer {
Expand All @@ -32,6 +33,12 @@ public void analyze(File input) {
if (statement instanceof Comment comment) {
LOGGER.info("Comment: " + comment.getText());
}
if (statement instanceof VariableInit stmnt) {
LOGGER.info("Name: " + stmnt.getName() + " Variable Type: " + stmnt.getVariableType());
for (String variable : stmnt.getVariables()) {
LOGGER.info("Variable: " + variable);
}
}
}
}

Expand Down

0 comments on commit 823515c

Please sign in to comment.