Skip to content

Commit

Permalink
few more fixes and improvements; fixed versionning; finished work on …
Browse files Browse the repository at this point in the history
…v0.6.1; built new plugin version
  • Loading branch information
Krzmbrzl committed Aug 9, 2016
1 parent 3a13604 commit f5ea630
Show file tree
Hide file tree
Showing 56 changed files with 4,185 additions and 1,726 deletions.
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Editors
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
Bundle-Version: 0.4.0
Bundle-Version: 0.5.0
Bundle-Activator: raven.sqdev.editors.activator.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import org.antlr.v4.runtime.ANTLRErrorListener;
import org.antlr.v4.runtime.ANTLRInputStream;
Expand All @@ -17,6 +16,7 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.part.FileEditorInput;

import raven.sqdev.editors.BasicCodeEditor;
Expand All @@ -25,6 +25,7 @@
import raven.sqdev.editors.parser.preprocessor.PreprocessorParser.DefineContext;
import raven.sqdev.editors.parser.preprocessor.PreprocessorParser.ErrorContext;
import raven.sqdev.editors.parser.preprocessor.PreprocessorParser.IncludeContext;
import raven.sqdev.util.SQDevPreferenceUtil;

public class PreprocessorParseListener extends PreprocessorBaseListener {

Expand All @@ -40,7 +41,15 @@ public class PreprocessorParseListener extends PreprocessorBaseListener {
/**
* A list of all previously visited files (via '#include')
*/
private List<IPath> includedFiles;
private Stack<IPath> includedFiles;
/**
* The start (offset) of the included file
*/
private int includedFileStart;
/**
* The length of the included file
*/
private int includedFileLength;


/**
Expand All @@ -54,7 +63,11 @@ public PreprocessorParseListener(BasicCodeEditor editor) {

this.editor = editor;

includedFiles = new ArrayList<IPath>();
includedFiles = new Stack<IPath>();

// indicate that the values have not yet been set
includedFileStart = -1;
includedFileLength = -1;
}

/**
Expand All @@ -66,12 +79,16 @@ public PreprocessorParseListener(BasicCodeEditor editor) {
* The files that have already been visited (via the '#include'
* instruction)
*/
private PreprocessorParseListener(BasicCodeEditor editor, List<IPath> files) {
private PreprocessorParseListener(BasicCodeEditor editor, Stack<IPath> files, int start,
int length) {
Assert.isNotNull(editor);

this.editor = editor;

includedFiles = files;

includedFileStart = start;
includedFileLength = length;
}

@Override
Expand All @@ -88,94 +105,126 @@ public void exitDefine(DefineContext ctx) {

@Override
public void exitInclude(IncludeContext ctx) {
int start = ctx.file.getStartIndex();
int length = ctx.file.getStopIndex() - ctx.file.getStartIndex() + 1;
if (includedFileStart == -1 && includedFileLength == -1) {
// only use the values of the topmost file (The one the user is
// looking at)
includedFileStart = ctx.file.getStartIndex();
includedFileLength = ctx.file.getStopIndex() - ctx.file.getStartIndex() + 1;
}

if (!(editor.getEditorInput() instanceof FileEditorInput)) {
editor.createMarker(IMarker.PROBLEM, start, length, "Can't evaluate include-instrution",
IMarker.SEVERITY_WARNING);
editor.createMarker(IMarker.PROBLEM, includedFileStart, includedFileLength,
"Can't evaluate include-instrution", IMarker.SEVERITY_WARNING);
// TODO: log
} else {
// Get latest origin file
IPath originFile;

if (includedFiles.size() == 0) {
originFile = ((FileEditorInput) editor.getEditorInput()).getPath();

// add the original file to the list of "included" files
includedFiles.push(originFile);

// use the new start + length values for new include instruction
includedFileStart = ctx.file.getStartIndex();
includedFileLength = ctx.file.getStopIndex() - ctx.file.getStartIndex() + 1;
} else {
originFile = includedFiles.peek();
}

String strFilePath = ctx.file.getText().substring(1, ctx.file.getText().length() - 1);
IPath root;

if (strFilePath.startsWith("\\")) {
// TODO: start from ArmA main directory
root = new Path(SQDevPreferenceUtil.getArmaProgramDirectory());
} else {
IPath originFile = ((FileEditorInput) editor.getEditorInput()).getPath();

if (includedFiles.contains(originFile)) {
// report cycle in hierarchy
reportError(start, length, CYCLE_IN_HIERARCHY_MSG);
return;
} else {
// add origin file
includedFiles.add(originFile);
}

IPath root = originFile.removeLastSegments(1);
root = originFile.removeLastSegments(1);

while (strFilePath.startsWith("..\\")) {
strFilePath = strFilePath.substring(3);

root = root.removeLastSegments(1);
}

IPath filePath = root.append(strFilePath);
File file = filePath.toFile();

// Check if path exists
if (file.exists()) {
if (!file.isFile()) {
// must be a file
reportError(start, length, "Reference is not a file");
}

IPath filePath = root.append(strFilePath);
File file = filePath.toFile();

// Check if path exists
if (file.exists()) {
if (!file.isFile()) {
// must be a file
reportError(includedFileStart, includedFileLength, "Reference is not a file");
} else {
if (includedFiles.contains(filePath)) {
// report cycle in hierarchy
reportError(includedFileStart, includedFileLength, CYCLE_IN_HIERARCHY_MSG);

includedFiles.clear();

return;
} else {
try {
ANTLRErrorListener errorListener = new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer,
Object offendingSymbol, int line, int charPositionInline,
String msg, RecognitionException e) {
reportError(start, length, "Errors while parsing \""
// add origin file
includedFiles.push(filePath);
}
try {
ANTLRErrorListener errorListener = new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer,
Object offendingSymbol, int line, int charPositionInline,
String msg, RecognitionException e) {
reportError(includedFileStart, includedFileLength,
"Errors while parsing \"" + file.getPath() + "\": " + msg);
}
};

ANTLRInputStream in = new ANTLRInputStream(new FileInputStream(file));

PreprocessorLexer lexer = new PreprocessorLexer(in);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);

CommonTokenStream tokens = new CommonTokenStream(lexer);

PreprocessorParser parser = new PreprocessorParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);

ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new PreprocessorParseListener(editor, includedFiles,
includedFileStart, includedFileLength) {
@Override
protected void reportError(int start, int length, String msg) {

if (msg.equals(CYCLE_IN_HIERARCHY_MSG)
&& includedFiles.size() <= 2) {
// Don't blame sub-file for cycle in
// hierarchy
super.reportError(start, length, msg);
} else {
super.reportError(start, length, "Errors while parsing \""
+ file.getPath() + "\": " + msg);
}
};

ANTLRInputStream in = new ANTLRInputStream(new FileInputStream(file));

PreprocessorLexer lexer = new PreprocessorLexer(in);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);

CommonTokenStream tokens = new CommonTokenStream(lexer);

PreprocessorParser parser = new PreprocessorParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);

ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new PreprocessorParseListener(editor, includedFiles) {
@Override
protected void reportError(int o, int l, String msg) {
if (msg.equals(CYCLE_IN_HIERARCHY_MSG)) {
// Don't blame sub-file for cycle in
// hierarchy
super.reportError(start, length, msg);
} else {
super.reportError(start, length, "Errors while parsing \""
+ file.getPath() + "\": " + msg);
}
}
}, parser.start());

} catch (IOException e) {
reportError(start, length, "Failed at parsing referenced file");

e.printStackTrace();
}
}, parser.start());

} catch (IOException e) {
reportError(includedFileStart, includedFileLength,
"Failed at parsing referenced file");

e.printStackTrace();
} finally {
// remove topmost element from stack as it has been
// fully processed by now
if (includedFiles.size() > 0) {
includedFiles.pop();
}
}
} else {
reportError(start, length, ctx.file.getText() + " does not exist");
}
} else {
reportError(includedFileStart, includedFileLength,
"\"" + file.getPath() + "\" does not exist");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Misc/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Misc
Bundle-SymbolicName: raven.sqdev.misc;singleton:=true
Bundle-Version: 0.3.0
Bundle-Version: 0.3.1
Bundle-Activator: raven.sqdev.activator.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.swt,
Expand Down
Binary file modified plugin/Raven.SQDev.Misc/bin/raven/sqdev/syntax/Syntax.class
Binary file not shown.
4 changes: 1 addition & 3 deletions plugin/Raven.SQDev.Misc/src/raven/sqdev/syntax/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public void setElements(ArrayList<SyntaxElement> elements) {
* The element to add
*/
public void addElement(SyntaxElement element) {
if (!getElements().contains(element)) {
getElements().add(element);
}
getElements().add(element);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.SQFEditor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SQFEditor
Bundle-SymbolicName: raven.sqdev.editors.sqfeditor;singleton:=true
Bundle-Version: 0.4.0
Bundle-Version: 0.5.0
Bundle-Activator: raven.sqdev.activator.Activator
Bundle-Vendor: Raven
Require-Bundle: org.eclipse.ui,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ public class SQFBaseListener implements SQFListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitBooleanExpression(SQFParser.BooleanExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterMacroExpression(SQFParser.MacroExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitMacroExpression(SQFParser.MacroExpressionContext ctx) { }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public class SQFBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SQ
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBooleanExpression(SQFParser.BooleanExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitMacroExpression(SQFParser.MacroExpressionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public interface SQFListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitBooleanExpression(SQFParser.BooleanExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code MacroExpression}
* labeled alternative in {@link SQFParser#expression}.
* @param ctx the parse tree
*/
void enterMacroExpression(SQFParser.MacroExpressionContext ctx);
/**
* Exit a parse tree produced by the {@code MacroExpression}
* labeled alternative in {@link SQFParser#expression}.
* @param ctx the parse tree
*/
void exitMacroExpression(SQFParser.MacroExpressionContext ctx);
/**
* Enter a parse tree produced by the {@code ElseExpression}
* labeled alternative in {@link SQFParser#expression}.
Expand Down
Loading

0 comments on commit f5ea630

Please sign in to comment.