I'm currently trying to build a compiler for a high level language.
curlpipe / synoptic Goto Github PK
View Code? Open in Web Editor NEWA simple, low-level, syntax highlighting library with unicode support
License: MIT License
A simple, low-level, syntax highlighting library with unicode support
License: MIT License
Thanks for the library, it saves so much time getting started! I am using your library in a way you did not plan for, but allow.
I am using FLTK, and the backend is a buffer full of single characters.
fn example() {
// test
}
Here is the FLTK version of the github highlighting above MOL
BBACCCCCCCAAAA
AAAAEEEEEEE
A
I currently use something like this:
let mut output:string = String::new();
//snip
for token in row {
match token {
Token::Start(kind) => {
highlighting = true;
match kind.as_str() {
"keywords" => character = "B".to_string(),
"comments" => character = "E".to_string(),
//etc..
_=> character = "A".to_string(),
}
output.push_str(character.as_str());// <-- here?
}
Token::Text(txt) => {
let len = txt.chars().count();
let ch = character.as_str();
// `string.len()` == `text.len()`
let string = ch.repeat(len);
output.push_str(string.as_str());
},
Token::End(_) => {
//output.push_str(character.as_str()); // <-- OR here?
highlighting = false;
character = "A".to_string();
},
}
}
Just not sure how to get it to be the correct length of the styling.
non-highlighted characters creep in, but I also end up with an incorrect len()
if I do not push a some character to the output string.
That said, your library is quite intuitive and I really enjoy the thought you put into making it flexible!
In line 45 of your code example, it should be changed to Token::Start(kind) => match kind.as_str() {
. The change is from match *kind
to kind.as_str()
.
Include pre-defined highlighters.
I could potentially look at a concurrent highlighting solution, where single line tokens, multiline tokens and bounded tokens are all calculated in parallel, hopefully that would speed up performance significantly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.