This is the beginning of a syntax highlighting UITextView
for iOS. Currently it only knows about Obj-C. Previously Chromatism used a combination of CoreText
and UITableView
for performance, but luckily that is not needed anymore.
Chromatism is currently unstable, changing quickly and without test-coverage.
MIT, see LICENSE.txt. If you develop Chromatism further, sharing your improvements are encouraged.
- Drag and drop
Chromatism.xcodeproj
to your project. - Add
Chromatism
as a target dependency and link tolibChromatism.a
- Make sure you have the
-ObjC
flag on theOther Linker Flags
build setting. - Add
"$(BUILT_PRODUCTS_DIR)/../../Headers"
to theHeader Search Paths
build setting.
JLTextView
is a textView with a syntaxTokenixer property to aJLTokenizer
JLTokenizer
is the work horse of Chromatism. It uses scopes and tokenPatterns to appropriately tokenize a textStorage or a string. It is a delegate ofNSTextStorage
andUITextView
.JLScope
has aNSMutableIndexSet
-property that corresponds to ranges in the textStorage. Scopes can be arranged in a hierarchy. A scope's children is stored in thesubscopes
property, and a scopes parent is simply called itsscope
. A scope can be executed via the-perform
-method. The method causes subscopes to perform cascadingly.JLTokenPattern
is a subclass ofJLScope
. It has a regex-pattern that in-perform
searches through the ranges of its parent scope.
Scopes and patters can ensure that regex patterns search in the right place. To understand how they work, it is helpful to know what happens in the -perform
method.
- A scope may contain ranges before it's performed. When it's performed, the scope's set is intersected with the parent scope set. A scope can never contain more indexes that its parent scope.
- The scope calls perform on its subscopes.
- The scope ensures that its siblings don't search where the scope have found things.
For more detail, see the -perform
-implementation on JLScope
and JLTokenPattern
.