GithubHelp home page GithubHelp logo

cyrilbarthelet / chromatism Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anviking/chromatism

2.0 2.0 0.0 1.16 MB

Obj-C Syntax Highlighting for iOS

License: MIT License

Objective-C 100.00%

chromatism's Introduction

Chromatism

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.

License

MIT, see LICENSE.txt. If you develop Chromatism further, sharing your improvements are encouraged.

How to add Chromatism to your application:

  1. Drag and drop Chromatism.xcodeproj to your project.
  2. Add Chromatism as a target dependency and link to libChromatism.a
  3. Make sure you have the -ObjC flag on the Other Linker Flags build setting.
  4. Add "$(BUILT_PRODUCTS_DIR)/../../Headers" to the Header Search Paths build setting.

Classes

  • JLTextView is a textView with a syntaxTokenixer property to a JLTokenizer
  • JLTokenizer is the work horse of Chromatism. It uses scopes and tokenPatterns to appropriately tokenize a textStorage or a string. It is a delegate of NSTextStorage and UITextView.
  • JLScope has a NSMutableIndexSet-property that corresponds to ranges in the textStorage. Scopes can be arranged in a hierarchy. A scope's children is stored in the subscopes property, and a scopes parent is simply called its scope. A scope can be executed via the -perform-method. The method causes subscopes to perform cascadingly.
  • JLTokenPattern is a subclass of JLScope. It has a regex-pattern that in -perform searches through the ranges of its parent scope.

Scopes and Patterns

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.

  1. 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.
  2. The scope calls perform on its subscopes.
  3. 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.

chromatism's People

Contributors

anviking avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.