You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a major release with multiple breaking API changes, although upgrading shouldn't be too difficult. It fixes bugs and comes with some nice new features.
4
+
5
+
## Breaking changes and upgrading
6
+
7
+
- The `SyntaxSet` API has been revamped to use a builder and an arena of contexts. See [example usage](https://github.com/trishume/syntect/blob/51208d35a6d98c07468fbe044d5c6f37eb129205/examples/gendata.rs#L25-L28).
8
+
- Many functions now need to be passed the `SyntaxSet` that goes with the rest of their arguments because of this new arena.
9
+
- Filename added to `LoadingError::ParseSyntax`
10
+
- Many functions in the `html` module now take the `newlines` version of syntaxes.
11
+
- These methods have also been renamed, partially so that code that needs updating doesn't break without a compile error.
12
+
- The HTML they output also treats newlines slightly differently and I think more correctly but uglier when you look at the HTML.
-`html::highlighted_snippet_for_string -> html::highlighted_html_for_string`: also change to `newlines``SyntaxSet`
20
+
-`html::highlighted_snippet_for_file -> html::highlighted_html_for_file`: also change to `newlines``SyntaxSet`
21
+
-`html::styles_to_coloured_html -> html::styled_line_to_highlighted_html`: also change to `newlines``SyntaxSet`
22
+
-`html::start_coloured_html_snippet -> html::start_highlighted_html_snippet`: return type also changed
23
+
24
+
## Major changes and new features
25
+
26
+
- Use arena for contexts (#182#186#187#190#195): This makes the code cleaner, enables use of syntaxes from multiple threads, and prevents accidental misuse.
27
+
- This involves a new `SyntaxSetBuilder` API for constructing new `SyntaxSet`s
28
+
- See the revamped [parsyncat example](https://github.com/trishume/syntect/blob/51208d35a6d98c07468fbe044d5c6f37eb129205/examples/parsyncat.rs).
29
+
- Encourage use of newlines (#197#207#196): The `nonewlines` mode is often buggy so we made it easier to use the `newlines` mode.
30
+
- Added a `LinesWithEndings` utility for iterating over the lines of a string with `\n` characters.
31
+
- Reengineer the `html` module to use `newlines` syntaxes.
32
+
- Add helpers for modifying highlighted lines (#198): For use cases like highlighting a piece of text in a blog code snippet or debugger. This allows you to reach into the highlighted spans and add styles.
33
+
- Check out `split_at` and `modify_range` in the `util` module.
34
+
- New `ThemeSet::add_from_folder` function (#200): For modifying existing theme sets.
35
+
36
+
## Bug Fixes
37
+
38
+
- Improve nonewlines regex rewriting: #212#211
39
+
- Reengineer theme application to match Sublime: #209
40
+
- Also mark contexts referenced by name as "no prototype" (same as ST): #180
41
+
- keep with_prototype when switching contexts with `set`: #177#166
42
+
- Fix unused import warning: #174
43
+
- Ignore trailing dots in selectors: #173
44
+
- Fix `embed` to not include prototypes: #172#160
45
+
46
+
## Upgraded dependencies
47
+
48
+
- plist: `0.2 -> 0.3`
49
+
- regex: `0.2 -> 1.0`
50
+
- onig: `3.2.1 -> 4.1`
51
+
52
+
# Prior versions
53
+
54
+
See the Github release notes: <https://github.com/trishume/syntect/releases>
Copy file name to clipboardexpand all lines: Readme.md
+46-37
Original file line number
Diff line number
Diff line change
@@ -7,27 +7,23 @@
7
7
8
8
`syntect` is a syntax highlighting library for Rust that uses [Sublime Text syntax definitions](http://www.sublimetext.com/docs/3/syntax.html#include-syntax). It aims to be a good solution for any Rust project that needs syntax highlighting, including deep integration with text editors written in Rust. It's used in production by at least two companies, and by [many open source projects](#projects-using-syntect).
9
9
10
-
If you are writing a text editor (or something else needing highlighting) in Rust and this library doesn't fit your needs, I consider that a bug and you should file an issue or email me.
10
+
If you are writing a text editor (or something else needing highlighting) in Rust and this library doesn't fit your needs, I consider that a bug and you should file an issue or email me. I consider this project mostly complete, I still maintain it and review PRs, but it's not under heavy development.
11
11
12
-
**Note:** I consider this project "done" in the sense that it works quite well for its intended purpose, accomplishes the major goals I had, and I'm unlikely to make any sweeping changes.
13
-
I won't be committing much anymore because the marginal return on additional work isn't very high. Rest assured if you submit PRs I will review them and likely merge promptly.
14
-
I'll also quite possibly still fix issues and definitely offer advice and knowledge on how the library works. Basically I'll be maintaining the library but not developing it further.
15
-
I've spent months working on, tweaking, optimizing, documenting and testing this library. If you still have any reasons you don't think it fits your needs, file an issue or email me.
12
+
## Important Links
16
13
17
-
### Rendered docs: <https://docs.rs/syntect>
14
+
- API docs with examples: <https://docs.rs/syntect>
15
+
-[Changelogs and upgrade notes for past releases](https://github.com/trishume/syntect/releases)
18
16
19
17
## Getting Started
20
18
21
19
`syntect` is [available on crates.io](https://crates.io/crates/syntect). You can install it by adding this line to your `Cargo.toml`:
22
20
23
21
```toml
24
-
syntect = "2.1"
22
+
syntect = "3.0"
25
23
```
26
24
27
25
After that take a look at the [documentation](https://docs.rs/syntect) and the [examples](https://github.com/trishume/syntect/tree/master/examples).
28
26
29
-
**Note:** with stable Rust on Linux there is a possibility you might have to add `./target/debug/build/onig_sys-*/out/lib/` to your `LD_LIBRARY_PATH` environment variable. I dunno why or even if this happens on other places than Travis, but see `travis.yml` for what it does to make it work. Do this if you see `libonig.so: cannot open shared object file`.
30
-
31
27
If you've cloned this repository, be sure to run
32
28
33
29
```
@@ -36,17 +32,10 @@ git submodule update --init
36
32
37
33
to fetch all the required dependencies for running the tests.
38
34
39
-
### Feature Flags
40
-
41
-
Syntect makes heavy use of [cargo features](http://doc.crates.io/manifest.html#the-features-section), to support users who require only a subset of functionality. In particular, it is possible to use the highlighting component of syntect without the parser (for instance when hand-rolling a higher performance parser for a particular language), by adding `default-features = false` to the syntect entry in your `Cargo.toml`.
42
-
43
-
For more information on available features, see the features section in `Cargo.toml`.
44
-
45
35
## Features/Goals
46
36
47
37
-[x] Work with many languages (accomplished through using existing grammar formats)
48
-
-[x] Highlight super quickly, faster than every editor except Sublime Text 3
49
-
-[x] Load up quickly, currently in around 23ms but could potentially be even faster.
38
+
-[x] Highlight super quickly, faster than nearly all text editors
50
39
-[x] Include easy to use API for basic cases
51
40
-[x] API allows use in fancy text editors with piece tables and incremental re-highlighting and the like.
52
41
-[x] Expose internals of the parsing process so text editors can do things like cache parse states and use semantic info for code intelligence
@@ -55,6 +44,7 @@ For more information on available features, see the features section in `Cargo.t
55
44
-[x] Well documented, I've tried to add a useful documentation comment to everything that isn't utterly self explanatory.
56
45
-[x] Built-in output to coloured HTML `<pre>` tags or 24-bit colour ANSI terminal escape sequences.
57
46
-[x] Nearly complete compatibility with Sublime Text 3, including lots of edge cases. Passes nearly all of Sublime's syntax tests, see [issue 59](https://github.com/trishume/syntect/issues/59).
47
+
-[x] Load up quickly, currently in around 23ms but could potentially be even faster.
58
48
59
49
## Screenshots
60
50
@@ -65,22 +55,29 @@ There's currently an example program called `syncat` that prints one of the sour
-[x] Sketch out representation of a Sublime Text syntax
71
-
-[x] Parse `.sublime-syntax` files into the representation.
72
-
-[x] Write an interpreter for the `.sublime-syntax` state machine that highlights an incoming iterator of file lines into an iterator of scope-annotated text.
73
-
-[x] Parse TextMate/Sublime Text theme files
74
-
-[x] Highlight a scope-annotated iterator into a colour-annotated iterator for display.
75
-
-[x] Ability to dump loaded packages as binary file and load them with lazy regex compilation for fast start up times.
76
-
-[x] Bundle dumped default syntaxes into the library binary so library users don't need an assets folder with Sublime Text packages.
77
-
-[x] Add nice API wrappers for simple use cases. The base APIs are designed for deep high performance integration with arbitrary text editor data structures.
78
-
-[x] Document the API better and make things private that don't need to be public
79
-
-[x] Detect file syntax based on first line
80
-
-[x] Make it really fast (mosty two hot-paths need caching, same places Textmate 2 caches)
81
-
-[ ] Make syncat a better demo, and maybe more demo programs
82
-
-[ ] Add sRGB colour correction (not sure if this is necessary, could be the job of the text editor)
83
-
-[ ] Add C bindings so it can be used as a C library from other languages.
58
+
## Example Code
59
+
60
+
Prints highlighted lines of a string to the terminal. See the [easy](https://docs.rs/syntect/latest/syntect/easy/index.html) and [html](https://docs.rs/syntect/latest/syntect/html/index.html) module docs for more basic use case examples.
@@ -110,7 +107,13 @@ All measurements were taken on a mid 2012 15" retina Macbook Pro.
110
107
-~1.9ms to parse and highlight the 30 line 791 character `testdata/highlight_test.erb` file. This works out to around 16,000 lines/second or 422 kilobytes/second.
111
108
-~250ms end to end for `syncat` to start, load the definitions, highlight the test file and shut down. This is mostly spent loading.
112
109
113
-
### Caching
110
+
## Feature Flags
111
+
112
+
Syntect makes heavy use of [cargo features](http://doc.crates.io/manifest.html#the-features-section), to support users who require only a subset of functionality. In particular, it is possible to use the highlighting component of syntect without the parser (for instance when hand-rolling a higher performance parser for a particular language), by adding `default-features = false` to the syntect entry in your `Cargo.toml`.
113
+
114
+
For more information on available features, see the features section in `Cargo.toml`.
115
+
116
+
## Caching
114
117
115
118
Because `syntect`'s API exposes internal cacheable data structures, there is a caching strategy that text editors can use that allows the text on screen to be re-rendered instantaneously regardless of the file size when a change is made after the initial highlight.
116
119
@@ -120,11 +123,15 @@ This way from the time the edit happens to the time the new colouring gets rende
120
123
121
124
Any time the file is changed the latest cached state is found, the cache is cleared after that point, and a background job is started. Any already running jobs are stopped because they would be working on old state. This way you can just have one thread dedicated to highlighting that is always doing the most up-to-date work, or sleeping.
122
125
123
-
### Parallelizing
126
+
## Parallelizing
127
+
128
+
Since 3.0, `syntect` can be used to do parsing/highlighting in parallel. `SyntaxSet` is both `Send` and `Sync` and so can easily be used from multiple threads. It is also `Clone`, which means you can construct a syntax set and then clone it to use for other threads if you prefer.
124
129
125
-
`syntect` doesn't provide any built-in facilities to enable highlighting in parallel. Some of the important data structures are not thread-safe, either, most notably `SyntaxSet`. However, if you find yourself in need of highlighting lots of files in parallel, the recommendation is to use some sort of thread pooling, along with the `thread_local!` macro from `libstd`, so that each thread that needs, say, a `SyntaxSet`, will have one, while minimizing the amount of them that need to be initialized. For adding parallelism to a previously single-threaded program, the recommended thread pooling is [`rayon`](https://github.com/nikomatsakis/rayon). However, if you're working in an already-threaded context where there might be more threads than you want (such as writing a handler for an Iron request), the recommendation is to force all highlighting to be done within a fixed-size thread pool using [`rust-scoped-pool`](https://github.com/reem/rust-scoped-pool). An example of the former is in `examples/parsyncat.rs`.
130
+
Compared to older versions, there's nothing preventing the serialization of a `SyntaxSet` either. So you can directly deserialize a fully linked `SyntaxSet` and start using it for parsing/highlighting. Before, it was always necessary to do linking first.
126
131
127
-
See [#20](https://github.com/trishume/syntect/issues/20) and [#78](https://github.com/trishume/syntect/pull/78) for more detail and discussion about why `syntect` doesn't provide parallelism by default.
132
+
It is worth mentioning that regex compilation is done lazily only when the regexes are actually needed. Once a regex has been compiled, the compiled version is used for all threads after that. Note that this is done using interior mutability, so if multiple threads happen to encounter the same uncompiled regex at the same time, compiling might happen multiple times. After that, one of the compiled regexes will be used. When a `SyntaxSet` is cloned, the regexes in the cloned set will need to be recompiled currently.
133
+
134
+
For adding parallelism to a previously single-threaded program, the recommended thread pooling is [`rayon`](https://github.com/nikomatsakis/rayon). However, if you're working in an already-threaded context where there might be more threads than you want (such as writing a handler for an Iron request), the recommendation is to force all highlighting to be done within a fixed-size thread pool using [`rust-scoped-pool`](https://github.com/reem/rust-scoped-pool). An example of the former is in `examples/parsyncat.rs`.
128
135
129
136
## Examples Available
130
137
@@ -173,4 +180,6 @@ Below is a list of projects using Syntect, in approximate order by how long they
173
180
174
181
## License and Acknowledgements
175
182
183
+
Thanks to [Robin Stocker](https://github.com/robinst) and also [Keith Hall](https://github.com/keith-hall) for making awesome substantial contributions of the most important impressive improvements `syntect` has had post-`v1.0`! They deserve lots of credit for where `syntect` is today.
184
+
176
185
Thanks to [Textmate 2](https://github.com/textmate/textmate) and @defuz's [sublimate](https://github.com/defuz/sublimate) for the existing open source code I used as inspiration and in the case of sublimate's `tmTheme` loader, copy-pasted. All code (including defuz's sublimate code) is released under the MIT license.
0 commit comments