]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
All modelica keywords are highlighted.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Sep 2010 06:49:17 +0000 (06:49 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Sep 2010 06:49:17 +0000 (06:49 +0000)
Fixed the bug where the end of the word is highlighted, if it is a keyword.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17955 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableNameValidator.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java

index 56ae17abb2de89ec5a9de02028b571eb32ea82ff..e4819708338e6d322a6e0bcf325e86efcc72fbc5 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import java.util.HashSet;\r
+import java.util.Set;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
@@ -9,6 +11,72 @@ public class VariableNameValidator {
                String lowerCase = name.toLowerCase();\r
                Pattern p = Pattern.compile("[a-zA-Z0-9]++");\r
                Matcher m = p.matcher(lowerCase);\r
-               return m.matches();\r
+               if (!m.matches() || keywords.contains(name))\r
+                       return false;\r
+               else\r
+                       return true;\r
+       }\r
+       \r
+       public static final Set<String> keywords = new HashSet<String>();\r
+\r
+       static {\r
+               keywords.add("algorithm");\r
+               keywords.add("discrete");\r
+               keywords.add("false");\r
+               keywords.add("model");\r
+               keywords.add("redeclare");\r
+               keywords.add("and");\r
+               keywords.add("each");\r
+               keywords.add("final");\r
+               keywords.add("not");\r
+               keywords.add("replaceable");\r
+               keywords.add("annotation");\r
+               keywords.add("else");\r
+               keywords.add("flow");\r
+               keywords.add("operator");\r
+               keywords.add("return");\r
+               keywords.add("assert");\r
+               keywords.add("elseif");\r
+               keywords.add("for");\r
+               keywords.add("or");\r
+               keywords.add("stream");\r
+               keywords.add("block");\r
+               keywords.add("elsewhen");\r
+               keywords.add("function");\r
+               keywords.add("outer");\r
+               keywords.add("then");\r
+               keywords.add("break");\r
+               keywords.add("encapsulated");\r
+               keywords.add("if");\r
+               keywords.add("output");\r
+               keywords.add("true");\r
+               keywords.add("class");\r
+               keywords.add("end");\r
+               keywords.add("import");\r
+               keywords.add("package");\r
+               keywords.add("type");\r
+               keywords.add("connect");\r
+               keywords.add("enumeration");\r
+               keywords.add("in");\r
+               keywords.add("parameter");\r
+               keywords.add("when");\r
+               keywords.add("connector");\r
+               keywords.add("equation");\r
+               keywords.add("initial");\r
+               keywords.add("partial");\r
+               keywords.add("while");\r
+               keywords.add("constant");\r
+               keywords.add("expandable");\r
+               keywords.add("inner");\r
+               keywords.add("protected");\r
+               keywords.add("within");\r
+               keywords.add("constrainedby");\r
+               keywords.add("extends");\r
+               keywords.add("input");\r
+               keywords.add("public");\r
+               keywords.add("der");\r
+               keywords.add("external");\r
+               keywords.add("loop");\r
+               keywords.add("record");\r
        }\r
 }\r
index 68d46d86564c05f79d4f95b5b09597640fcb0671..08ecb22ddf6e83b1aa512f8ac615b276dd8402e3 100644 (file)
@@ -11,9 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.properties.widgets.expressions;\r
 \r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
 import org.eclipse.jface.text.DefaultTextHover;\r
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.jface.text.ITextHover;\r
@@ -24,6 +21,7 @@ import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
 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.MultiLineRule;\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
@@ -33,148 +31,84 @@ import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.graphics.RGB;\r
+import org.simantics.sysdyn.ui.properties.VariableNameValidator;\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 reserved = new Token(\r
-                new TextAttribute(\r
-                        colorManager.getColor(new RGB(127, 0, 85)),\r
-                        null,\r
-                        SWT.BOLD\r
-                ));\r
-        \r
-\r
-        WordRule reservedWord = new WordRule(new IWordDetector() {   \r
-            @Override\r
-            public boolean isWordStart(char c) {\r
-                return Character.isLetter(c);\r
-            }\r
-\r
-            @Override\r
-            public boolean isWordPart(char c) {\r
-                return Character.isLetter(c);\r
-            }\r
-        });\r
-\r
-        for(String s : keywords) {\r
-            reservedWord.addWord(s, reserved);\r
-        }\r
-\r
-        IRule[] rules = new IRule[] {\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
-     static final Set<String> keywords = new HashSet<String>();\r
-     \r
-     static {\r
-         keywords.add("within");\r
-         keywords.add("final");\r
-         keywords.add("public");\r
-         keywords.add("protected");\r
-         keywords.add("connect");\r
-         keywords.add("when");\r
-         keywords.add("then");\r
-         keywords.add("elsewhen");\r
-         keywords.add("if");\r
-         keywords.add("end");\r
-         keywords.add("elseif");\r
-         keywords.add("else");\r
-         keywords.add("for");\r
-         keywords.add("while");\r
-         keywords.add("loop");\r
-         keywords.add("der");\r
-         keywords.add("enumeration");\r
-         keywords.add("extends");\r
-         keywords.add("class");\r
-         keywords.add("partial");\r
-         keywords.add("encapsulated");\r
-         keywords.add("model");\r
-         keywords.add("record");\r
-         keywords.add("block");\r
-         keywords.add("expandable");\r
-         keywords.add("connector");\r
-         keywords.add("type");\r
-         keywords.add("package");\r
-         keywords.add("function");\r
-         keywords.add("import");\r
-         keywords.add("external");\r
-         keywords.add("constrainedby");\r
-         keywords.add("redeclare");\r
-         keywords.add("replaceable");\r
-         keywords.add("flow");\r
-         keywords.add("discrete");\r
-         keywords.add("parameter");\r
-         keywords.add("constant");\r
-         keywords.add("input");\r
-         keywords.add("output");\r
-         keywords.add("annotation");\r
-         keywords.add("false");\r
-         keywords.add("true");\r
-         keywords.add("each");\r
-         keywords.add("initial");\r
-         keywords.add("algorithm");\r
-         keywords.add("equation");\r
-         keywords.add("or");\r
-         keywords.add("and");\r
-         keywords.add("not");\r
-         keywords.add("break");\r
-         keywords.add("return");     \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
+       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
+       ITokenScanner getSclTokenScanner() {\r
+               RuleBasedScanner scanner = new RuleBasedScanner();\r
+\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 defaultToken = new Token(new TextAttribute(colorManager.getColor(new RGB(0, 0, 0))));\r
+\r
+                final Token comment = new Token(new TextAttribute(colorManager.getColor(new RGB(63, 127, 95))));\r
+\r
+\r
+               WordRule reservedWord = new WordRule(new IWordDetector() {   \r
+                       @Override\r
+                       public boolean isWordStart(char c) {\r
+                               return Character.isLetter(c);\r
+                       }\r
+\r
+                       @Override\r
+                       public boolean isWordPart(char c) {\r
+                               return Character.isLetter(c);\r
+                       }\r
+               }, defaultToken);\r
+               \r
+\r
+               for(String s : VariableNameValidator.keywords) {\r
+                       reservedWord.addWord(s, reserved);\r
+               }\r
+\r
+               IRule[] rules = new IRule[] {\r
+                               reservedWord,\r
+                               new MultiLineRule("/*", "*/", comment)\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