[SCM] Lisaac compiler branch, master, updated. lisaac-0.12-457-gc5a376d
Damien Bouvarel
dams.bouvarel at wanadoo.fr
Thu Aug 27 10:26:24 UTC 2009
The following commit has been merged in the master branch:
commit c5a376d71f984f8c6b3213299d892ae1824ae3df
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date: Thu Aug 27 12:26:08 2009 +0200
fix bugs in eclise mode
diff --git a/editor/eclipse/META-INF/MANIFEST.MF b/editor/eclipse/META-INF/MANIFEST.MF
index 982f333..5df0e1d 100644
--- a/editor/eclipse/META-INF/MANIFEST.MF
+++ b/editor/eclipse/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.lisaac.ldt;singleton:=true
-Bundle-Version: 1.1.4
+Bundle-Version: 1.1.5
Bundle-Activator: org.lisaac.ldt.LisaacPlugin
Bundle-Vendor: %Bundle-Vendor.0
Require-Bundle: org.eclipse.ui,
diff --git a/editor/eclipse/src/org/lisaac/ldt/LisaacPlugin.java b/editor/eclipse/src/org/lisaac/ldt/LisaacPlugin.java
index 06acca3..56d14fd 100644
--- a/editor/eclipse/src/org/lisaac/ldt/LisaacPlugin.java
+++ b/editor/eclipse/src/org/lisaac/ldt/LisaacPlugin.java
@@ -2,6 +2,7 @@ package org.lisaac.ldt;
import java.io.IOException;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
@@ -99,8 +100,13 @@ public class LisaacPlugin extends AbstractUIPlugin {
if (projects[i] != null && projects[i].isOpen()) {
if (projects[i].getNature(LisaacNature.NATURE_ID) != null) {
try {
+ IContainer bin = projects[i].getFolder("lib");
+ if (bin.exists()) {
+ bin.delete(true, null);
+ }
+
// clean all lisaac projects to get started
- projects[i].build(IncrementalProjectBuilder.FULL_BUILD, null);
+ projects[i].build(IncrementalProjectBuilder.CLEAN_BUILD, null);
} catch (Exception e) {
log(new Status(IStatus.ERROR,
diff --git a/editor/eclipse/src/org/lisaac/ldt/builder/LisaacBuilder.java b/editor/eclipse/src/org/lisaac/ldt/builder/LisaacBuilder.java
index e79b445..d90bb2c 100644
--- a/editor/eclipse/src/org/lisaac/ldt/builder/LisaacBuilder.java
+++ b/editor/eclipse/src/org/lisaac/ldt/builder/LisaacBuilder.java
@@ -2,6 +2,7 @@ package org.lisaac.ldt.builder;
import java.util.Map;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@@ -146,6 +147,11 @@ public class LisaacBuilder extends IncrementalProjectBuilder {
if (kind == CLEAN_BUILD) {
model.refreshPath();
monitor.worked(10);
+
+ IContainer bin = project.getFolder("lib");
+ if (bin.exists()) {
+ bin.delete(true, monitor);
+ }
}
if (kind == FULL_BUILD) {
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/AbstractLisaacEditor.java b/editor/eclipse/src/org/lisaac/ldt/editors/AbstractLisaacEditor.java
index b37056e..e3e8d41 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/AbstractLisaacEditor.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/AbstractLisaacEditor.java
@@ -169,15 +169,6 @@ public class AbstractLisaacEditor extends TextEditor {
markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
}
- public void doSave(IProgressMonitor progressMonitor) {
- super.doSave(progressMonitor);
-
- /*LisaacModel model = LisaacModel.getModel(getProject());
- if (model != null) {
- model.incrementalBuild();
- }*/
- }
-
public ISourceViewer getViewer() {
return getSourceViewer();
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacConfiguration.java b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacConfiguration.java
index 4af210f..437a03e 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacConfiguration.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacConfiguration.java
@@ -42,7 +42,9 @@ public class LisaacConfiguration extends SourceViewerConfiguration {
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] {
IDocument.DEFAULT_CONTENT_TYPE,
- LisaacPartitionScanner.LISAAC_COMMENT
+ LisaacPartitionScanner.LISAAC_COMMENT,
+ LisaacPartitionScanner.LISAAC_STRING,
+ LisaacPartitionScanner.LISAAC_EXTERNAL
};
}
@@ -155,11 +157,17 @@ public class LisaacConfiguration extends SourceViewerConfiguration {
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
NonRuleBasedDamagerRepairer ndr =
- new NonRuleBasedDamagerRepairer(
- new TextAttribute(
- colorManager.getColor(ILisaacColor.COMMENT)));
+ new NonRuleBasedDamagerRepairer(colorManager.getToken(ILisaacColor.PREF_COMMENT, ILisaacColor.PREF_NORMAL));
reconciler.setDamager(ndr, LisaacPartitionScanner.LISAAC_COMMENT);
reconciler.setRepairer(ndr, LisaacPartitionScanner.LISAAC_COMMENT);
+
+ ndr = new NonRuleBasedDamagerRepairer(colorManager.getToken(ILisaacColor.PREF_STRING, ILisaacColor.STYLE_STRING));
+ reconciler.setDamager(ndr, LisaacPartitionScanner.LISAAC_STRING);
+ reconciler.setRepairer(ndr, LisaacPartitionScanner.LISAAC_STRING);
+
+ ndr = new NonRuleBasedDamagerRepairer(colorManager.getToken2(ILisaacColor.PREF_EXTERNAL, ILisaacColor.PREF_LOCAL_SLOT));
+ reconciler.setDamager(ndr, LisaacPartitionScanner.LISAAC_EXTERNAL);
+ reconciler.setRepairer(ndr, LisaacPartitionScanner.LISAAC_EXTERNAL);
return reconciler;
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacDocumentProvider.java b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacDocumentProvider.java
index af20e26..88a2877 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacDocumentProvider.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacDocumentProvider.java
@@ -20,7 +20,9 @@ public class LisaacDocumentProvider extends FileDocumentProvider {
new LisaacPartitionScanner(),
new String[] {
LisaacPartitionScanner.LISAAC_DEFAULT,
- LisaacPartitionScanner.LISAAC_COMMENT });
+ LisaacPartitionScanner.LISAAC_COMMENT,
+ LisaacPartitionScanner.LISAAC_STRING,
+ LisaacPartitionScanner.LISAAC_EXTERNAL});
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacPartitionScanner.java b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacPartitionScanner.java
index 0ef3916..4a51bca 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacPartitionScanner.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacPartitionScanner.java
@@ -8,6 +8,8 @@ import org.eclipse.jface.text.rules.*;
*/
public class LisaacPartitionScanner extends RuleBasedPartitionScanner {
public final static String LISAAC_COMMENT = "__lisaac_comment";
+ public final static String LISAAC_STRING = "__lisaac_string";
+ public final static String LISAAC_EXTERNAL = "__lisaac_external";
public final static String LISAAC_DEFAULT = "__lisaac_default";
public LisaacPartitionScanner() {
@@ -15,15 +17,20 @@ public class LisaacPartitionScanner extends RuleBasedPartitionScanner {
* Define rules to identify comment partition, the rest of documents is default partition
*/
IToken comment = new Token(LISAAC_COMMENT);
+ IToken string = new Token(LISAAC_STRING);
+ IToken external = new Token(LISAAC_EXTERNAL);
IPredicateRule[] rules = new IPredicateRule[4];
rules[0] = new MultiLineRule("/*", "*/", comment);
rules[1] = new EndOfLineRule("//", comment);
+ rules[2] = new MultiLineRule("\"", "\"", string);
+ rules[3] = new MultiLineRule("`", "`", external);
+
// avoid processing comment inside lisaac strings
- rules[2] = new MultiLineRule("\"", "\"", Token.UNDEFINED, '\0', true);
- rules[3] = new SingleLineRule("`", "`", Token.UNDEFINED, '\0', true);
+ //rules[2] = new MultiLineRule("\"", "\"", Token.UNDEFINED, '\0', true);
+ //rules[3] = new SingleLineRule("`", "`", Token.UNDEFINED, '\0', true);
setPredicateRules(rules);
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacWordRule.java b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacWordRule.java
index 17839ed..2a96baf 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/LisaacWordRule.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/LisaacWordRule.java
@@ -42,6 +42,17 @@ public class LisaacWordRule extends WordRule {
int offset = ((LisaacScanner) scanner).getOffset();
String word = fBuffer.toString();
+ try {
+ Slot slot = prototype.getSlotFromKeyword(word, prototype.openParser(), offset-word.length());
+ if (slot != null) {
+ return result;
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
Slot slot = prototype.getSlot(offset);
if (slot != null) {
@@ -54,16 +65,6 @@ public class LisaacWordRule extends WordRule {
return localVariableToken;
}
}
- try {
- slot = prototype.getSlotFromKeyword(word, prototype.openParser(), offset-word.length());
- if (slot != null) {
- return result;
- }
- } catch (CoreException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
}
return result;
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/NonRuleBasedDamagerRepairer.java b/editor/eclipse/src/org/lisaac/ldt/editors/NonRuleBasedDamagerRepairer.java
index f176cb3..7984844 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/NonRuleBasedDamagerRepairer.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/NonRuleBasedDamagerRepairer.java
@@ -10,7 +10,7 @@ import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
-import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.rules.IToken;
import org.eclipse.swt.custom.StyleRange;
public class NonRuleBasedDamagerRepairer
@@ -19,15 +19,13 @@ public class NonRuleBasedDamagerRepairer
/** The document this object works on */
protected IDocument fDocument;
/** The default text attribute if non is returned as data by the current token */
- protected TextAttribute fDefaultTextAttribute;
+ protected IToken colorToken;
/**
* Constructor for NonRuleBasedDamagerRepairer.
*/
- public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) {
- Assert.isNotNull(defaultTextAttribute);
-
- fDefaultTextAttribute = defaultTextAttribute;
+ public NonRuleBasedDamagerRepairer(IToken colorToken) {
+ this.colorToken = colorToken;
}
/**
@@ -106,11 +104,13 @@ public class NonRuleBasedDamagerRepairer
public void createPresentation(
TextPresentation presentation,
ITypedRegion region) {
+
+ TextAttribute attr = (TextAttribute) colorToken.getData();
addRange(
presentation,
region.getOffset(),
region.getLength(),
- fDefaultTextAttribute);
+ attr);
}
/**
diff --git a/editor/eclipse/src/org/lisaac/ldt/editors/PrototypeHyperLink.java b/editor/eclipse/src/org/lisaac/ldt/editors/PrototypeHyperLink.java
index 48a45ae..236dfcf 100644
--- a/editor/eclipse/src/org/lisaac/ldt/editors/PrototypeHyperLink.java
+++ b/editor/eclipse/src/org/lisaac/ldt/editors/PrototypeHyperLink.java
@@ -109,6 +109,7 @@ public class PrototypeHyperLink implements IHyperlink {
if (prototype != null) {
final IProject p = project;
final String filename = prototype.getFileName();
+ final String prototypePath = prototype.getModel().getPathManager().getFullPath(prototype.getName());
final Position selectPosition = position;
part.getSite().getShell().getDisplay().asyncExec(new Runnable() {
@@ -117,33 +118,38 @@ public class PrototypeHyperLink implements IHyperlink {
if (page == null) {
return;
}
- IFile file=null;
- IPath location = new Path(filename);
-
- IContainer src = p.getFolder("src");
- if (src == null) {
- src = p;
- }
- file = src.getFile(location);
- if (!file.isAccessible()) {
- IContainer lib = p.getFolder("lib");
- if (lib == null) {
- lib = p;
+
+ if (prototypePath != null) {
+ IPath location = new Path(prototypePath);
+ IPath projectLocation = p.getLocation();
+ IFile file = null;
+
+ if (projectLocation.isPrefixOf(location)) {
+ // the file is inside the workspace
+ location = location.removeFirstSegments(projectLocation.segmentCount());
+ file = p.getFile(location);
+ } else {
+ // file is outside workspace : search in /lib
+ IContainer lib = p.getFolder("lib");
+ if (lib == null) {
+ lib = p;
+ }
+ file = lib.getFile(new Path(filename));
}
- file = lib.getFile(location);
- }
- try {
- IDE.openEditor(page, file);
- if (selectPosition != null) {
- IWorkbenchPart part = w.getPartService().getActivePart();
- if (part instanceof LisaacEditor) {
- ((LisaacEditor)part).selectAndReveal(selectPosition.offset, selectPosition.length);
+
+ try {
+ IDE.openEditor(page, file);
+ if (selectPosition != null) {
+ IWorkbenchPart part = w.getPartService().getActivePart();
+ if (part instanceof LisaacEditor) {
+ ((LisaacEditor)part).selectAndReveal(selectPosition.offset, selectPosition.length);
+ }
}
+ } catch (CoreException e) {
+ // TODO open editor error
+ e.printStackTrace();
}
- } catch (CoreException e) {
- // TODO open editor error
- e.printStackTrace();
- }
+ }
}
});
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/launch/LisaacCompiler.java b/editor/eclipse/src/org/lisaac/ldt/launch/LisaacCompiler.java
index 4e2e470..a5029b7 100644
--- a/editor/eclipse/src/org/lisaac/ldt/launch/LisaacCompiler.java
+++ b/editor/eclipse/src/org/lisaac/ldt/launch/LisaacCompiler.java
@@ -43,16 +43,26 @@ public class LisaacCompiler {
}
public IContainer launchInConsole(final ILaunch launch, IProject project, IProgressMonitor monitor) throws CoreException {
- IContainer src = project.getFolder("src");
-
- if (src != null) {
- if (LisaacLauncher.executeCommandInConsole(launch, monitor, src, this.toCommandLineArray(),this)) {
- return src;
+
+ String prototypePath = model.getPathManager()
+ .getFullPath(LisaacModel.extractPrototypeName(inputFile));
+
+ if (prototypePath != null) {
+ IPath location = new Path(prototypePath);
+ IPath projectLocation = project.getLocation();
+ IFile file = null;
+
+ if (projectLocation.isPrefixOf(location)) {
+ // the file is inside the workspace
+ location = location.removeFirstSegments(projectLocation.segmentCount());
+ file = project.getFile(location);
+
+ IContainer container = file.getParent();
+ if (LisaacLauncher.executeCommandInConsole(launch, monitor, container, this.toCommandLineArray(),this)) {
+ return container;
+ }
}
}
- else if (LisaacLauncher.executeCommandInConsole(launch, monitor, project, this.toCommandLineArray(),this)) {
- return project;
- }
return null;
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/LisaacModel.java b/editor/eclipse/src/org/lisaac/ldt/model/LisaacModel.java
index e0913ae..b4055a7 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/LisaacModel.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/LisaacModel.java
@@ -3,8 +3,8 @@ package org.lisaac.ldt.model;
import java.io.InputStream;
import java.util.HashMap;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
@@ -102,7 +102,7 @@ public class LisaacModel implements ILisaacModel{
if (prototypes != null) {
result = prototypes.get(name); // prototype is already cached
- if (result == null) {
+ if (result == null && modelPath != null) {
// cache new prototype
String prototypePath = modelPath.getFullPath(name);
if (prototypePath != null) {
@@ -116,17 +116,17 @@ public class LisaacModel implements ILisaacModel{
file = project.getFile(location);
} else {
// file is outside workspace : create link in /lib
- IContainer lib = project.getFolder("lib");
- if (lib == null) {
- lib = project;
+ IFolder lib = project.getFolder("lib");
+ if (!lib.exists()) {
+ lib.create(false, true, null);
}
file = lib.getFile(new Path(location.lastSegment()));
if (! file.isAccessible() && ! file.exists()) {
file.createLink(location, IResource.NONE, null);
//
- ResourceAttributes attrib = new ResourceAttributes();
- attrib.setReadOnly(true);
- file.setResourceAttributes(attrib);
+ //ResourceAttributes attrib = new ResourceAttributes();
+ //attrib.setReadOnly(true);
+ //file.setResourceAttributes(attrib);
//
}
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/LisaacParser.java b/editor/eclipse/src/org/lisaac/ldt/model/LisaacParser.java
index 994bd3f..cf72e27 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/LisaacParser.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/LisaacParser.java
@@ -670,32 +670,33 @@ public class LisaacParser extends AbstractLisaacParser {
}
private String getOperator(String typ, String op) {
- String s = new String(typ);
+ StringBuffer s = new StringBuffer(typ);
+
for (int i=0; i<op.length(); i++) {
char c = op.charAt(i);
switch (c) {
- case '+': s += "_add"; break;
- case '-': s += "_sub"; break;
- case '~': s += "_logicnot"; break;
- case '!': s += "_not"; break;
- case '/': s += "_div"; break;
- case '*': s += "_mul"; break;
- case '^': s += "_xor"; break;
- case '%': s += "_mod"; break;
- case '>': s += "_greater"; break;
- case '<': s += "_less"; break;
- case '=': s += "_equal"; break;
- case '\\': s += "_notdiv"; break;
- case '|': s += "_or"; break;
- case '&': s += "_and"; break;
- case '$': s += "_dollar"; break;
- case '#': s += "_diese"; break;
- case '@': s += "_at"; break;
- case '?': s += "_ask"; break;
+ case '+': s.append("_add"); break;
+ case '-': s.append("_sub"); break;
+ case '~': s.append("_logicnot"); break;
+ case '!': s.append("_not"); break;
+ case '/': s.append("_div"); break;
+ case '*': s.append("_mul"); break;
+ case '^': s.append("_xor"); break;
+ case '%': s.append("_mod"); break;
+ case '>': s.append("_greater"); break;
+ case '<': s.append("_less"); break;
+ case '=': s.append("_equal"); break;
+ case '\\': s.append("_notdiv"); break;
+ case '|': s.append("_or"); break;
+ case '&': s.append("_and"); break;
+ case '$': s.append("_dollar"); break;
+ case '#': s.append("_diese"); break;
+ case '@': s.append("_at"); break;
+ case '?': s.append("_ask"); break;
}
}
- return getString(s); // alias string
+ return getString(s.toString()); // alias string
}
//++ EXPR -> { ASSIGN !!AMBIGU!! affect } EXPR_OPERATOR
@@ -814,7 +815,7 @@ public class LisaacParser extends AbstractLisaacParser {
ITMOperator itm_op = (ITMOperator) l_expr.get(last_msg+1);
expr = new ITMReadArg1(getOperator("__postfix", itm_op.getName()), l_expr.get(last_msg));
- l_expr.add(last_msg, expr);
+ l_expr.set(last_msg, expr);
l_expr.remove(last_msg+1);
}
if (last_msg - first_msg < 3) {
diff --git a/editor/eclipse/src/org/lisaac/ldt/model/items/Prototype.java b/editor/eclipse/src/org/lisaac/ldt/model/items/Prototype.java
index adc9b70..ac95e56 100644
--- a/editor/eclipse/src/org/lisaac/ldt/model/items/Prototype.java
+++ b/editor/eclipse/src/org/lisaac/ldt/model/items/Prototype.java
@@ -78,7 +78,7 @@ public class Prototype {
public IFile getFile() {
return file;
}
-
+
public String getFileName() {
return file.getName();
}
@@ -106,7 +106,7 @@ public class Prototype {
copyrightOffset = position;
}
}
-
+
public LisaacParser openParser() {
parser.initialize();
@@ -318,6 +318,11 @@ public class Prototype {
// Rewind to '(' '{' ';' '[' '.' '<-' 'operator'
c = source.charAt(offset);
+ if (c == '\n') {// '//' comments
+ offset = unreadSingleLineComment(offset, source);
+ continue;
+ }
+
if (c == '(' || c == '{' || c == '[') {
if (bracketLevel == 0) {
break;
@@ -335,7 +340,6 @@ public class Prototype {
if (c == ';' || c == '.') {
break;
}
-
// affectation
if (c == '=' && source.length() - offset > 2) {
if (source.charAt(offset - 1) == ':'
@@ -349,57 +353,57 @@ public class Prototype {
}
if (parser.isOperatorSymbol(c)) {
if (c == '+' || c == '-') {
- // ambiguity with slot definition
+ // slot definition
if (offset - 3 > 0 && source.charAt(offset - 1) == ' ' &&
source.charAt(offset - 2) == ' ' &&
source.charAt(offset - 3) == '\n') {
- offset = offset - 3;
- continue;
- }
- }
- break;
- }
- }
-
- // look at indentation
- if (c == '\n' && source.length() - offset > 4) {
- if (source.charAt(offset + 1) == ' '
- && source.charAt(offset + 2) == ' '
- && (source.charAt(offset + 3) == '+' || source
- .charAt(offset + 3) == '-')) {
- String slotName = parser
- .readSlotNameFromOffset(offset + 4, false);
- if (slotName != null) {
- result = lookupSlot(slotName);
- if (result == null) {
- return null;
- }
- if (result.keywordCount() == 1) {
- if (result.getName().compareTo(keyword) == 0) {
- return result;
- }
- } else {
- // find keyword next token
- offset = baseOffset;
- while (offset < source.length() - 1
- && Character
- .isJavaIdentifierPart(source
- .charAt(offset))) {
- offset++;
+ String slotName = parser
+ .readSlotNameFromOffset(offset + 1, false);
+ if (slotName != null) {
+ result = lookupSlot(slotName);
+ if (result == null) {
+ return null;
+ }
+ if (result.keywordCount() == 1) {
+ if (result.getName().compareTo(keyword) == 0) {
+ return result;
+ }
+ return null; // not a keyword
+ } else {
+ // find keyword next token
+ offset = baseOffset;
+ while (offset < source.length() - 1
+ && Character
+ .isJavaIdentifierPart(source
+ .charAt(offset))) {
+ offset++;
+ }
+ // read space
+ while (offset < source.length() - 1
+ && Character.isWhitespace(source
+ .charAt(offset))) {
+ offset++;
+ }
+ if (source.charAt(offset) != ':') {
+ return result;// 'keyword' is a slot keyword
+ }
+ return null;
+ }
}
- // read space
- while (offset < source.length() - 1
- && Character.isWhitespace(source
- .charAt(offset))) {
- offset++;
- }
- if (source.charAt(offset) != ':') {
- return result;// 'keyword' is a slot keyword
- }
- return null;
}
}
+ // comments */
+ if (offset - 1 > 0 && c == '/' && source.charAt(offset - 1) == '*') {
+ offset = unreadMultiLineComment(offset, source);
+ continue;
+ }
+ break;
}
+ // strings
+ if (c == '\"' || c == '\'' || c == '`') {
+ offset = unreadString(c, offset, source);
+ continue;
+ }
}
offset--;
}
@@ -410,21 +414,48 @@ public class Prototype {
int pointOffset = offset;
offset--;
bracketLevel = 0;
+ invBracketLevel = 0;
- // rewind until ';' '(' '{' '['
+ // Rewind to '(' '{' ';' '[' '.' '<-' 'operator'
while (offset > 0) {
c = source.charAt(offset);
- if (c == ';') {
- break;
- }
+
if (c == '(' || c == '{' || c == '[') {
if (bracketLevel == 0) {
break;
}
bracketLevel--;
+ invBracketLevel++;
}
if (c == ')' || c == '}' || c == ']') {
bracketLevel++;
+ invBracketLevel--;
+ }
+
+ // ok, we're not in nested statements
+ if (bracketLevel == 0 && invBracketLevel == 0) {
+ if (c == ';') {
+ break;
+ }
+ // affectation
+ if (c == '=' && source.length() - offset > 2) {
+ if (source.charAt(offset - 1) == ':'
+ || source.charAt(offset - 1) == '?') {
+ break;
+ }
+ } else if (c == '-' && source.length() - offset > 2) {
+ if (source.charAt(offset - 1) == '<') {
+ break;
+ }
+ }
+ if (parser.isOperatorSymbol(c)) {
+ break;
+ }
+ // strings
+ if (c == '\"' || c == '\'' || c == '`') {
+ offset = unreadString(c, offset, source);
+ continue;
+ }
}
offset--;
}
@@ -451,6 +482,59 @@ public class Prototype {
return result;
}
+ private int unreadSingleLineComment(int offset, String source) {
+ int saveOffset;
+
+ offset--; // unread '\n'
+ saveOffset = offset;
+
+ while (offset > 0) {
+ char c = source.charAt(offset);
+ if (c == '\n') {// no comment in the line
+ return saveOffset;
+ }
+ if (offset - 1 > 0 && c == '/' && source.charAt(offset - 1) == '/') {
+ offset = offset - 2;
+ break;
+ }
+ offset--;
+ }
+ if (offset < 0) {
+ offset = 0;
+ }
+ return offset;
+ }
+
+ private int unreadMultiLineComment(int offset, String source) {
+ offset -= 2; // unread '*/'
+
+ while (offset > 0) {
+ char c = source.charAt(offset);
+ // read '/*'
+ if (offset - 1 > 0 && c == '*' && source.charAt(offset - 1) == '/') {
+ offset = offset - 2;
+ break;
+ }
+ offset--;
+ }
+ if (offset < 0) {
+ offset = 0;
+ }
+ return offset;
+ }
+
+ private int unreadString(char type, int offset, String source) {
+ char c;
+ do {
+ offset--;
+ c = source.charAt(offset);
+ } while (offset > 0 && c != type);
+ if (c == type) {
+ offset--;
+ }
+ return offset;
+ }
+
public void addSlot(Slot s) {
slotList.put(s.getName(), s);
}
@@ -600,19 +684,19 @@ public class Prototype {
public Change refactorHeader(String author, String bibliography,
String copyright, String license) {
MultiTextEdit edit= new MultiTextEdit();
-
+
// update header slots.
refactorHeaderSlot(ILisaacModel.slot_author, authorOffset, author, edit);
refactorHeaderSlot(ILisaacModel.slot_bibliography, bibliographyOffset, bibliography, edit);
refactorHeaderSlot(ILisaacModel.slot_copyright, copyrightOffset, copyright, edit);
-
+
// update license.
if (license != null) {
int offset = getOffsetBeforeSection();
edit.addChild(new DeleteEdit(0, offset-1));
edit.addChild(new InsertEdit(0, license));
}
-
+
// create change
if (edit.getChildrenSize() > 0) {
TextFileChange change = new TextFileChange("Update Section Header", file);
@@ -621,7 +705,7 @@ public class Prototype {
}
return null;
}
-
+
private void refactorHeaderSlot(String name, Position pos, String newValue, MultiTextEdit edit) {
if (newValue != null) {
if (pos != null) {
@@ -635,16 +719,16 @@ public class Prototype {
}
}
}
-
+
private int getOffsetAfterName() {
LisaacParser parser = openParser();
parser.setPosition(nameOffset);
parser.readCapIdentifier();
parser.readCharacter(';');
-
+
return parser.getOffset();
}
-
+
private int getOffsetBeforeSection() {
LisaacParser parser = openParser();
parser.setPosition(0);
@@ -653,19 +737,19 @@ public class Prototype {
}
return 0;
}
-
+
public void setNameOffset(int offset) {
nameOffset = offset;
}
-
+
public void setAuthorOffset(Position p) {
authorOffset = p;
}
-
+
public void setBibliographyOffset(Position p) {
bibliographyOffset = p;
}
-
+
public void setCopyrightOffset(Position p) {
copyrightOffset = p;
}
@@ -673,7 +757,7 @@ public class Prototype {
public IRegion getRegionAt(int line, int column) {
LisaacParser parser = openParser();
parser.readTokenAt(line, column);
-
+
return new Region(parser.getOffset(), parser.getLastString().length());
}
}
diff --git a/editor/eclipse/src/org/lisaac/ldt/views/LisaacOutlineView.java b/editor/eclipse/src/org/lisaac/ldt/views/LisaacOutlineView.java
index 17f9dd8..17c08d3 100644
--- a/editor/eclipse/src/org/lisaac/ldt/views/LisaacOutlineView.java
+++ b/editor/eclipse/src/org/lisaac/ldt/views/LisaacOutlineView.java
@@ -8,7 +8,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
@@ -19,7 +18,6 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
@@ -40,7 +38,7 @@ import org.lisaac.ldt.outline.OutlineLabelProvider;
public class LisaacOutlineView extends ContentOutlinePage implements IDocumentListener {
/** the delay before the outline view is updated. */
- private static final long UPDATE_DELAY = 1000;
+ private static final long UPDATE_DELAY = 2000;
/** the document provider. */
private IDocumentProvider documentProvider;
--
Lisaac compiler
More information about the Lisaac-commits
mailing list