Package org.daiitech.naftah.parser
Class SyntaxHighlighter
java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
org.daiitech.naftah.parser.SyntaxHighlighter
- All Implemented Interfaces:
org.jline.reader.Highlighter
A syntax highlighter class specifically tailored for highlighting
Naftah language source code in a terminal environment.
It tokenizes the input buffer using a lexer and applies color styling to various language constructs based on token types.
Right-to-left (RTL) shaping and terminal wrapping support are also handled.
- Author:
- Chakib Daii
-
Field Summary
Fields inherited from class org.daiitech.naftah.utils.repl.BaseHighlighter
originalHighlighter -
Constructor Summary
ConstructorsConstructorDescriptionSyntaxHighlighter(org.jline.reader.Highlighter originalHighlighter) Constructs a SyntaxHighlighter that wraps another highlighter. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.jline.utils.AttributedStylegetStyleForTokenType(int tokenType) Maps token types to specific styles (e.g., colors, bold, italic).org.jline.utils.AttributedStringHighlights the input line with token-based styles and formatting.Methods inherited from class org.daiitech.naftah.utils.repl.BaseHighlighter
merge, setErrorIndex, setErrorPatternMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jline.reader.Highlighter
refresh
-
Constructor Details
-
SyntaxHighlighter
public SyntaxHighlighter(org.jline.reader.Highlighter originalHighlighter) Constructs a SyntaxHighlighter that wraps another highlighter.- Parameters:
originalHighlighter- the base highlighter to delegate to
-
-
Method Details
-
highlight
public org.jline.utils.AttributedString highlight(org.jline.reader.LineReader reader, String buffer) Highlights the input line with token-based styles and formatting. It performs RTL shaping and wraps lines based on terminal width.- Specified by:
highlightin interfaceorg.jline.reader.Highlighter- Overrides:
highlightin classBaseHighlighter- Parameters:
reader- the line readerbuffer- the input string buffer- Returns:
- an
AttributedStringcontaining styled output - Throws:
org.jline.reader.EOFError- if the buffer contains escape sequences indicating multiline
-
getStyleForTokenType
private org.jline.utils.AttributedStyle getStyleForTokenType(int tokenType) Maps token types to specific styles (e.g., colors, bold, italic).- Parameters:
tokenType- the integer type of the token from the lexer- Returns:
- the corresponding
AttributedStylefor the token
-