Class SyntaxHighlighter

java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
org.daiitech.naftah.parser.SyntaxHighlighter
All Implemented Interfaces:
org.jline.reader.Highlighter

public class SyntaxHighlighter extends BaseHighlighter
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
  • 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:
      highlight in interface org.jline.reader.Highlighter
      Overrides:
      highlight in class BaseHighlighter
      Parameters:
      reader - the line reader
      buffer - the input string buffer
      Returns:
      an AttributedString containing 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 AttributedStyle for the token