Class SimpleRegexSyntaxHighlighter
- java.lang.Object
-
- net.sourceforge.pmd.util.fxdesigner.util.codearea.SimpleRegexSyntaxHighlighter
-
- All Implemented Interfaces:
SyntaxHighlighter
- Direct Known Subclasses:
ApexSyntaxHighlighter
,JavaSyntaxHighlighter
,ModelicaSyntaxHighlighter
,XmlSyntaxHighlighter
,XPathSyntaxHighlighter
public abstract class SimpleRegexSyntaxHighlighter extends java.lang.Object implements SyntaxHighlighter
Language-specific engine for syntax highlighting. This implementation tokenises the text using regex, and assigns a specific CSS class to every found token. The whole text also receives a style class named after the language of the tokenizer (e.g. "xml" or "java"). Styling of each class is then done in stylesheets.- Since:
- 6.0.0
- Author:
- Clément Fournier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SimpleRegexSyntaxHighlighter.RegexHighlightGrammar
Describes the tokens of the language that should be colored with a regular expression.protected static class
SimpleRegexSyntaxHighlighter.RegexHighlightGrammarBuilder
Builds a highlight grammar in a concise way.
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleRegexSyntaxHighlighter(java.lang.String languageName, SimpleRegexSyntaxHighlighter.RegexHighlightGrammar grammar)
Creates a highlighter given a name for the language and a "regex grammar".
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.lang.String
alternation(java.lang.String[] alternatives)
Returns a regex alternation for the given words.protected static java.lang.String
asWord(java.lang.String regex)
org.fxmisc.richtext.model.StyleSpans<java.util.Collection<java.lang.String>>
computeHighlighting(java.lang.String text)
Computes the syntax highlighting on the given text.java.lang.String
getLanguageTerseName()
Gets the terse name of the language this highlighter cares for.protected static SimpleRegexSyntaxHighlighter.RegexHighlightGrammarBuilder
grammarBuilder(java.util.Collection<java.lang.String> cssClass, java.lang.String pattern)
Gets a builder to make a grammar to build a highlighter.
-
-
-
Constructor Detail
-
SimpleRegexSyntaxHighlighter
protected SimpleRegexSyntaxHighlighter(java.lang.String languageName, SimpleRegexSyntaxHighlighter.RegexHighlightGrammar grammar)
Creates a highlighter given a name for the language and a "regex grammar".- Parameters:
languageName
- The language namegrammar
- The grammar
-
-
Method Detail
-
computeHighlighting
public org.fxmisc.richtext.model.StyleSpans<java.util.Collection<java.lang.String>> computeHighlighting(java.lang.String text)
Description copied from interface:SyntaxHighlighter
Computes the syntax highlighting on the given text. The returned spans are exactly the length of the given text.- Specified by:
computeHighlighting
in interfaceSyntaxHighlighter
- Parameters:
text
- The text- Returns:
- The computed style spans
-
getLanguageTerseName
public final java.lang.String getLanguageTerseName()
Description copied from interface:SyntaxHighlighter
Gets the terse name of the language this highlighter cares for. That's used as a css class for text regions.- Specified by:
getLanguageTerseName
in interfaceSyntaxHighlighter
- Returns:
- The terse name of the language
-
alternation
protected static java.lang.String alternation(java.lang.String[] alternatives)
Returns a regex alternation for the given words. The words must not begin with an escaped character.- Parameters:
alternatives
- Words to join
-
asWord
protected static java.lang.String asWord(java.lang.String regex)
-
grammarBuilder
protected static SimpleRegexSyntaxHighlighter.RegexHighlightGrammarBuilder grammarBuilder(java.util.Collection<java.lang.String> cssClass, java.lang.String pattern)
Gets a builder to make a grammar to build a highlighter.- Parameters:
cssClass
- The css class of the first patternpattern
- The first pattern- Returns:
- A builder
-
-