Skip to content

Latest commit

 

History

History
25 lines (16 loc) · 1.71 KB

File metadata and controls

25 lines (16 loc) · 1.71 KB

Rouge Plugin Example

This is an example repository for those interested in developing a plug-in to add a language to Rouge. By way of example, this implements my thesis language, Magritte (pdf).

How to use

  • spec/visual/samples/magritte holds the visual spec - this is text intended to stress-test the lexer and catch any weirdnesses or errors.
  • ruby preview.rb will output the highlighted sample to the terminal. Set the environment variable DEBUG=1 to instead output detailed debugging information.
  • rake or rake spec runs the tests.
  • rake server runs a preview server on port 9292, which hot-reloads the lexer.

Making your own plug-in

You can either use this repository as a starting point (make sure to rename files and constants as relevant, and replace LICENSE), or simply use this as a reference while writing your own. Rouge is extensible simply by subclassing Rouge::RegexLexer, but some of the logic in this repository can be convenient for live-previewing some sample text while developing the lexer.

Additionally, spec/rouge_magritte_spec.rb shows how to best to test relevant properties of a lexer - that it preserves the input, and at least the demo does not contain any error tokens. You are welcome to adapt any of this to your project, with your preferred test framework or testing approach.

Also please read our Lexer Development Guide for a general guide on using the Rouge API to define a lexer.