[SCM] Lisaac eclipse plugin branch, master, updated. 30c3a1da65b747d70cbb2fde8823b0696201c6b5

Damien Bouvarel dams.bouvarel at wanadoo.fr
Wed Apr 15 19:44:20 UTC 2009


The following commit has been merged in the master branch:
commit 30c3a1da65b747d70cbb2fde8823b0696201c6b5
Author: Damien Bouvarel <dams.bouvarel at wanadoo.fr>
Date:   Wed Apr 15 21:27:40 2009 +0200

    improve syntax coloring (block arguments & sub-list variables)

diff --git a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
index e138082..036e35b 100644
--- a/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
+++ b/src/org/eclipse/lisaac/editors/LisaacCompletionProcessor.java
@@ -18,7 +18,7 @@ import org.eclipse.lisaac.templates.LisaacTemplateProcessor;
 public class LisaacCompletionProcessor implements IContentAssistProcessor {
 
 	private final IContextInformation[] NO_CONTEXTS = new IContextInformation[0];
-	private final char[] PROPOSAL_ACTIVATION_CHARS = new char[] { '.', '('};
+	private final char[] PROPOSAL_ACTIVATION_CHARS = new char[] { '.' };
 	private ICompletionProposal[] NO_COMPLETIONS = new ICompletionProposal[0];
 
 	private LisaacTemplateProcessor templates;
diff --git a/src/org/eclipse/lisaac/editors/LisaacDamagerRepairer.java b/src/org/eclipse/lisaac/editors/LisaacDamagerRepairer.java
index f1ca3ab..fb4ee3e 100644
--- a/src/org/eclipse/lisaac/editors/LisaacDamagerRepairer.java
+++ b/src/org/eclipse/lisaac/editors/LisaacDamagerRepairer.java
@@ -1,60 +1,60 @@
-package org.eclipse.lisaac.editors;
-
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.ITokenScanner;
-import org.eclipse.jface.text.rules.Token;
-
-public class LisaacDamagerRepairer extends DefaultDamagerRepairer{
-
-	public LisaacDamagerRepairer(ITokenScanner scanner) {
-		super(scanner);
-	}
-	
-	/*
-	 * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
-	 */
-	public void createPresentation(TextPresentation presentation, ITypedRegion region) {
-
-		if (fScanner == null) {
-			// will be removed if deprecated constructor will be removed
-			addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute);
-			return;
-		}
-
-		int lastStart= region.getOffset();
-		int length= 0;
-		boolean firstToken= true;
-		IToken lastToken= Token.UNDEFINED;
-		TextAttribute lastAttribute= getTokenTextAttribute(lastToken);
-
-		fScanner.setRange(fDocument, lastStart, region.getLength());
-
-		while (true) {
-			IToken token= fScanner.nextToken();
-			if (token.isEOF())
-				break;
-
-			// define text attribute for this token
-			TextAttribute attribute= getTokenTextAttribute(token);
-			if (lastAttribute != null && lastAttribute.equals(attribute)) {
-				length += fScanner.getTokenLength();
-				firstToken= false;
-			} else {
-				if (!firstToken)
-					addRange(presentation, lastStart, length, lastAttribute);
-				firstToken= false;
-				lastToken= token;
-				lastAttribute= attribute;
-				lastStart= fScanner.getTokenOffset();
-				length= fScanner.getTokenLength();
-			}			
-		}
-		
-		// process last token
-		addRange(presentation, lastStart, length, lastAttribute);
-	}
-}
+package org.eclipse.lisaac.editors;
+
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.ITokenScanner;
+import org.eclipse.jface.text.rules.Token;
+
+public class LisaacDamagerRepairer extends DefaultDamagerRepairer{
+
+	public LisaacDamagerRepairer(ITokenScanner scanner) {
+		super(scanner);
+	}
+	
+	/*
+	 * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
+	 */
+	public void createPresentation(TextPresentation presentation, ITypedRegion region) {
+
+		if (fScanner == null) {
+			// will be removed if deprecated constructor will be removed
+			addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute);
+			return;
+		}
+
+		int lastStart= region.getOffset();
+		int length= 0;
+		boolean firstToken= true;
+		IToken lastToken= Token.UNDEFINED;
+		TextAttribute lastAttribute= getTokenTextAttribute(lastToken);
+
+		fScanner.setRange(fDocument, lastStart, region.getLength());
+
+		while (true) {
+			IToken token= fScanner.nextToken();
+			if (token.isEOF())
+				break;
+
+			// define text attribute for this token
+			TextAttribute attribute= getTokenTextAttribute(token);
+			if (lastAttribute != null && lastAttribute.equals(attribute)) {
+				length += fScanner.getTokenLength();
+				firstToken= false;
+			} else {
+				if (!firstToken)
+					addRange(presentation, lastStart, length, lastAttribute);
+				firstToken= false;
+				lastToken= token;
+				lastAttribute= attribute;
+				lastStart= fScanner.getTokenOffset();
+				length= fScanner.getTokenLength();
+			}			
+		}
+		
+		// process last token
+		addRange(presentation, lastStart, length, lastAttribute);
+	}
+}
diff --git a/src/org/eclipse/lisaac/editors/LisaacScanner.java b/src/org/eclipse/lisaac/editors/LisaacScanner.java
index 75263a0..39c66ea 100644
--- a/src/org/eclipse/lisaac/editors/LisaacScanner.java
+++ b/src/org/eclipse/lisaac/editors/LisaacScanner.java
@@ -2,7 +2,6 @@ package org.eclipse.lisaac.editors;
 
 import org.eclipse.jface.text.*;
 import org.eclipse.jface.text.rules.*;
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.RGB;
 
 class LisaacWhitespaceDetector implements IWhitespaceDetector {
diff --git a/src/org/eclipse/lisaac/editors/LisaacWordRule.java b/src/org/eclipse/lisaac/editors/LisaacWordRule.java
index 6fe5d70..baadd77 100644
--- a/src/org/eclipse/lisaac/editors/LisaacWordRule.java
+++ b/src/org/eclipse/lisaac/editors/LisaacWordRule.java
@@ -1,87 +1,84 @@
-package org.eclipse.lisaac.editors;
-
-import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.lisaac.model.LisaacModel;
-import org.eclipse.lisaac.model.items.ITMList;
-import org.eclipse.lisaac.model.items.Prototype;
-import org.eclipse.lisaac.model.items.Slot;
-
-public class LisaacWordRule extends WordRule {
-
-	private IToken localVariableToken;
-	
-	private StringBuffer fBuffer= new StringBuffer();
-	
-	
-	public LisaacWordRule(IWordDetector detector, IToken defaultToken, IToken localVariableToken) {
-		super(detector, defaultToken);
-		this.localVariableToken = localVariableToken;
-	}
-
-	/*
-	 * @see IRule#evaluate(ICharacterScanner)
-	 */
-	public IToken evaluate(ICharacterScanner scanner) {
-		IToken result = doEvaluate(scanner);
-		
-		if (result == fDefaultToken) {	
-			//
-			Prototype prototype = LisaacModel.getCurrentPrototype();
-			if (prototype == null) {
-				return result;
-			}
-			//
-			int offset = ((LisaacScanner) scanner).getOffset();
-			
-			Slot slot = prototype.getSlot(offset);
-			if (slot != null) {
-				String word = fBuffer.toString();
-				
-				if (slot.hasArgument(word)) {
-					return localVariableToken;
-				}
-				if (slot.getValue() instanceof ITMList) {
-					ITMList code = (ITMList) slot.getValue();
-					
-					if (code.hasVariableDefinition(word)) {
-						return localVariableToken;
-					}
-				}
-			}
-		}
-		return result;
-	}
-	
-
-	public IToken doEvaluate(ICharacterScanner scanner) {
-		int c= scanner.read();
-		if (c != ICharacterScanner.EOF && fDetector.isWordStart((char) c)) {
-			if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
-
-				fBuffer.setLength(0);
-				do {
-					fBuffer.append((char) c);
-					c= scanner.read();
-				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
-				scanner.unread();
-
-				String buffer= fBuffer.toString();
-				IToken token= (IToken)fWords.get(buffer);
-								
-				if (token != null)
-					return token;
-
-				if (fDefaultToken.isUndefined())
-					unreadBuffer(scanner);
-
-				return fDefaultToken;
-			}
-		}
-		scanner.unread();
-		return Token.UNDEFINED;
-	}
-}
+package org.eclipse.lisaac.editors;
+
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+import org.eclipse.lisaac.model.LisaacModel;
+import org.eclipse.lisaac.model.items.Prototype;
+import org.eclipse.lisaac.model.items.Slot;
+
+public class LisaacWordRule extends WordRule {
+
+	private IToken localVariableToken;
+	
+	private StringBuffer fBuffer= new StringBuffer();
+	
+	
+	public LisaacWordRule(IWordDetector detector, IToken defaultToken, IToken localVariableToken) {
+		super(detector, defaultToken);
+		this.localVariableToken = localVariableToken;
+	}
+
+	/*
+	 * @see IRule#evaluate(ICharacterScanner)
+	 */
+	public IToken evaluate(ICharacterScanner scanner) {
+		IToken result = doEvaluate(scanner);
+		
+		if (result == fDefaultToken) {	
+			//
+			Prototype prototype = LisaacModel.getCurrentPrototype();
+			if (prototype == null) {
+				return result;
+			}
+			//
+			int offset = ((LisaacScanner) scanner).getOffset();
+			
+			Slot slot = prototype.getSlot(offset);
+			if (slot != null) {
+				String word = fBuffer.toString();
+				
+				// is current word a slot argument?
+				if (slot.hasArgument(word)) {
+					return localVariableToken;
+				}
+				// is current word a slot variable?
+				if (slot.hasVariableDefinition(word, offset)) {
+					return localVariableToken;
+				}
+			}
+		}
+		return result;
+	}
+	
+
+	public IToken doEvaluate(ICharacterScanner scanner) {
+		int c= scanner.read();
+		if (c != ICharacterScanner.EOF && fDetector.isWordStart((char) c)) {
+			if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
+
+				fBuffer.setLength(0);
+				do {
+					fBuffer.append((char) c);
+					c= scanner.read();
+				} while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
+				scanner.unread();
+
+				String buffer= fBuffer.toString();
+				IToken token= (IToken)fWords.get(buffer);
+								
+				if (token != null)
+					return token;
+
+				if (fDefaultToken.isUndefined())
+					unreadBuffer(scanner);
+
+				return fDefaultToken;
+			}
+		}
+		scanner.unread();
+		return Token.UNDEFINED;
+	}
+}
diff --git a/src/org/eclipse/lisaac/model/LisaacParser.java b/src/org/eclipse/lisaac/model/LisaacParser.java
index ae1d0a4..64d325a 100644
--- a/src/org/eclipse/lisaac/model/LisaacParser.java
+++ b/src/org/eclipse/lisaac/model/LisaacParser.java
@@ -6,7 +6,6 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.eclipse.lisaac.LisaacPlugin;
-import org.eclipse.lisaac.builder.LisaacParseException;
 import org.eclipse.lisaac.model.items.*;
 import org.eclipse.lisaac.model.types.*;
 import org.eclipse.lisaac.preferences.PreferenceConstants;
