Skip to content

Commit 63b9a5e

Browse files
committed
Add a trivial Modelica syntax highlighter
1 parent 079fb6a commit 63b9a5e

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/main/java/net/sourceforge/pmd/util/fxdesigner/util/codearea/AvailableSyntaxHighlighters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.sourceforge.pmd.lang.Language;
1414
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.ApexSyntaxHighlighter;
1515
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.JavaSyntaxHighlighter;
16+
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.ModelicaSyntaxHighlighter;
1617
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.ScalaSyntaxHighlighter;
1718
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.XPathSyntaxHighlighter;
1819
import net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.XmlSyntaxHighlighter;
@@ -35,7 +36,8 @@ public enum AvailableSyntaxHighlighters implements SyntaxHighlighter {
3536
XSL("xsl", new XmlSyntaxHighlighter()),
3637
WSDL("wsdl", new XmlSyntaxHighlighter()),
3738
POM("pom", new XmlSyntaxHighlighter()),
38-
XPATH("xpath", new XPathSyntaxHighlighter());
39+
XPATH("xpath", new XPathSyntaxHighlighter()),
40+
MODELICA("modelica", new ModelicaSyntaxHighlighter());
3941

4042

4143
private final String language;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting;
6+
7+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.BOOLEAN;
8+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.BRACE;
9+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.BRACKET;
10+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.IDENTIFIER;
11+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.KEYWORD;
12+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.MULTIL_COMMENT;
13+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.NUMBER;
14+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.PAREN;
15+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.SEMICOLON;
16+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.SINGLEL_COMMENT;
17+
import static net.sourceforge.pmd.util.fxdesigner.util.codearea.syntaxhighlighting.HighlightClasses.STRING;
18+
19+
import java.util.regex.Pattern;
20+
21+
import net.sourceforge.pmd.util.fxdesigner.util.codearea.SimpleRegexSyntaxHighlighter;
22+
23+
public class ModelicaSyntaxHighlighter extends SimpleRegexSyntaxHighlighter {
24+
25+
private static final String[] KEYWORDS = {
26+
"import", "within", "encapsulated", "partial", "final",
27+
"class", "model", "operator", "record", "block", "expandable",
28+
"connector", "type", "package", "pure", "impure", "function",
29+
"extends", "end", "enumeration", "public", "protected", "external",
30+
"redeclare", "inner", "outer", "replaceable", "constrainedby",
31+
"flow", "stream", "discrete", "parameter", "constant", "input",
32+
"output", "der", "connect", "if", "each", "initial", "equation",
33+
"algorithm", "annotation", "break", "return", "then", "elseif",
34+
"else", "for", "loop", "in", "while", "when", "elsewhen", "or",
35+
"and", "not", "true", "false",
36+
};
37+
38+
// based on Java highlighter
39+
private static final RegexHighlightGrammar GRAMMAR
40+
= grammarBuilder(SINGLEL_COMMENT.css, "//[^\n]*")
41+
.or(MULTIL_COMMENT.css, "/\\*.*?\\*/")
42+
.or(PAREN.css, "[()]")
43+
.or(NUMBER.css, asWord("\\d[_\\d]*+(\\.\\d(_?\\d)*+)?[fdlFDL]?"))
44+
.or(BRACE.css, "[{}]")
45+
.or(BRACKET.css, "[\\[]]")
46+
.or(SEMICOLON.css, ";")
47+
.or(KEYWORD.css, alternation(KEYWORDS))
48+
.or(STRING.css, "\"[^\"\\\\]*(\\\\.[^\"\\\\]*)*\"")
49+
.or(BOOLEAN.css, asWord("true|false"))
50+
.or(IDENTIFIER.css, asWord("[\\w_$]+"))
51+
.create(Pattern.DOTALL);
52+
53+
public ModelicaSyntaxHighlighter() {
54+
super("modelica", GRAMMAR);
55+
}
56+
}

0 commit comments

Comments
 (0)