]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
SourceViewer not working
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 12:32:46 +0000 (12:32 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 12:32:46 +0000 (12:32 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13767 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj
org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/TestExpressionParser.java

index f2be79e668762e751f8b15724c6a83d0810b7866..7a7185bf593062fd79ceeb4329d574f20a879ffa 100644 (file)
             commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
       </handler>\r
    </extension>\r
-\r
+-  <extension point="org.eclipse.ui.editors.annotationTypes">\r
+      <type markerSeverity="0" name="com.mycompany.element" /> \r
+   </extension>\r
+-     <extension point="org.eclipse.ui.editors.markerAnnotationSpecification">\r
+      <specification annotationType="com.mycompany.element" colorPreferenceKey="annotateElemColor" colorPreferenceValue="255,255,0" highlightPreferenceKey="annotateElemHighlight" highlightPreferenceValue="true" includeOnPreferencePage="true" label="Sample Annotation" overviewRulerPreferenceKey="annotateElemOverviewRuler" textPreferenceKey="annotateElemText" verticalRulerPreferenceKey="annotateElemVerticalRuler" verticalRulerPreferenceValue="true" /> \r
+   </extension>\r
 </plugin>\r
index f741b600e450be5d5287c62d6493eab66c3f729f..9ece38b081555ffab87edb2ccd4860620ae69d89 100644 (file)
@@ -2,7 +2,12 @@ package org.simantics.sysdyn.ui.equation;
 \r
 \r
 import java.io.StringReader;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
+import java.util.HashMap;\r
 import java.util.HashSet;\r
+import java.util.List;\r
 import java.util.Set;\r
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
@@ -10,6 +15,8 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.StyleRange;\r
+import org.eclipse.swt.custom.StyledText;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.KeyEvent;\r
@@ -23,9 +30,7 @@ import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.graphics.Font;\r
 import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.layout.RowLayout;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.TableItem;\r
 import org.eclipse.swt.widgets.Text;\r
@@ -41,6 +46,8 @@ import org.simantics.db.procedure.Listener;
 import org.simantics.db.request.Read;\r
 import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
 import org.simantics.sysdyn.expressionParser.ParseException;\r
+import org.simantics.sysdyn.expressionParser.Token;\r
+import org.simantics.sysdyn.ui.equation.expressions.ExpressionField;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 public class EquationView extends ViewPart implements ISelectionListener {\r
@@ -64,6 +71,20 @@ public class EquationView extends ViewPart implements ISelectionListener {
     // Dummies\r
     Composite unitsAndRange;  \r
     Composite emptyComposite;\r
+    \r
+    ExpressionField ef;\r
+\r
+\r
+    StyledText styledText;\r
+    \r
+    public static final String              ANNO_TYPE          = "org.eclipse.ui.workbench.texteditor.error";\r
+    public static final String              ANNO_KEY_HIGHLIGHT = "annotateElemHighlight";\r
+    public static final String              ANNO_KEY_OVERVIEW  = "annotateElemOverviewRuler";\r
+    public static final String              ANNO_KEY_VERTICAL  = "annotateElemVertialRuler";\r
+    public static final String              ANNO_KEY_TEXT      = "annotateElemText";\r
+    public static final String              ANNO_KEY_COLOR     = "annotateElemColor";\r
\r
+\r
 \r
     @Override    \r
     public void createPartControl(Composite parent) {\r
@@ -88,7 +109,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
                     if(unitSelector != null) {\r
                         unitSelector.save();                       \r
                     }\r
-                    \r
+\r
                     if(nameComposite != null) {\r
                         nameComposite.save(variable);\r
                     }\r
@@ -130,6 +151,9 @@ public class EquationView extends ViewPart implements ISelectionListener {
         emptyComposite = new Composite(parent, SWT.NONE);\r
         GridDataFactory.fillDefaults().span(1,4).grab(true, true).applyTo(emptyComposite);\r
         GridLayoutFactory.fillDefaults().applyTo(emptyComposite);\r
+        \r
+        ef = new ExpressionField(emptyComposite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(ef);\r
 \r
         // Below variable name: Equation\r
         expressionComposite = new ExpressionComposite(parent, SWT.NONE);\r
@@ -138,7 +162,42 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
         // Lower part of the view: Units and Range\r
         unitsAndRange = new Composite(parent, SWT.NONE); \r
-        GridDataFactory.fillDefaults().span(3, 1).applyTo(unitsAndRange);\r
+        GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(unitsAndRange);\r
+\r
+        GridLayoutFactory.fillDefaults().applyTo(unitsAndRange);\r
+\r
+        styledText = new StyledText(unitsAndRange, SWT.BORDER | SWT.H_SCROLL\r
+                | SWT.V_SCROLL);\r
+\r
+\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(styledText);\r
+\r
+        /*\r
+        styledText.addLineStyleListener(new LineStyleListener() {\r
+\r
+            public void lineGetStyle(LineStyleEvent event) {\r
+              // Create a collection to hold the StyleRanges\r
+              java.util.List styles = new java.util.ArrayList();\r
+              // Iterate through the text\r
+              for (int i = 0, n = event.lineText.length(); i < n; i++) {\r
+                // Check for 'e'\r
+                if (event.lineText.charAt(i) == 'e') {\r
+                  // Found an 'e'; combine all subsequent e's into the same StyleRange\r
+                  int start = i;\r
+                  for (; i < n && event.lineText.charAt(i) == 'e'; i++);\r
+\r
+                  // Create the StyleRange and add it to the collection\r
+                  styles.add(new StyleRange(event.lineOffset + start, i - start, styledText.getDisplay().getSystemColor(SWT.COLOR_RED),\r
+                      null));\r
+                }\r
+              }\r
+              // Set the styles for the line\r
+              event.styles = (StyleRange[]) styles.toArray(new StyleRange[0]);\r
+            }\r
+          });\r
+         */\r
+\r
+        /*\r
         RowLayout layout = new RowLayout();\r
         layout.spacing = 3;\r
         unitsAndRange.setLayout(layout);\r
@@ -155,6 +214,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
         text1.setToolTipText("Stop");\r
         text1 = new Text(c, SWT.SINGLE | SWT.BORDER);\r
         text1.setToolTipText("Step");\r
+         */\r
     }   \r
 \r
     static class Auxiliary {\r
@@ -330,11 +390,11 @@ public class EquationView extends ViewPart implements ISelectionListener {
                     }\r
                 });\r
                 text.addKeyListener(new KeyListener() {\r
-                    \r
+\r
                     @Override\r
                     public void keyReleased(KeyEvent e) {\r
                     }\r
-                    \r
+\r
                     @Override\r
                     public void keyPressed(KeyEvent e) {\r
                         if(e.keyCode == SWT.ESC && expression != null) {\r
@@ -349,14 +409,24 @@ public class EquationView extends ViewPart implements ISelectionListener {
     private void validateExpressionFields() {\r
         ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
         Set<String> variables = new HashSet<String>();\r
+        HashMap<String, List<Token>> references = null;\r
+\r
+\r
 \r
         if(expressionComposite.getExpressionViewFactor() != null)\r
             for(Text text : expressionComposite.getExpressionViewFactor().getExpressionFields()) {\r
+\r
+                \r
+                styledText.setText(text.getText());\r
+\r
                 String textString = text.getText();\r
                 parser.ReInit(new StringReader(textString));\r
                 try {\r
                     parser.expr();\r
-                    variables.addAll(parser.getReferences());\r
+                    System.out.println(parser.getReferences());\r
+                    references = parser.getReferences();\r
+                    for(String t : references.keySet())\r
+                        variables.add(t);\r
                     text.setBackground(new Color(text.getDisplay(), 255, 255, 255));\r
                 } catch (ParseException e1) {\r
                     text.setBackground(new Color(text.getDisplay(), 255, 230, 230));\r
@@ -376,11 +446,39 @@ public class EquationView extends ViewPart implements ISelectionListener {
         }\r
 \r
         if(!variables.isEmpty()) {\r
+            ArrayList<StyleRange> ranges = new ArrayList<StyleRange>();\r
             String no_connections = "No connections for: ";\r
             for(String s : variables) {\r
-                no_connections = no_connections + s + " ";\r
+                List<Token> tlist = references.get(s);\r
+                for(Token t : tlist) {\r
+                    no_connections = no_connections + s + "[" + t.beginLine + "," + \r
+                    t.beginColumn + "," + t.endLine + "," + t.endColumn + "]";\r
+                    int start = styledText.getOffsetAtLine(t.beginLine - 1) + t.beginColumn - 1;\r
+                    int length = t.endColumn - t.beginColumn + 1;\r
+                    System.out.println(start + ", " + length);\r
+                    ranges.add(new StyleRange( \r
+                            start,\r
+                            length, \r
+                            new Color(styledText.getDisplay(), 0, 0, 0), \r
+                            new Color(styledText.getDisplay(), 255, 255, 255), \r
+                            SWT.BOLD));\r
+                }\r
             }\r
+            System.out.println(no_connections);\r
+            Collections.sort(ranges, new StyleRangeSorter());\r
+            styledText.setStyleRanges(ranges.toArray(new StyleRange[0]));\r
         }\r
     }\r
 \r
+\r
+    class StyleRangeSorter implements Comparator<StyleRange> {\r
+        public int compare(StyleRange a, StyleRange b) {\r
+            Integer ai, bi;\r
+\r
+            ai = a.start;\r
+            bi = b.start;\r
+\r
+            return ai.compareTo(bi);\r
+        }\r
+    }\r
 }
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ColorManager.java
new file mode 100644 (file)
index 0000000..9a4e8c1
--- /dev/null
@@ -0,0 +1,32 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import java.util.HashMap;\r
+\r
+import org.eclipse.jface.text.source.ISharedTextColors;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.widgets.Display;\r
+\r
+public class ColorManager implements ISharedTextColors {\r
+\r
+    protected HashMap<RGB, Color> colorTable = new HashMap<RGB, Color>();\r
+\r
+    @Override\r
+    public void dispose() {\r
+        for(Color c : colorTable.values())\r
+            c.dispose();\r
+        colorTable.clear();\r
+    }\r
+\r
+    @Override\r
+    public Color getColor(RGB rgb) {\r
+        Color color = colorTable.get(rgb);\r
+        if (color == null) {\r
+            color = new Color(Display.getCurrent(), rgb);\r
+            colorTable.put(rgb, color);\r
+        }\r
+        return color;\r
+\r
+\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java
new file mode 100644 (file)
index 0000000..3c97db7
--- /dev/null
@@ -0,0 +1,144 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import org.eclipse.jface.text.Document;\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.PaintManager;\r
+import org.eclipse.jface.text.Position;\r
+import org.eclipse.jface.text.source.Annotation;\r
+import org.eclipse.jface.text.source.AnnotationModel;\r
+import org.eclipse.jface.text.source.AnnotationPainter;\r
+import org.eclipse.jface.text.source.CompositeRuler;\r
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;\r
+import org.eclipse.jface.text.source.IAnnotationAccess;\r
+import org.eclipse.jface.text.source.IOverviewRuler;\r
+import org.eclipse.jface.text.source.LineNumberRulerColumn;\r
+import org.eclipse.jface.text.source.MatchingCharacterPainter;\r
+import org.eclipse.jface.text.source.OverviewRuler;\r
+import org.eclipse.jface.text.source.SourceViewer;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.texteditor.AnnotationPreference;\r
+import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;\r
+import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;\r
+\r
+public class ExpressionField extends Composite {\r
+    \r
+    public static final String              ANNO_TYPE          = "com.mycompany.element";\r
+    public static final String              ANNO_KEY_HIGHLIGHT = "annotateElemHighlight";\r
+    public static final String              ANNO_KEY_OVERVIEW  = "annotateElemOverviewRuler";\r
+    public static final String              ANNO_KEY_VERTICAL  = "annotateElemVertialRuler";\r
+    public static final String              ANNO_KEY_TEXT      = "annotateElemText";\r
+    public static final String              ANNO_KEY_COLOR     = "annotateElemColor";\r
\r
+    protected SourceViewer                  _sourceViewer;\r
+    protected SourceViewerDecorationSupport _sds;\r
+    protected IDocument                     _document;\r
+    protected AnnotationModel               _annotationModel;\r
\r
+    protected String                        _docString         = "this\nis\na\ntest\ndocument";\r
+\r
+    ColorManager cManager = new ColorManager();\r
+    \r
+    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
+\r
+    public ExpressionField(Composite parent, int style) {\r
+        super(parent, style);\r
+\r
+        int VERTICAL_RULER_WIDTH = 12;\r
+        \r
+        int styles = SWT.V_SCROLL\r
+            | SWT.H_SCROLL\r
+            | SWT.MULTI\r
+            | SWT.BORDER\r
+            | SWT.FULL_SELECTION;\r
+\r
+        IOverviewRuler overviewRuler = new OverviewRuler(null, VERTICAL_RULER_WIDTH,\r
+                cManager);\r
+        CompositeRuler ruler = new CompositeRuler(VERTICAL_RULER_WIDTH);\r
\r
+        _document = new Document();\r
+        _document.set(_docString);\r
\r
+        _annotationModel = new AnnotationModel();\r
+        _annotationModel.connect(_document);\r
\r
+        _sourceViewer = new SourceViewer(parent,\r
+                                         ruler,\r
+                                         overviewRuler,\r
+                                         true,\r
+                                         styles);\r
+        _sourceViewer.configure(new ExpressionFieldConfiguration(cManager));\r
+        \r
+        \r
+        // Tämä ei esimerkissä \r
+        AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
+        _sourceViewer.addPainter(painter);\r
+        \r
+        _sds = new SourceViewerDecorationSupport(_sourceViewer,\r
+                                                 overviewRuler,\r
+                                                 annotationAccess,\r
+                                                 cManager);\r
+        // ^^^^^^^\r
+        \r
+        /* Esimerkistä:\r
+         _sds = new SourceViewerDecorationSupport(_sourceViewer,\r
+                                                 overviewRuler,\r
+                                                 null,\r
+                                                 cManager);\r
+         */\r
\r
+        AnnotationPreference ap = new AnnotationPreference();\r
+        ap.setColorPreferenceKey(ANNO_KEY_COLOR);\r
+        ap.setHighlightPreferenceKey(ANNO_KEY_HIGHLIGHT);\r
+        ap.setVerticalRulerPreferenceKey(ANNO_KEY_VERTICAL);\r
+        ap.setOverviewRulerPreferenceKey(ANNO_KEY_OVERVIEW);\r
+        ap.setTextPreferenceKey(ANNO_KEY_TEXT);\r
+        ap.setAnnotationType(ANNO_TYPE);\r
+        _sds.setAnnotationPreference(ap);\r
\r
+        _sds.install(PlatformUI.getPreferenceStore());\r
\r
+        _sourceViewer.setDocument(_document, _annotationModel);\r
\r
+        _sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL,\r
+                                                              SWT.FILL,\r
+                                                              true,\r
+                                                              true));\r
\r
+        ruler.addDecorator(0, new LineNumberRulerColumn());\r
\r
+        \r
+        Annotation annotation = new Annotation(false);\r
+        annotation.setType(ANNO_TYPE);\r
+        annotation.setText("moro!");\r
+        Position position = new Position(0, 4);\r
+        _annotationModel.addAnnotation(annotation, position);        \r
+\r
+\r
+        \r
+        PaintManager paintManager = new PaintManager(_sourceViewer);\r
+        MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(_sourceViewer,\r
+                new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} ));\r
+        matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160)));\r
+        paintManager.addPainter(matchingCharacterPainter);\r
+        \r
+        \r
+        \r
+        annotation = new Annotation(false);\r
+        annotation.setType("org.eclipse.ui.workbench.texteditor.error");\r
+        annotation.setText("Tekstiä!");\r
+        position = new Position(0, 4);\r
+        _sourceViewer.getAnnotationModel().addAnnotation(annotation, position);\r
+\r
+    }\r
+    \r
+    public SourceViewer getSourceViewer() {\r
+        return this._sourceViewer;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionFieldConfiguration.java
new file mode 100644 (file)
index 0000000..6c274f3
--- /dev/null
@@ -0,0 +1,122 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import org.eclipse.jface.text.DefaultTextHover;\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.ITextHover;\r
+import org.eclipse.jface.text.TextAttribute;\r
+import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
+import org.eclipse.jface.text.presentation.PresentationReconciler;\r
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;\r
+import org.eclipse.jface.text.rules.IRule;\r
+import org.eclipse.jface.text.rules.ITokenScanner;\r
+import org.eclipse.jface.text.rules.IWordDetector;\r
+import org.eclipse.jface.text.rules.PatternRule;\r
+import org.eclipse.jface.text.rules.RuleBasedScanner;\r
+import org.eclipse.jface.text.rules.Token;\r
+import org.eclipse.jface.text.rules.WordRule;\r
+import org.eclipse.jface.text.source.DefaultAnnotationHover;\r
+import org.eclipse.jface.text.source.IAnnotationHover;\r
+import org.eclipse.jface.text.source.ISourceViewer;\r
+import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.RGB;\r
+\r
+public class ExpressionFieldConfiguration extends SourceViewerConfiguration {\r
+\r
+\r
+    ColorManager colorManager;\r
+\r
+    public ExpressionFieldConfiguration(ColorManager colorManager) {\r
+        super();\r
+        this.colorManager = colorManager;\r
+    }\r
+\r
+    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
+        return new String[] {\r
+                IDocument.DEFAULT_CONTENT_TYPE\r
+        };\r
+    }\r
+\r
+    /*\r
+    @Override\r
+    public IAutoEditStrategy[] getAutoEditStrategies(\r
+            ISourceViewer sourceViewer, String contentType) {\r
+        return new IAutoEditStrategy[] {\r
+                new ReplaceTabsBySpaces(),\r
+                new IndentLineEditStrategy(),\r
+                new MatchingBracketsEditStrategy()\r
+        };\r
+    }\r
+    */\r
+\r
+    public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
+        PresentationReconciler reconciler = new PresentationReconciler();\r
+\r
+        DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());\r
+\r
+        reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
+        reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
+\r
+        return reconciler;\r
+    }\r
+\r
+    /*\r
+     * \r
+     */\r
+     ITokenScanner getSclTokenScanner() {\r
+        RuleBasedScanner scanner = new RuleBasedScanner();\r
+\r
+        final Token string = new Token(new TextAttribute(colorManager.getColor(new RGB(42, 0, 255))));  \r
+        final Token reserved = new Token(\r
+                new TextAttribute(\r
+                        colorManager.getColor(new RGB(127, 0, 85)),\r
+                        null,\r
+                        SWT.BOLD\r
+                ));\r
+        final Token comment = new Token(new TextAttribute(colorManager.getColor(new RGB(63, 127, 95))));\r
+\r
+        WordRule reservedWord = new WordRule(new IWordDetector() {   \r
+            @Override\r
+            public boolean isWordStart(char c) {\r
+                return c=='@';\r
+            }\r
+\r
+            @Override\r
+            public boolean isWordPart(char c) {\r
+                return Character.isJavaIdentifierPart(c);\r
+            }\r
+        });\r
+\r
+        reservedWord.addWord("@a", reserved);\r
+        reservedWord.addWord("@keywords", reserved);\r
+        reservedWord.addWord("@forAll", reserved);\r
+        reservedWord.addWord("@forSome", reserved);\r
+        reservedWord.addWord("@true", reserved);\r
+        reservedWord.addWord("@false", reserved);\r
+        reservedWord.addWord("@base", reserved);\r
+        reservedWord.addWord("@prefix", reserved);\r
+\r
+        IRule[] rules = new IRule[] {\r
+                //new MultiLineRule("\"\"\"", "\"\"\"", string),\r
+                new PatternRule("\"", "\"", string, '\\', true),   \r
+                new PatternRule("\"\"\"", "\"\"\"", string, '\\', false),\r
+                new PatternRule("<", ">", string, '\\', false),\r
+                new PatternRule("#", null, comment, '\0', true),\r
+                reservedWord\r
+        };\r
+        scanner.setRules(rules);\r
+\r
+        return scanner;  \r
+     }\r
+\r
+     @Override\r
+     public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {\r
+         return new DefaultTextHover(sourceViewer);\r
+     }\r
+\r
+     @Override\r
+     public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {\r
+         return new DefaultAnnotationHover();\r
+     }\r
+\r
+}\r
index b9fd2b45fb0f98c8b9205a5eaf9a6545da69cfcb..2dbca6f54c4433c6aae9b2316935a3c0538754b2 100644 (file)
@@ -8,13 +8,18 @@ package org.simantics.sysdyn.expressionParser;
 \r
 import java.util.Set;\r
 import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
 \r
 public class ExpressionParser {\r
-    Set<String> references = new HashSet<String>();\r
+       HashMap<String, List<Token>> references = new HashMap<String, List<Token>>();\r
     \r
-    public Set<String> getReferences() {\r
+    public HashMap<String, List<Token>> getReferences() {\r
         return references;\r
     }\r
+    \r
+    \r
 }\r
 PARSER_END(ExpressionParser)\r
 \r
@@ -56,7 +61,7 @@ TOKEN:
 // { add_op term } -> ( add_op() term() )*\r
 \r
 void expr() : {\r
-       references = new HashSet<String>();\r
+       references = new HashMap<String, List<Token>>();\r
 } {\r
        simple_expression() <EOF> \r
        | "if" expression() "then" expression() ( "elseif" expression() "then" expression() )*\r
@@ -148,7 +153,15 @@ void name() : {
 void component_reference() : {\r
 } {\r
        //IDENT [ array_subscripts ] [ "." component_reference ]\r
-       <IDENT> { references.add(token.image); } \r
+       <IDENT> { \r
+       \r
+       if(references.get(token.image) == null) {\r
+               references.put(token.image, new ArrayList<Token>());\r
+       }\r
+       List list = references.get(token.image);\r
+       list.add(token); \r
+       \r
+       } \r
        ( "." component_reference() )?\r
 }\r
 \r
index bed43adb1ae49c64fd68e51488fb16a85c2eba81..ec74402b7a1536bd5c337937ae0cc6fa73c1a505 100644 (file)
@@ -1,6 +1,8 @@
 package org.simantics.sysdyn.expressionParser;\r
 \r
 import java.io.StringReader;\r
+import java.util.HashMap;\r
+import java.util.List;\r
 \r
 public class TestExpressionParser {\r
     \r
@@ -10,7 +12,8 @@ public class TestExpressionParser {
         parser.ReInit(new StringReader(string));\r
         try {\r
             parser.expr();\r
-            for(String ref : parser.getReferences()) {\r
+            HashMap<String, List<Token>> references = parser.getReferences();\r
+            for(String ref : references.keySet()) {\r
                 System.out.println(ref);\r
             }\r
         } catch (ParseException e) {\r