|
| 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