@@ -864,7 +863,7 @@ public class LisaacParser extends AbstractLisaacParser {
 		} else if ((result = readConstant()) != null) {
 		} else if (readCharacter('(')) {
 			group_sav = lastGroup;
-			lastGroup = new ITMList();
+			lastGroup = new ITMList(lastSlot, position);
 			result = lastGroup;
 
 			lastGroup.setCode(readGroup());
@@ -872,10 +871,11 @@ public class LisaacParser extends AbstractLisaacParser {
 				reporter.syntaxError("Added ')'.", getPosition());
 				return null;
 			}
+			lastGroup.setEndOffset(position);
 			lastGroup = group_sav;
 		} else if (readCharacter('{')) {
 			group_sav = lastGroup;  
-			lastGroup = new ITMList();
+			lastGroup = new ITMList(lastSlot, position);
 
 			saveContext(); // !! SAVE CONTEXT !!
 
@@ -890,13 +890,14 @@ public class LisaacParser extends AbstractLisaacParser {
 			} else {
 				restoreContext(); // !! RESTORE CONTEXT !!
 			}
-			result = new ITMBlock(lastGroup, arg);
+			result = new ITMBlock(lastGroup, arg, lastSlot);
 
 			lastGroup.setCode(readGroup());
 			if (! readCharacter('}')) {
 				reporter.syntaxError("Added '}'.", getPosition());
 				return null;
 			}
+			lastGroup.setEndOffset(position);
 			lastGroup = group_sav; 
 		} else if (readExternal()) {
 			if (! readCharacter(':')) {
@@ -1148,7 +1149,7 @@ public class LisaacParser extends AbstractLisaacParser {
 		ITMList result = null;
 
 		if (readCharacter('[')) {
-			result = new ITMList();
+			result = new ITMList(lastSlot, position);
 			lastGroup = result;
 
 			readDefLocal();
@@ -1178,6 +1179,7 @@ public class LisaacParser extends AbstractLisaacParser {
 			}
 			// TODO lst add prototype void
 			result.setCode(lst.toArray(new ICode[lst.size()]));
+			result.setEndOffset(position);
 		}
 		return result;
 	}	   
diff --git a/src/org/eclipse/lisaac/model/items/IArgument.java b/src/org/eclipse/lisaac/model/items/IArgument.java
index 6e8d761..614a81a 100644
--- a/src/org/eclipse/lisaac/model/items/IArgument.java
+++ b/src/org/eclipse/lisaac/model/items/IArgument.java
@@ -1,12 +1,14 @@
-package org.eclipse.lisaac.model.items;
-
-import org.eclipse.lisaac.model.types.IType;
-
-public interface IArgument {
-
-	String getName();
-
-	IType getType();
-
-	void printIn(StringBuffer buffer);
-}
+package org.eclipse.lisaac.model.items;
+
+import org.eclipse.lisaac.model.types.IType;
+
+public interface IArgument {
+
+	String getName();
+
+	IType getType();
+
+	boolean hasName(String word);
+	
+	void printIn(StringBuffer buffer);
+}
diff --git a/src/org/eclipse/lisaac/model/items/ITMArgs.java b/src/org/eclipse/lisaac/model/items/ITMArgs.java
index 76ec72a..9ac2577 100644
--- a/src/org/eclipse/lisaac/model/items/ITMArgs.java
+++ b/src/org/eclipse/lisaac/model/items/ITMArgs.java
@@ -34,11 +34,11 @@ public class ITMArgs implements IArgument {
 		}
 		return -1;
 	}
-	
-	public boolean hasArgument(String word) {
+
+	public boolean hasName(String word) {
 		return lastIndexOf(word) != -1;
 	}
-
+	
 	public IType getType() {
 		// TODO Auto-generated method stub
 		return null;// FIXME list arg type
diff --git a/src/org/eclipse/lisaac/model/items/ITMArgument.java b/src/org/eclipse/lisaac/model/items/ITMArgument.java
index ff002a2..6811bf1 100644
--- a/src/org/eclipse/lisaac/model/items/ITMArgument.java
+++ b/src/org/eclipse/lisaac/model/items/ITMArgument.java
@@ -1,29 +1,33 @@
-package org.eclipse.lisaac.model.items;
-
-import org.eclipse.lisaac.model.types.IType;
-import org.eclipse.lisaac.model.types.ITypeMono;
-
-public class ITMArgument implements IArgument {
-	
-	protected String name;
-	protected ITypeMono type;
-	
-	public ITMArgument(String name, ITypeMono type) {
-		this.name = name;
-		this.type = type;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public IType getType() {
-		return type;
-	}
-	
-	public void printIn(StringBuffer buffer) {
-		buffer.append(name);
-		buffer.append(':');
-		buffer.append(type);
-	}
-}
+package org.eclipse.lisaac.model.items;
+
+import org.eclipse.lisaac.model.types.IType;
+import org.eclipse.lisaac.model.types.ITypeMono;
+
+public class ITMArgument implements IArgument {
+	
+	protected String name;
+	protected ITypeMono type;
+	
+	public ITMArgument(String name, ITypeMono type) {
+		this.name = name;
+		this.type = type;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public IType getType() {
+		return type;
+	}
+	
+	public boolean hasName(String word) {
+		return name.compareTo(word) == 0;
+	}
+	
+	public void printIn(StringBuffer buffer) {
+		buffer.append(name);
+		buffer.append(':');
+		buffer.append(type);
+	}
+}
diff --git a/src/org/eclipse/lisaac/model/items/ITMBlock.java b/src/org/eclipse/lisaac/model/items/ITMBlock.java
index 0fba3b3..7e58d4a 100644
--- a/src/org/eclipse/lisaac/model/items/ITMBlock.java
+++ b/src/org/eclipse/lisaac/model/items/ITMBlock.java
@@ -7,9 +7,11 @@ public class ITMBlock implements ICode {
 	protected ITMList list;
 	protected IArgument argument;
 	
-	public ITMBlock(ITMList list, IArgument argument) {
+	public ITMBlock(ITMList list, IArgument argument, Slot slot) {
 		this.list = list;
 		this.argument = argument;
+		
+		slot.addSubList(this);
 	}
 
 	public IType getType(Slot slot, Prototype prototype) {
diff --git a/src/org/eclipse/lisaac/model/items/ITMList.java b/src/org/eclipse/lisaac/model/items/ITMList.java
index 9534bde..8039725 100644
--- a/src/org/eclipse/lisaac/model/items/ITMList.java
+++ b/src/org/eclipse/lisaac/model/items/ITMList.java
@@ -7,7 +7,16 @@ public class ITMList implements ICode {
 	protected ITMLocal[] localList;
 	protected ITMLocal[] staticList;
 
-	public ITMList() {
+	protected int startOffset, endOffset;
+	
+	public ITMList(Slot slot, int start) {
+		startOffset = start;
+		endOffset = startOffset;
+		slot.addSubList(this);
+	}
+	
+	public void setEndOffset(int end) {
+		endOffset = end;
 	}
 
 	public void setCode(ICode[] code) {
@@ -49,4 +58,8 @@ public class ITMList implements ICode {
 		}
 		return null;
 	}
+	
+	public boolean isInside(int offset) {
+		return offset >= startOffset && offset <= endOffset;
+	}
 }
diff --git a/src/org/eclipse/lisaac/model/items/ITMPrototype.java b/src/org/eclipse/lisaac/model/items/ITMPrototype.java
index 440ad83..1d7e958 100644
--- a/src/org/eclipse/lisaac/model/items/ITMPrototype.java
+++ b/src/org/eclipse/lisaac/model/items/ITMPrototype.java
@@ -2,7 +2,6 @@ package org.eclipse.lisaac.model.items;
 
 import org.eclipse.lisaac.model.types.IType;
 import org.eclipse.lisaac.model.types.ITypeMono;
-import org.eclipse.lisaac.model.types.TypeSimple;
 
 public class ITMPrototype implements ICode {
 	protected ITypeMono type;
diff --git a/src/org/eclipse/lisaac/model/items/Slot.java b/src/org/eclipse/lisaac/model/items/Slot.java
index 2cec93f..ac132d6 100644
--- a/src/org/eclipse/lisaac/model/items/Slot.java
+++ b/src/org/eclipse/lisaac/model/items/Slot.java
@@ -1,8 +1,6 @@
 package org.eclipse.lisaac.model.items;
 
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
 
 import org.eclipse.jface.text.contentassist.CompletionProposal;
 import org.eclipse.jface.text.contentassist.ICompletionProposal;
@@ -26,6 +24,10 @@ public class Slot  {
 
 	protected String[] keywordList;
 
+	protected ICode value;
+
+	protected ArrayList<ICode> subLists;
+
 
 	public Slot(Position position, String name, Section sectionId) {
 		this.name = name;
@@ -79,7 +81,6 @@ public class Slot  {
 	//
 	// Value.
 	//
-	ICode value;
 
 	public void setValue(ICode v) {
 		if (affect == '<') {
@@ -92,6 +93,13 @@ public class Slot  {
 		return value;
 	}
 
+	public void addSubList(ICode list) {
+		if (subLists == null) {
+			subLists = new ArrayList<ICode>();
+		}
+		subLists.add(list);
+	}
+
 	//
 	// Access associativity & priority level.
 	//
@@ -134,11 +142,7 @@ public class Slot  {
 	public IArgument getArgument(String word) {
 		if (argumentList != null) {
 			for (int i=0; i<argumentList.length; i++) {
-				if (argumentList[i] instanceof ITMArgs) {
-					if (((ITMArgs)argumentList[i]).hasArgument(word)) {
-						return argumentList[i];
-					}
-				} else if (argumentList[i].getName().compareTo(word) == 0) {
+				if (argumentList[i].hasName(word)) {
 					return argumentList[i];
 				}
 			}
@@ -146,6 +150,32 @@ public class Slot  {
 		return null;
 	}
 
+	public boolean hasVariableDefinition(String word, int offset) {
+		ITMList list;
+		
+		if (subLists != null) {
+			for (int i=0; i< subLists.size(); i++) {
+				ICode c = subLists.get(i);		
+				
+				if (c instanceof ITMList) {
+					list = (ITMList) c;
+					if (list.isInside(offset) && list.hasVariableDefinition(word)) {
+						// list variable
+						return true;
+					}
+				} else if (c instanceof ITMBlock) {
+					list = ((ITMBlock) c).list;
+
+					if (list.isInside(offset) && ((ITMBlock) c).argument.hasName(word)) {
+						// block argument
+						return true;
+					}
+				}
+			}
+		}
+		return false;
+	}
+
 	public Prototype getPrototype() {
 		return sectionId.getPrototype();
 	}
@@ -189,13 +219,13 @@ public class Slot  {
 				offset, length, displayString.length()-1, image,
 				getSignature(false), null, null));
 	}
-	
+
 	public void getSlotMatchProposals(ArrayList<ICompletionProposal> proposals, 
 			int offset, int length, int matchLength) {
 
 		Image image = new OutlineSlot(this).getImage();
 		String displayString = getSignature(true);
-		
+
 		displayString = displayString.substring(matchLength);
 		proposals.add(new CompletionProposal(displayString,
 				offset, length, displayString.length(), image,

-- 
Lisaac eclipse plugin



More information about the Lisaac-commits mailing list