Synoptic
Syntax highlighting for Rust applications
I originally wrote this for my text editor, Ox. It needed a fast, robust and reliable syntax highlighter that was configurable and was able to easily plug-in to a front end.
Low-level
No pre-built language rules so everything is entirely up to you. Outputs a simple stream of tokens.
Fast
Takes advantage of Rust's speed. Benches say that it can highlight 18470 lines of Rust code in around 60 milliseconds
Simple
You can highlight code for most languages in just a few steps:
- Construct a
Highlighter
instance - Add regular expressions and keywords to the highlighter and assign each a name
- Use the
run
method to recieve a stream of start, end and text tokens to use in your program.
You can also very quickly add, remove and modify build syntax highlighting rules to adjust to your liking.
Example
Here's an example of a Rust syntax highlighter, using the termion crate.
use ;
use color;
const DEMO: &str = r#"/*
Multiline comments
Work great
*/
pub fn main() -> bool {
// Demonstrate syntax highlighting in Rust!
println!("Full Unicode Support: 你好!Pretty cool");
return true;
}
"#;
That will render this result:
Installation
Just add it to your Cargo.toml
:
[]
= "1"
License
MIT
license to ensure that you can use it in your project
you can check the LICENSE
file for more info