Commit 8d318652 authored by jayherron's avatar jayherron

Added coloration features and cleaned class code.

parent db4f69e2
...@@ -7,7 +7,10 @@ site ...@@ -7,7 +7,10 @@ site
area: 3702ft² area: 3702ft²
geoAddr: "100 Main St, Richmond, VA" geoAddr: "100 Main St, Richmond, VA"
geoCoord: C(37.5458,-77.4491) geoCoord: C(37.5458,-77.4491)
uri: `http://www.openstreetmap.org`
strTag: OK if unquoted if only safe chars strTag: OK if unquoted if only safe chars
id: @p:test:r:2173d4a5-9c12a854
user: @u:jherron
summary: summary:
This is a string value which spans multiple This is a string value which spans multiple
lines with two or more space characters lines with two or more space characters
...@@ -34,4 +37,52 @@ site ...@@ -34,4 +37,52 @@ site
src: src:
() => do () => do
return "hello world" return "hello world"
end end
\ No newline at end of file ---
name:addEnumPoints
func
src:
// add an ahuMode enum point to all AHUs
() => do
readAll(ahu).each ahu => do
// tags for point
tags: {
disMacro: "\$equipRef \$navName",
navName: "Mode",
kind: "Str",
enum: "off,heat,cool",
point,
his,
sp,
ahuMode,
regionRef: ahu->regionRef,
siteRef: ahu->siteRef,
equipRef: ahu->id,
tz: ahu->siteRef->tz,
}
if (ahu.has("floorRef")) tags = tags.set("floorRef", ahu->floorRef)
// add the point
pt: diff(null, tags, {add}).commit
logInfo("addEnumPoints", "Adding " + pt.dis)
// populate the point's history
fan: read(fan and cmd and equipRef==ahu->id)
(fan->hisStart.date .. fan->hisEnd.date).eachDay d => do
items: []
cooling: ahuCoolPeriods(ahu, d)
heating: ahuHeatPeriods(ahu, d)
matrix: hisPeriodMatrix([cooling, heating])
matrix.each row => do
if (row->ts.date != d) return null
mode: "off"
if (row["v0"] == true) mode = "cool"
else if (row["v1"] == true) mode = "heat"
items = items.add({ts: row->ts, val: mode})
end
hisWrite(items, pt)
end
end
end
package trioeditor.editors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.rules.*;
/**
* This is a rule that simply detects the input character in any context.
* @author jay
*
*/
public class CharRule implements IRule {
/** Internal setting for the un-initialized column constraint */
protected static final int UNDEFINED= -1;
/** The token to be returned when this rule is successful */
protected IToken fToken;
/** The character to match */
protected char character;
/**
* Creates a rule which will return the specified
* token when a numerical sequence is detected.
*
* @param token the token to be returned
*/
public CharRule(char c, IToken token) {
character = c;
Assert.isNotNull(token);
fToken= token;
}
@Override
public IToken evaluate(ICharacterScanner scanner) {
int c= scanner.read();
if (c == character) {
return fToken;
}
scanner.unread();
return Token.UNDEFINED;
}
}
...@@ -8,6 +8,12 @@ import org.eclipse.swt.graphics.Color; ...@@ -8,6 +8,12 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
/**
* Standard color manager from template editor plugin.
*
* @author jay
*
*/
public class ColorManager { public class ColorManager {
protected Map fColorTable = new HashMap(10); protected Map fColorTable = new HashMap(10);
......
package trioeditor.editors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.rules.*;
/**
* An implementation of <code>IRule</code> detecting a numerical value with optional unit. Units are
* allowed to have an underscore, but special characters like subscipts or superscripts are missed.
*/
public class HaystackNumberRule implements IRule {
/** Internal setting for the un-initialized column constraint */
protected static final int UNDEFINED= -1;
/** The token to be returned when this rule is successful */
protected IToken fToken;
/**
* Creates a rule which will return the specified
* token when a numerical sequence is detected.
*
* @param token the token to be returned
*/
public HaystackNumberRule(IToken token) {
Assert.isNotNull(token);
fToken= token;
}
@Override
public IToken evaluate(ICharacterScanner scanner) {
// Get the preceeding character
scanner.unread();
int p= scanner.read();
if(!Character.isLetter(p)) { // Only continue if prev character is not a letter.
int c= scanner.read();
if(Character.isDigit(c)) {
do {
c= scanner.read();
} while (Character.isLetterOrDigit(c) || c=='_'); // Misses exponent characters.
scanner.unread();
return fToken;
}
scanner.unread();
return Token.UNDEFINED;
}
return Token.UNDEFINED;
}
}
...@@ -2,13 +2,27 @@ package trioeditor.editors; ...@@ -2,13 +2,27 @@ package trioeditor.editors;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
/**
* The colors to highlight the text with. These are intended to match the SkySpark Func app axon
* editor as closely as possible.
*
* @author jay
*
*/
public interface ITrioColorConstants { public interface ITrioColorConstants {
RGB COMMENT = new RGB(128, 0, 0); // Trio feature colors
RGB COORDINATE = new RGB(0, 128, 128);
RGB DEFAULT = new RGB(0, 0, 0); RGB DEFAULT = new RGB(0, 0, 0);
RGB KEYWORD = new RGB(128, 128, 0); RGB SPLIT = new RGB(0, 0, 128);
RGB NUMBER = new RGB(128, 0, 128); RGB TAG = new RGB(128, 128, 0);
RGB PROC_INSTR = new RGB(128, 128, 128);
RGB STRING = new RGB(0, 128, 0); // Axon code colors (to match the SkySpark Func app)
RGB TAG = new RGB(0, 0, 128); // These may fill in non-axon areas of trio files.
RGB BRACKET = new RGB(255, 0, 0);
RGB COMMENT = new RGB(0, 128, 0);
RGB COORDINATE = new RGB(128, 100, 0);
RGB KEYWORD = new RGB(0, 0, 255);
RGB NUMBER = new RGB(128, 0, 0);
RGB REF = new RGB(128, 0, 128);
RGB STRING = new RGB(0, 128, 128);
RGB URI = new RGB(0, 128, 128); // Same as string
} }
package trioeditor.editors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.rules.*;
/**
* An implementation of <code>IRule</code> detecting a haystack Ref format, which is an "@", followed
* by alphanumerical characters, underscores, dashes, and colons.
*/
public class RefRule implements IRule {
/** Internal setting for the un-initialized column constraint */
protected static final int UNDEFINED= -1;
/** The token to be returned when this rule is successful */
protected IToken fToken;
/**
* Creates a rule which will return the specified
* token when a numerical sequence is detected.
*
* @param token the token to be returned
*/
public RefRule(IToken token) {
Assert.isNotNull(token);
fToken= token;
}
@Override
public IToken evaluate(ICharacterScanner scanner) {
int c= scanner.read();
if (c == '@') {
do {
c= scanner.read();
} while (Character.isLetterOrDigit(c) || c=='_' || c=='-' || c==':');
scanner.unread();
return fToken;
}
scanner.unread();
return Token.UNDEFINED;
}
}
...@@ -11,7 +11,6 @@ import org.eclipse.jface.text.source.ISourceViewer; ...@@ -11,7 +11,6 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.source.SourceViewerConfiguration;
public class TrioConfiguration extends SourceViewerConfiguration { public class TrioConfiguration extends SourceViewerConfiguration {
private TrioDoubleClickStrategy doubleClickStrategy;
private TrioScanner scanner; private TrioScanner scanner;
private ColorManager colorManager; private ColorManager colorManager;
...@@ -27,15 +26,6 @@ public class TrioConfiguration extends SourceViewerConfiguration { ...@@ -27,15 +26,6 @@ public class TrioConfiguration extends SourceViewerConfiguration {
}; };
} }
@Override
public ITextDoubleClickStrategy getDoubleClickStrategy(
ISourceViewer sourceViewer,
String contentType) {
if (doubleClickStrategy == null)
doubleClickStrategy = new TrioDoubleClickStrategy();
return doubleClickStrategy;
}
protected TrioScanner getTrioScanner() { protected TrioScanner getTrioScanner() {
if (scanner == null) { if (scanner == null) {
scanner = new TrioScanner(colorManager); scanner = new TrioScanner(colorManager);
......
...@@ -11,12 +11,15 @@ public class TrioDocumentProvider extends FileDocumentProvider { ...@@ -11,12 +11,15 @@ public class TrioDocumentProvider extends FileDocumentProvider {
@Override @Override
protected IDocument createDocument(Object element) throws CoreException { protected IDocument createDocument(Object element) throws CoreException {
IDocument document = super.createDocument(element); IDocument document = super.createDocument(element);
// TODO Implement partitioning once I know what that is.
/* // This caused there to be strange areas that didn't get any formatting.
if (document != null) { if (document != null) {
IDocumentPartitioner partitioner = new FastPartitioner(new TrioPartitionScanner(), IDocumentPartitioner partitioner = new FastPartitioner(new TrioPartitionScanner(),
new String[] { TrioPartitionScanner.TRIO_RECORD }); new String[] { TrioPartitionScanner.TRIO_RECORD });
partitioner.connect(document); partitioner.connect(document);
document.setDocumentPartitioner(partitioner); document.setDocumentPartitioner(partitioner);
} }
*/
return document; return document;
} }
} }
\ No newline at end of file
package trioeditor.editors;
import org.eclipse.jface.text.*;
public class TrioDoubleClickStrategy implements ITextDoubleClickStrategy {
protected ITextViewer fText;
@Override
public void doubleClicked(ITextViewer part) {
int pos = part.getSelectedRange().x;
if (pos < 0)
return;
fText = part;
if (!selectComment(pos)) {
selectWord(pos);
}
}
protected boolean selectComment(int caretPos) {
IDocument doc = fText.getDocument();
int startPos, endPos;
try {
int pos = caretPos;
char c = ' ';
while (pos >= 0) {
c = doc.getChar(pos);
if (c == '\\') {
pos -= 2;
continue;
}
if (c == Character.LINE_SEPARATOR || c == '\"')
break;
--pos;
}
if (c != '\"')
return false;
startPos = pos;
pos = caretPos;
int length = doc.getLength();
c = ' ';
while (pos < length) {
c = doc.getChar(pos);
if (c == Character.LINE_SEPARATOR || c == '\"')
break;
++pos;
}
if (c != '\"')
return false;
endPos = pos;
int offset = startPos + 1;
int len = endPos - offset;
fText.setSelectedRange(offset, len);
return true;
} catch (BadLocationException x) {
}
return false;
}
protected boolean selectWord(int caretPos) {
IDocument doc = fText.getDocument();
int startPos, endPos;
try {
int pos = caretPos;
char c;
while (pos >= 0) {
c = doc.getChar(pos);
if (!Character.isJavaIdentifierPart(c))
break;
--pos;
}
startPos = pos;
pos = caretPos;
int length = doc.getLength();
while (pos < length) {
c = doc.getChar(pos);
if (!Character.isJavaIdentifierPart(c))
break;
++pos;
}
endPos = pos;
selectRange(startPos, endPos);
return true;
} catch (BadLocationException x) {
}
return false;
}
private void selectRange(int startPos, int stopPos) {
int offset = startPos + 1;
int length = stopPos - offset;
fText.setSelectedRange(offset, length);
}
}
\ No newline at end of file
package trioeditor.editors; package trioeditor.editors;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.*; import org.eclipse.jface.text.rules.*;
public class TrioPartitionScanner extends RuleBasedPartitionScanner { public class TrioPartitionScanner extends RuleBasedPartitionScanner {
......
...@@ -4,7 +4,7 @@ import org.eclipse.jface.text.rules.*; ...@@ -4,7 +4,7 @@ import org.eclipse.jface.text.rules.*;
import org.eclipse.jface.text.*; import org.eclipse.jface.text.*;
/** /**
* Defines the rules by * Defines the rules by which the Trio editor will operate.
* @author jay * @author jay
* *
*/ */
...@@ -12,12 +12,16 @@ public class TrioScanner extends RuleBasedScanner { ...@@ -12,12 +12,16 @@ public class TrioScanner extends RuleBasedScanner {
public TrioScanner(ColorManager manager) { public TrioScanner(ColorManager manager) {
IToken comment = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.COMMENT))); IToken comment = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.COMMENT)));
IToken split = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.SPLIT)));
IToken string = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.STRING))); IToken string = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.STRING)));
IToken uri = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.URI)));
IToken coordinate = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.COORDINATE))); IToken coordinate = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.COORDINATE)));
IToken number = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.NUMBER))); IToken number = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.NUMBER)));
IToken ref = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.REF)));
IToken keyword = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.KEYWORD))); IToken keyword = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.KEYWORD)));
IToken bracket = new Token(new TextAttribute(manager.getColor(ITrioColorConstants.BRACKET)));
IRule[] rules = new IRule[7]; IRule[] rules = new IRule[16];
// Multi-line rules // Multi-line rules
// Comment // Comment
...@@ -28,19 +32,25 @@ public class TrioScanner extends RuleBasedScanner { ...@@ -28,19 +32,25 @@ public class TrioScanner extends RuleBasedScanner {
rules[1] = new EndOfLineRule("//", comment); rules[1] = new EndOfLineRule("//", comment);
// Single-line rules // Single-line rules
// Rec split
rules[2] = new SingleLineRule("---", "", split);
// String // String
rules[2] = new SingleLineRule("\"", "\"", string); rules[3] = new SingleLineRule("\"", "\"", string);
// Uri (format as string)
rules[4] = new SingleLineRule("`", "`", uri);
// Coordinates // Coordinates
rules[3] = new SingleLineRule("C(", ")", coordinate); rules[5] = new SingleLineRule("C(", ")", coordinate);
// Coordinates // Numbers
rules[4] = new NumberRule(number); rules[6] = new HaystackNumberRule(number);
// Refs
rules[7] = new RefRule(ref);
// Add generic whitespace rule. // Add generic whitespace rule.
rules[5] = new WhitespaceRule(new TrioWhitespaceDetector()); rules[8] = new WhitespaceRule(new TrioWhitespaceDetector());
// Keywords // Keywords
final KeywordRule keywords = new KeywordRule(); KeywordRule keywords = new KeywordRule();
// Axon keywords // Axon keywords
keywords.addWord("null", keyword); keywords.addWord("null", keyword);
keywords.addWord("do", keyword); keywords.addWord("do", keyword);
...@@ -48,7 +58,15 @@ public class TrioScanner extends RuleBasedScanner { ...@@ -48,7 +58,15 @@ public class TrioScanner extends RuleBasedScanner {
keywords.addWord("return", keyword); keywords.addWord("return", keyword);
keywords.addWord("true", keyword); keywords.addWord("true", keyword);
keywords.addWord("false", keyword); keywords.addWord("false", keyword);
rules[6] = keywords; rules[9] = keywords;
// Character rules
rules[10] = new CharRule('(', bracket);
rules[11] = new CharRule(')', bracket);
rules[12] = new CharRule('{', bracket);
rules[13] = new CharRule('}', bracket);
rules[14] = new CharRule('[', bracket);
rules[15] = new CharRule(']', bracket);
setRules(rules); setRules(rules);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment