TextMate-style syntax highlighting

Overview

SyntaxKit

Version Carthage compatible CocoaPods compatible

SyntaxKit makes TextMate-style syntax highlighting easy. It works on iOS, watchOS, and OS X.

SyntaxKit was abstracted from Whiskey.

Building

SyntaxKit is written in Swift 2 so Xcode 7 is required. There aren't any dependencies besides system frameworks.

Installation

Carthage is the recommended way to install SyntaxKit. Add the following to your Cartfile:

github "soffes/SyntaxKit"

You can also install with CocoaPods:

pod 'SyntaxKit'

For manual installation, I recommend adding the project as a subproject to your project or workspace and adding the appropriate framework as a target dependency.

Usage

SyntaxKit uses tmLanguage and tmTheme files to highlight source code. None are provided with SyntaxKit. Thankfully, there are tons available at TextMate's GitHub org.

Basic Parsing

Once you have a language, you can get started:

import SyntaxKit

let path = "path to your .tmLanguage file"
let plist = NSDictionary(contentsOfFile: path)! as [NSObject: AnyObject]
let yaml = Language(dictionary: plist)

let parser = Parser(language: yaml)

Parser is a very simple class that just calls a block when it finds something the language file knows about. Let's print all of the elements in this string:

let input = "title: \"Hello World\"\n"
parser.parse(input) { scope, range in
    print("\(scope) - \(range)")
}

scope is the name of an element. This is something like "string" or "constant.numeric". range is an NSRange struct representing where the scope falls in the input string.

Working with Attributed Strings

SyntaxKit also comes with AttributedParser. This is a simple subclass of Parser that knows how to work with themes.

let tomorrow = Theme(dictionary: themePlist)
let attributedParser = AttributedParser(language: yaml, theme: tomorrow)

attributedParser.parse(input) { scope, range, attributes in
    print("\(scope) - \(range) - \(attributes)")
}

Notice that attributes is the third paramenter to the block now. This is a dictionary of attributes you can give to NSAttributedString. Other values may be included here that don't work with NSAttributedString. You can do your own inspection and do something custom if you want.

AttributedParser includes a convenience method for turning a String of source code into an NSAttributedString:

let attributedString = attributedParser.attributedStringForString(input)

Easy as that. This method takes an optional baseAttributes parameter to customize how the string is created. This is great if you want to specify a font, etc.

Custom Parsers

If you want to build your own parser (for example, to generate HTML) you can subclass whichever one meets your needs. Go wild.

Enjoy.

Comments
  • Wrong syntax highlighting for latex?

    Wrong syntax highlighting for latex?

    It seems that there is an issue with this library.

    For the text

    \begin{document}
    This is a test
    $test$
    \end{document}
    
    \begin{document}
    $x+y$
    \end{document}
    

    and the theme Rainbow_Dash, I get the colours capture d ecran 2016-12-27 a 00 42 05

    These are not (I guess) the correct colours.

    The .tmLanguage file that I use is given here.

    More precisely, here is the NSAttributedString I get:

    \documentclass{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.172549 0.364706 0.803922 1";
        caret = "#000000";
        fontStyle = bold;
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }{article}
    {
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }\begin{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 0.501961 0 1";
        caret = "#000000";
        fontStyle = bold;
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }{{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }document{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        fontStyle = italic;
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }}
    Ceci est mon test?
    $test$
    {
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }\end{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 0.501961 0 1";
        caret = "#000000";
        fontStyle = bold;
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }{{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }document{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        fontStyle = italic;
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }}{
        NSBackgroundColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 1 1 1 1";
        NSColor = "NSCustomColorSpace sRGB IEC61966-2.1 colorspace 0.301961 0.301961 0.301961 1";
        caret = "#000000";
        invisibles = "#BFBFBF";
        lineHighlight = "#00000012";
        selection = "#4D97FF54";
    }
    
    opened by colasbd 21
  • Negative length sometimes

    Negative length sometimes

    The following causes an exception because the length is negative.

    class A < B; def self.create(object = User)
    class Zebra; def inspect; "X#{2 + self.object_id}"
    
    module ABC::DEF
      include Comparable
    
      # @param test
      # @return [String] nothing
      def foo(test)
        Thread.new do |blockvar|
          ABC::DEF.reverse(:a_symbol, :'a symbol', :<=>, 'test')
        end.join
      end
    
      # A really really long line than goes on and on and on, continuing outside of the  bounds of the code box
    
      def [](index) self[index] end
      def ==(other) other == self end
    end
    
    anIdentifier = an_identifier
    Constant = 1
    render action: :new
    

    From nothingmagical/whiskey-issues#90.

    bug 
    opened by soffes 9
  • [NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds

    [NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds

    use AttributedParser for .m file

    @implementation Car
    
    - (int) getOdometerReading
    {
        SpecificCar *myCar = [[SpecificCar alloc] init];
        [myCar getOdometerReading];
        return 50000;
    }
    @end
    

    crashed with: *** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds

    The crash seems to be happening in Parser.swift

           /// Returns new location
        private func parse(string: String, inRange bounds: NSRange, callback: Callback) -> UInt {
            ...
              let endBounds = NSMakeRange(location, bounds.length - location - bounds.location) 
                      //when endBounds.length = -106  
    
    
    crash 
    opened by janyou 3
  • Update to Swift 4.1

    Update to Swift 4.1

    Updated to Swift 4.1. Compiles with no errors or warnings on Xcode 9.3 (9E145). All tests passing. In addition to source changes the project has been updated to recommended settings.

    I noticed the dependency on X.framework is missing from the podspec, but my podspec knowledge is a bit rusty so I did not try to fix this.

    opened by iosdevzone 2
  • Cannot invoke initializer for type 'Language'?

    Cannot invoke initializer for type 'Language'?

    Hello! I follow your readme but I got this:

    Cannot invoke initializer for type 'Language' with an argument list of type '(dictionary: [NSObject : AnyObject])'

    screen shot 2017-09-23 at 8 38 09

    opened by mrtungdev 2
  • Change how range is calculated to fix crash

    Change how range is calculated to fix crash

    This fixes the crash in #9 and #13. The existing method of calculating the range can result in negative ranges, which throws an exception. This can be reproduced with the test I added for parsing JavaScript. Though this fixes the crash, I can't tell if it's 100% correct, since I wasn't certain of the intention of the original code. I'm assuming we want to calculate the new endBounds as the remaining range after the beginRange, but let me know if that's incorrect.

    opened by zachwaugh 2
  • Replace 'nuts' with 'wild'

    Replace 'nuts' with 'wild'

    Hi @soffes,

    Thanks for the awesome library.

    I replaced the use of the word "nuts" in the Custom Parsers section of the README. The word "nuts" refers to people with mental or psychiatric disabilities or a fruit. I don't think you meant either.

    Let's make SyntaxKit an awesome library for everyone.

    💃 😸

    opened by noisypigeon 1
  • Proper use is not clear

    Proper use is not clear

    The lack of a wiki makes the use of this potential great framework hard to use.

    For example I can't figure out how to set the view background colour to the one defined in the theme and the provided example was not enough to clarify.

    question 
    opened by Reonarudo 1
  • Xcode7b6

    Xcode7b6

    This PR would also apply the changes I'm asking to be pulled in for https://github.com/soffes/SyntaxKit/pull/6, because I'm lazy.

    Also, this PR relies on https://github.com/soffes/X/pull/5 being merged in to X.

    opened by younata 1
  • HTML tmLanguage causes crash

    HTML tmLanguage causes crash

    The HTML tmLanguage file causes SyntaxKit to crash on "<h1 title='Hello Title'>Hello World!</h1>\n" .

    My code:

    let path = NSBundle.mainBundle().pathForResource("HTML", ofType: "tmLanguage")!
    let plist = NSDictionary(contentsOfFile: path)! as [NSObject: AnyObject]
    let html = Language(dictionary: plist)!
    let parser = Parser(language: html)
    
    let input = "<h1 title='Hello Title'>Hello World!</h1>\n"
    
    parser.parse(input) { scope, range in
        print("\(scope) - \(range)")
    }
    

    I used the HTML plist from TextMate's html.tmbundle.

    It managed to output:

    meta.tag.block.any.html - (0,24)
    punctuation.definition.tag.begin.html - (0,1)
    entity.name.tag.block.any.html - (1,2)
    punctuation.definition.tag.end.html - (23,1)
    

    And then crashed with:

    2015-06-25 20:37:35.479 MyOSXApp[2481:41424] An uncaught exception was raised
    2015-06-25 20:37:35.479 MyOSXApp[2481:41424] *** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds
    2015-06-25 20:37:35.479 MyOSXApp[2481:41424] (
        0   CoreFoundation                      0x00007fff9411f03c __exceptionPreprocess + 172
        1   libobjc.A.dylib                     0x00007fff8cbc876e objc_exception_throw + 43
        2   CoreFoundation                      0x00007fff9411eeed +[NSException raise:format:] + 205
        3   Foundation                          0x00007fff96a1951e -[NSRegularExpression(NSMatching) enumerateMatchesInString:options:range:usingBlock:] + 365
        4   Foundation                          0x00007fff96a19398 -[NSRegularExpression(NSMatching) matchesInString:options:range:] + 162
        5   SyntaxKit                           0x00000001005d75c2 _TFC9SyntaxKit6ParserP33_3B8D38F1D3A332B2216177DC3565447D5parsefS0_FTSS7inRangeVSC8_NSRange5scopeGSqSS_10expressionSS8capturesGSqVS_17CaptureCollection__GSqVS_9ResultSet_ + 898
        6   SyntaxKit                           0x00000001005d6c13 _TFC9SyntaxKit6ParserP33_3B8D38F1D3A332B2216177DC3565447D5parsefS0_FTSS7inRangeVSC8_NSRange8callbackFT5scopeSS5rangeS1__T__Su + 3091
        7   SyntaxKit                           0x00000001005d5eeb _TFC9SyntaxKit6Parser5parsefS0_FTSS5matchFT5scopeSS5rangeVSC8_NSRange_T__T_ + 715
        8   MyOSXApp                            0x000000010003885e _TFC12MyOSXApp16WindowController13windowDidLoadfS0_FT_T_ + 2414
        9   MyOSXApp                            0x0000000100038992 _TToFC12MyOSXApp16WindowController13windowDidLoadfS0_FT_T_ + 34
        10  AppKit                              0x00007fff8d6d5947 -[NSWindowController _windowDidLoad] + 586
        11  CoreFoundation                      0x00007fff9402bbdf -[NSSet makeObjectsPerformSelector:] + 223
        12  AppKit                              0x00007fff8d53511b -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1166
        13  AppKit                              0x00007fff8d70fa0e -[NSNib _instantiateNibWithExternalNameTable:options:] + 677
        14  AppKit                              0x00007fff8d70f65e -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143
        15  AppKit                              0x00007fff8dc5955c -[NSStoryboard instantiateControllerWithIdentifier:] + 181
        16  AppKit                              0x00007fff8d50bf74 NSApplicationMain + 840
        17  MyOSXApp                            0x000000010000ac27 main + 87
        18  libdyld.dylib                       0x00007fff97c925c9 start + 1
    )
    2015-06-25 20:37:35.480 MyOSXApp[2481:41424] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x00007fff9411f03c __exceptionPreprocess + 172
        1   libobjc.A.dylib                     0x00007fff8cbc876e objc_exception_throw + 43
        2   CoreFoundation                      0x00007fff9411eeed +[NSException raise:format:] + 205
        3   Foundation                          0x00007fff96a1951e -[NSRegularExpression(NSMatching) enumerateMatchesInString:options:range:usingBlock:] + 365
        4   Foundation                          0x00007fff96a19398 -[NSRegularExpression(NSMatching) matchesInString:options:range:] + 162
        5   SyntaxKit                           0x00000001005d75c2 _TFC9SyntaxKit6ParserP33_3B8D38F1D3A332B2216177DC3565447D5parsefS0_FTSS7inRangeVSC8_NSRange5scopeGSqSS_10expressionSS8capturesGSqVS_17CaptureCollection__GSqVS_9ResultSet_ + 898
        6   SyntaxKit                           0x00000001005d6c13 _TFC9SyntaxKit6ParserP33_3B8D38F1D3A332B2216177DC3565447D5parsefS0_FTSS7inRangeVSC8_NSRange8callbackFT5scopeSS5rangeS1__T__Su + 3091
        7   SyntaxKit                           0x00000001005d5eeb _TFC9SyntaxKit6Parser5parsefS0_FTSS5matchFT5scopeSS5rangeVSC8_NSRange_T__T_ + 715
        8   MyOSXApp                            0x000000010003885e _TFC12MyOSXApp16WindowController13windowDidLoadfS0_FT_T_ + 2414
        9   MyOSXApp                            0x0000000100038992 _TToFC12MyOSXApp16WindowController13windowDidLoadfS0_FT_T_ + 34
        10  AppKit                              0x00007fff8d6d5947 -[NSWindowController _windowDidLoad] + 586
        11  CoreFoundation                      0x00007fff9402bbdf -[NSSet makeObjectsPerformSelector:] + 223
        12  AppKit                              0x00007fff8d53511b -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1166
        13  AppKit                              0x00007fff8d70fa0e -[NSNib _instantiateNibWithExternalNameTable:options:] + 677
        14  AppKit                              0x00007fff8d70f65e -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143
        15  AppKit                              0x00007fff8dc5955c -[NSStoryboard instantiateControllerWithIdentifier:] + 181
        16  AppKit                              0x00007fff8d50bf74 NSApplicationMain + 840
        17  MyOSXApp                            0x000000010000ac27 main + 87
        18  libdyld.dylib                       0x00007fff97c925c9 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb)
    

    The crash seems to be happening on line 103 of Parser.swift

    Parsing worked fine when I tested SyntaxKit with the YAML plist included in the SyntaxKit fixtures.

    This is on OS X 10.10.3 with Xcode 7 beta 2

    opened by matiaskorhonen 0
  • Update README to reflect dependencies

    Update README to reflect dependencies

    A clean clone of the repo won't build, since it depends on https://github.com/soffes/x.

    I'm not really a Carthage person, so I can't speak to whether the actual correct solution is to check in dependencies or not, but for now updating the README seems like a sensible quick fix.

    opened by lazerwalker 1
  • Slow parsing

    Slow parsing

    I'm using this .tmLanguage (it is latex).

    The parsing of the following text is very long (more than 1 minute). Is there a problem? Thanks

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%
    %%   This is my macro files
    %%
    %%   Feel free to use it or to delete it
    %%
    %%   Anyway, this is where you put your own macros
    %%   (in addition to these ones
    %%    or in replacement as you want)
    %%
    %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%    Fonctions, notations usuelles   %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    \newcommand{\CoeffBinom}[2]{\binom{#1}{#2}}
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%    Ensembles classiques        %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \def\N{\mathbb{N}}
    \def\Z{\mathbb{Z}}
    \def\Q{\mathbb{Q}}
    \def\R{\mathbb{R}}
    \def\C{\mathbb{C}}
    \def\U{\mathbb{U}}
    \def\K{\mathbb{K}}
    \def\vide{\varnothing}
    \def\Premiers{\mathcal{P}}
    
    
    
    
    
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%    Notations pour les probas   %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    \def\P{P} %\def\P{\mathbb{P}}
    \newcommand{\Pcond}[2]{\P_{#1}\left ( #2\right )}
    \def\E{\mathbb{E}}
    \def\V{\mathbb{V}}
    \newcommand{\covar}[2]{\mathrm{cov}\left (#1, #2 \right)}
    \newcommand{\Correlation}[2]{\mathrm{cor}\left (#1, #2 \right )}
    
    \newcommand{\Bernoulli}[1]{\mathcal{B}(#1)}
    \newcommand{\Binomiale}[2]{\mathcal{B}(#1, #2)}
    \newcommand{\Poisson}[1]{\mathcal{P}(#1)}
    \newcommand{\Geometrique}[1]{\mathcal{G}(#1)}
    \newcommand{\Uniforme}[1]{\mathcal{U}(#1)}
    \newcommand{\Exponentielle}[1]{\mathcal{E}(#1)}
    \newcommand{\Normale}[2]{\mathscr{N}(#1, #2)}
    
    \newcommand{\loiSuit}{\rightsquigarrow}
    \def\suitVA{\hookrightarrow}
    
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Matrices   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%% Espaces vectoriels %%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \def\GLcore{\mathrm{GL}}
    \def\SLcore{\mathrm{SL}}
    \def\SOcore{\mathrm{SO}}
    
    
    % cf. http://stackoverflow.com/a/1812314/1670830
    \DeclareDocumentCommand\GL{ m g }{%
    {\IfNoValueTF {#2} {\GLcore\left (#1 \right )} {\GLcore_{#1}\left (#2 \right )}
    }%
    }
    
    \DeclareDocumentCommand\SL{ m g }{%
    {\IfNoValueTF {#2} {\SLcore\left (#1 \right )} {\SLcore_{#1}\left (#2 \right )}
    }%
    }
    
    \DeclareDocumentCommand\SO{ m g }{%
    {\IfNoValueTF {#2} {\SOcore\left (#1 \right )} {\SOcore_{#1}\left (#2 \right )}
    }%
    }
    
    \newcommand{\Mat}[2]{\mathrm{M}_{#1}\left ( #2\right)}
    \newcommand{\MatRectangle}[3]{\mathrm{M}_{#1\, #2}\left ( #3\right)}
    \DeclareMathOperator{\tr}{tr}
    
    %\newcommand{\AppliLin}[2]{\mathscr{L}\left (#1, #2\right)}
    %\newcommand{\Endo}[1]{\mathscr{L}\left (#1\right)}
    \newcommand{\AppliLin}[2]{\mathrm{L}\left (#1, #2\right)}
    \newcommand{\Endo}[1]{\mathrm{L}\left (#1\right)}
    
    
    \newcommand{\Orth}[1]{\mathrm{O}\left (#1\right)}
    \newcommand{\MatOrth}[1]{\mathrm{O}_{#1}\left (\R\right)}
    
    \newcommand{\MatSym}[1]{\mathrm{S}_{#1}(\R)}
    \newcommand{\MatSymPos}[1]{\mathrm{S}_{#1}^+(\R)}
    \newcommand{\MatSymDefPos}[1]{\mathrm{S}_{#1}^{++}(\R)}
    
    
    %% old way
    %%\newcommand{\Transposee}[1]{\prescript{\mathrm t}{}{#1}}
    \newcommand{\Transposee}[1]{\transp{#1}}
    \newcommand{\TransposeeParenth}[1]{\transp{\left (#1\right )}}
    \newcommand*{\transp}[2][-3mu]{\ensuremath{\mskip1mu\prescript{\smash{\mathrm t\mkern#1}}{}{\mathstrut#2}}}%
    
    %% new way
    \newcommand{\TransposeeNew}[1]{\transpNew{#1}}
    \newcommand{\TransposeeNewParenth}[1]{\transpNew{\left (#1\right )}}
    \newcommand*{\transpNew}[1]{{#1}^\mathsf{T}}%
    
    
    \newcommand{\MatApplLin}[2]{\mathrm{Mat}_{#1}\left ( #2\right)}
    
    \DeclareMathOperator{\Spec}{Sp}
    
    
    
    \def\Id{\mathrm{Id}}
    
    \DeclareMathOperator{\Vect}{Vect}
    
    \DeclareMathOperator{\Matt}{Mat}
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Guillemets   %%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%     Accolades   %%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\guillemets}[1]{\enquote{#1}}
    
    \newcommand{\accolades}[1]{\left \{#1\right \}}
    \newcommand{\accoladesB}[1]{\big \{#1\big \}}
    \newcommand{\accoladesBB}[1]{\Big \{#1\Big \}}
    \newcommand{\accoladesBBB}[1]{\bigg \{#1\bigg \}}
    \newcommand{\accoladesBBBB}[1]{\Bigg \{#1\Bigg \}}
    
    \newcommand{\crochets}[1]{\left [#1\right ]}
    \newcommand{\crochetsB}[1]{\big [#1\big ]}
    \newcommand{\crochetsBB}[1]{\Big [#1\Big ]}
    \newcommand{\crochetsBBB}[1]{\bigg [#1\bigg ]}
    
    \newcommand{\crochetsOuv}[1]{\left ]#1\right [}
    \newcommand{\crochetsOuvB}[1]{\big ]#1\big [}
    \newcommand{\crochetsOuvBB}[1]{\Big ]#1\Big [}
    \newcommand{\crochetsOuvBBB}[1]{\bigg ]#1\bigg [}
    
    \def\tq{\mathrel{}\middle|\mathrel{}}
    \def\tqN{\mathrel{}|\mathrel{}}
    \def\tqB{\mathrel{}\big|\mathrel{}}
    \def\tqBB{\mathrel{}\Big|\mathrel{}}
    \def\tqBBB{\mathrel{}\bigg|\mathrel{}}
    
    \newcommand{\parenth}[1]{\left (#1\right )}
    \newcommand{\parenthB}[1]{\big (#1\big )}
    \newcommand{\parenthBB}[1]{\Big (#1\Big )}
    \newcommand{\parenthBBB}[1]{\bigg (#1\bigg )}
    
    \newcommand{\accoladesForAnd}[2]{\left \{\begin{array}{ll}#1\\[1mm]#2\end{array}\right.}
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%    Produit scalaire   %%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\prodScal}[2]{\left(#1\,\middle\vert\,#2\right)}
    \newcommand{\prodScalB}[2]{\big(#1\,\big\vert\,#2\big)}
    \newcommand{\prodScalBB}[2]{\Big(#1\,\Big\vert\,#2\Big)}
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%    Intervalles   %%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\intervalle}[2]{\left [#1, #2 \right ]}
    \newcommand{\intervalleOF}[2]{\left ]#1, #2 \right ]}
    \newcommand{\intervalleFO}[2]{\left [#1, #2 \right [}
    \newcommand{\intervalleN}[2]{\left \llbracket #1, #2 \right \rrbracket}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%   Mon propre style de listes   %%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %
    % ex : \begin{myItemize}[2mm] \myItem Bonjour \myItem Hello \end{myItemize}
    %
    
    
    \usepackage{xifthen}% provides \isempty test
    
    \newcommand{\optarg}[1][]{%
    \ifthenelse{\isempty{#1}}%
    {}% if #1 is empty
    {(((#1)))}% if #1 is not empty
    }
    
    \newenvironment{myItemize}[1][]
    {%
    \begin{itemize}%
    \ifthenelse{\isempty{#1}}%
    {}% if #1 is empty
    {\setlength{\itemsep}{#1}}% if #1 is not empty
    }
    {%
    \end{itemize}%
    }
    
    
    
    \def\myItem{\item[•]}
    \def\myItemLong{\item[---]}
    \def\myItemShort{\item[--]}
    
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%    Valeur absolue        %%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\va}[1]{\left | #1 \right |}
    \newcommand{\vaB}[1]{\big | #1 \big |}
    \newcommand{\vaBB}[1]{\Big | #1 \Big |}
    \newcommand{\vaBBB}[1]{\bigg | #1 \bigg |}
    
    \newcommand{\norm}[1]{\left \| #1 \right \|}
    \newcommand{\normB}[1]{\big \| #1 \big \|}
    \newcommand{\normBB}[1]{\Big \| #1 \Big \|}
    \newcommand{\normBBB}[1]{\bigg \| #1 \bigg \|}
    
    \newcommand{\normetriple}[1]{\left | \! \left | \! \left |  #1 \right | \! \right | \! \right |}
    \newcommand{\normetripleB}[1]{\big | \! \big | \! \big |  #1 \big | \! \big | \! \big |}
    \newcommand{\normetripleBB}[1]{\Big | \! \Big| \! \Big |  #1 \Big | \! \Big | \! \Big |}
    \newcommand{\normetripleBBB}[1]{\bigg | \! \bigg | \! \bigg |  #1 \bigg | \! \bigg | \! \bigg |}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%    Le d de dx dans les intégrales    %%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \renewcommand{\d}[1]{\ensuremath{\operatorname{d}\!{#1}}}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%    Modulo        %%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\modd}[1]{\ (#1)}
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%% Petits mots français qu'on trouve dans les formules (ou pas)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    \newcommand{\ie}{\emph{ie} }
    \newcommand{\et}{\text{ et }}
    \newcommand{\donc}{\text{ donc }}
    \newcommand{\ou}{\text{ ou }}
    \newcommand{\cf}{\emph{cf.} }
    
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%    Quantificateurs       %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \def\fa{\forall}
    \def\xt{\exists}
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%% Raccourcis et petites commandes  %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \def\longto{\mathop{\longrightarrow}}
    \def\impl{\Longrightarrow}
    \def\implInverse{\Longleftarrow}
    \def\ssi{\iff}
    \def\ssivert{\Updownarrow}
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%% Modification de \Im (et ker)  %%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \renewcommand{\Im}{\mathrm{Im}}
    \newcommand{\im}{\mathrm{Im}}
    \newcommand{\Ker}{\mathrm{Ker}}
    \renewcommand{\ker}{\mathrm{Ker}}
    \newcommand{\rg}{\mathrm{rg}}
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%    Compléments xy-pic       %%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%%% Pour centrer les diagrammes et autres
    %
    % ex : \boite{<le diagramme>}
    %
    \newlength\longueurdelaboite
    \newcommand{\boite}[1]
    {
    \settowidth{\longueurdelaboite}{#1}
    \begin{minipage}{\longueurdelaboite}
    #1
    \end{minipage}
    }
    
    
    
    %%%%%%% Pour écrire des fonctions
    %
    % ex : \fonction{\R}{\R}{x}{x^2}
    %
    \newcommand{\fonction}[4]{
    \begin{tabular}{r@{~}c@{~}l}
    $#1$&$\longrightarrow$&$#2$ \\
    $#3$&$\longmapsto$&$#4$ \\
    \end{tabular}}
    
    
    
    %%%%%%% Pour écrire des fonctions bis
    %
    % ex : \fonction{\R}{\R}{x}{x^2}
    %
    \makeatother
    \newlength\longueurdudiagramme
    \newcommand{\fonctionb}[4]
    {%
    \settowidth{\longueurdudiagramme}
    {%
    $\xymatrix@R=0mm{
    #1 \ar[r] & #2 \\
    #3 \ar@{|->}[r] & #4}$
    }
    \begin{minipage}{\longueurdudiagramme}
    $\xymatrix@R=0mm{
    #1 \ar[r] & #2 \\
    #3 \ar@{|->}[r] & #4}$
    \end{minipage}
    }
    \makeatletter
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Quotients   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%%% Une commande pour les gros quotients
    %
    %  ancienne commande
    %%%%\newcommand{\quotient}[2]{\raisebox{4pt}{$#1$} \Big/ \raisebox{-4pt}{$#2$}}
    %
    %
    % ex : \quotient{Z}{nZ}
    %
    \newcommand{\quotient}[2]{\left. \raisebox{.2em}{$#1$}\middle/\raisebox{-.2em}{$#2$}\right.}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Canonical matrixes   %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %
    %
    % example
    % \canonicalmatrix{2\text{-ième ligne}}{3\text{-ième colonne}}{A}
    %
    %
    
    \NewDocumentCommand{\canonicalmatrix}{mmm}{%
    \begin{array}{@{}c@{}}
    \vphantom{
    \begin{array}{@{}c@{}}\text{$#2$}\\\downarrow\end{array}
    }
    \\
    \hphantom{#3={}\enspace
    }
    \begin{pmatrix}
    & & \smash[t]{
    \begin{array}[b]{@{}c@{}}
    \makebox[0pt]{$#2$}\\
    \downarrow\\[-.5ex]
    \vdots
    \end{array}
    }
    \\
    & & 0
    \\
    \llap{$#3={}$\quad}
    \cdots & 0 & 1 & 0 & \cdots\rlap{\quad$\leftarrow$ $#1$}
    \\
    & & 0
    \\
    & & \vdots
    \end{pmatrix}
    \end{array}%\hphantom{\text{\enspace$\leftarrow$ $#1$-#2 row}}
    }
    
    
    \newcommand{\vecteurCanonique}[1]{%
    \left (
    \begin{array}{c}
    \vdots \\
    0 \\
    1 \\
    0 \\
    \vdots
    \end{array}
    \right ) \text{\small $\gets$ $#1$-ième ligne}
    }
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Démo   %%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    \newcommand{\demo}[1]{\noindent  \textit{Démonstration.\,---\!--} #1 $\blacksquare$}
    \newcommand{\demoOf}[2]{\noindent  \textit{Démonstration #1.\,---\!--} #2 $\blacksquare$}
    
    \newcommand{\solution}[1]{\noindent  \textit{Solution.\,---\!--} #1 $\blacksquare$}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%    Fonctions continues   %%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \def\Cont{\mathscr{C}}
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%    Petit o   %%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\petito}[1]{ o\left ( #1\right)}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%    Topologie   %%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \newcommand{\bouleO}[2]{\mathring{B}\left ( #1, #2\right )}
    \newcommand{\bouleF}[2]{\overline{B}\left ( #1, #2\right )}
    \DeclareMathOperator{\diam}{diam}
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%    Récurrence   %%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \def\Heredite{$\text{HR}_n \impl \text{HR}_{n+1}$}
    \def\HerediteForte{$(\text{HR}_k)_{k\leq n} \impl \text{HR}_{n+1}$}
    \newcommand{\initRecurrence}[1]{$n=#1$}
    \newcommand{\HerediteWithArgument}[1]{$\text{HR}_{#1} \impl \text{HR}_{#1+1}$}
    \newcommand{\HerediteForteWithArgument}[1]{$(\text{HR}_\ell)_{\ell\leq #1} \impl \text{HR}_{#1+1}$}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%    Partie réelle et imaginaire   %%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \renewcommand{\Re}{\operatorname{Re}}
    \renewcommand{\Im}{\operatorname{Im}}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%    Cardinal   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \DeclareMathOperator{\Card}{Card}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%    Groupes   %%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \DeclareMathOperator{\Stab}{Stab}
    \def\Orb{\mathscr{O}}
    \newcommand{\GroupeSym}[1]{\mathfrak{S}_{#1}}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%    pgcd et ppcm   %%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \DeclareMathOperator{\pgcd}{pgcd}
    \DeclareMathOperator{\ppcm}{ppcm}
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%    Better underbraces for matrices   %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \newcommand{\underbracedmatrix}[2]{%
    \left(\;
    \smash[b]{\underbrace{
    \begin{matrix}#1\end{matrix}
    }_{#2}}
    \;\right)
    \vphantom{\underbrace{\begin{matrix}#1\end{matrix}}_{#2}}
    }
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%    Equivalence   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \DeclareMathOperator{\equivaut}{\sim}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%    Signe   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \DeclareMathOperator{\signe}{\mathrm{sign}}
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%    Vertical symbols   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \def\verticalEquals{\rotatebox[origin=c]{90}{$=$}}
    \def\verticalDefines{\rotatebox[origin=c]{-90}{$:=$}}
    \def\verticalSsi{\big\Updownarrow}
    \def\verticalImpl{\big\Downarrow}
    \def\verticalLongto{\rotatebox[origin=c]{-90}{$\longto$}}
    \def\verticalLeadsto{\rotatebox[origin=c]{-90}{$\leadsto$}}
    
    
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%    Better inf, max and min   %%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \let\inf\relax \DeclareMathOperator*\inf{\vphantom{p}inf}
    \let\max\relax \DeclareMathOperator*\max{\vphantom{p}max}
    \let\min\relax \DeclareMathOperator*\min{\vphantom{p}min}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%    Nice symbol for \leq and \geq   %%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \renewcommand\leq{\leqslant}
    \renewcommand\geq{\geqslant}
    
    
    
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%    Extra thin space   %%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % cf. http://tex.stackexchange.com/a/332158/8323
    
    \protected\def\miniSpace{%
    \ifmmode
    \mskip0.5\thinmuskip
    \else
    \ifhmode
    \kern0.08334em
    \fi
    \fi
    }
    
    opened by colasbd 12
  • Improved parser and other stuff

    Improved parser and other stuff

    This should fix #5 and make the framework usable for production. Uses or closes #5, #10, #11, #15 and #16.

    Major changes

    • It works, parsing actually produces results that are close to what TextMate does.
    • Supports incremental parsing with an NSOperation subclass.
    • The public interface to get languages and themes has changed.
    • Updated for Swift 3, Xcode 8 and the Swift API Design Guidelines
    • It copies the Color code from the X dependency (see #11 from alimoeeny).
    • Oh, and I changed tabs to spaces (soft tabs).

    The last two changes might be a bit polarizing. The reationale behind them is to make it easier for new people to contribute. Setting up the environment for a new project is always a big hurdle for adoption. If you want to invite people to play around with your framework, make it as simple as possible to go from git clone to a project that builds (and where tests pass). Like this it builds out of the box with no dependencies. Also, the current default in Xcode is soft tabs (4 spaces), so a new user will not mess up the spacing if he uses a clean install of Xcode.

    Caveats

    There are however a few things that still don't work as expected. Feel free to improve upon this.

    Due to differences between Onigurama and NSRegularExpression:

    • \G is not supported (for performance reasons the parser does not guarantee to match the end of a pattern right after begin, and even if it would, \G behaves wierdly with NSRegularExpression). This might be fixable.
    • NSRegularExpression seems to require a few more escape characters in certain places.
    • Backreferences from end to begin like \1 are not supported (I would like to know how Texmate does this).

    Not implemented:

    • The contentName property is ignored.
    • Attributes other than foreground color are ignored.
    • Cannot recursively include itself (use $self or $base instead, would require extra checks in the BundleManager). Fixable with extra logic.

    Notes

    Since I don't use Carthage or CocoaPods, some work probably still has to be done that is plays well with them. Any help would be appreciated.

    opened by alehed 33
  • Unable to build with carthage

    Unable to build with carthage

    Looks like the swift2 branch on soffes/X was deleted, which broke this.

    Cartfile:

    github "soffes/SyntaxKit" "master"
    

    terminal:

    $ carthage update
    *** Fetching X
    Failed to check out repository into /Users/you/Library/Caches/org.carthage.CarthageKit/dependencies/X: No object named "swift2" exists
    
    opened by younata 2
  • Only a subset of syntax is highlighted

    Only a subset of syntax is highlighted

    Hi, I was playing around with initial setup of the library. It seems like the library recognises only a subset of the syntax (while the same file opened in TextMate is showing the full syntax highlight – not sure if it's relevant)

    screen shot 2015-06-27 at 3 15 22 pm

    This is the code I used (more or less copied from the readme, slightly modified for Swift 2):

    let samplePath = bundle.URLForResource("Sample", withExtension: "swift")!
    let sample = try! String(contentsOfURL: samplePath)
    
    let languagePath = bundle.URLForResource("Swift", withExtension: "tmLanguage")!
    let languageDictionary = NSDictionary(contentsOfURL: languagePath) as! [NSObject: AnyObject]
    let language = Language(dictionary: languageDictionary)!
    
    let themeURL = bundle.URLsForResourcesWithExtension("tmTheme", subdirectory: nil)!.first!
    let themeDictioanry = NSDictionary(contentsOfURL: themeURL) as! [NSObject: AnyObject]
    let theme = Theme(dictionary: themeDictioanry)!
    
    let parse = AttributedParser(language: language, theme: theme)
    let attributedString = parse.attributedStringForString(sample)
    

    Following is the playground (please rename to .zip and extract).

    Is anything I'm doing look obviously wrong?

    And a follow up question: is there a smarter way to figure out the language used for a file than the file extension? Extensions might be used by several languages: .h file might be either Objective-C or plain C; while .m is used for both Objective-C and Matlab.

    Thanks a lot!

    enhancement 
    opened by zats 13
Releases(v0.1.1)
Owner
Sam Soffes
Building things
Sam Soffes
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view

ZSSRichTextEditor The Editor ZSSRichTextEditor is a beautiful Rich Text WYSIWYG Editor for iOS. It includes all of the standard editor tools one would

Nic Hubbard 3.7k Dec 31, 2022
Markdown syntax highlighter for iOS

Marklight Markdown syntax highlighter for iOS and macOS. Description Marklight is a drop in component to easily add realtime Markdown syntax highlight

Matteo Gavagnin 539 Dec 29, 2022
iOS & OSX Syntax Highlighter.

Highlightr Highlightr is an iOS & macOS syntax highlighter built with Swift. It uses highlight.js as it core, supports 185 languages and comes with 89

J.P. Illanes 1.4k Dec 23, 2022
An iOS app to turn typed text into images of handwritten text in your own handwriting style.

Text-to-Handwritting © 2021 by Daniel Christopher Long An iOS app to turn typed text into images of handwritten text in your own handwriting style. ht

Daniel Long 11 Dec 29, 2022
Generate SwiftUI Text or AttributedString from markdown strings with custom style names.

iOS 15.0 / macOS 12.0 / tvOS 15.0 / watchOS 8.0 StyledMarkdown is a mini library that lets you define custom styles in code and use them in your local

null 19 Dec 7, 2022
Notepad - A fully themeable iOS markdown editor with live syntax highlighting.

Notepad is just like any other UITextView, but you need to use the convenience initializer in order to use the themes. To create a new theme, copy one of the existing themes and edit the JSON.

Rudd Fawcett 802 Dec 31, 2022
Simple Application that registers Vapor Leaf's .leaf file type to LaunchServices as html enabling automatic syntax highlighting in Xcode.

Vapor Leaf Extension Update: The Vapor Leaf Extension is now meant to be used with the Xcode Plugin I designed to provide Xcode language support for t

Omran Khoja 12 Jun 18, 2022
CodeEditor - A SwiftUI TextEditor with syntax highlighting using Highlight.js

CodeEditor A SwiftUI TextEditor View with syntax highlighting using Highlight.js. It builds on top of Highlightr which does the wrapping of Highlight.

ZeeZide 269 Dec 30, 2022
A Swift library for efficient highlighting, indenting, and querying the structure of language syntax.

Neon A Swift library for efficient highlighting, indenting, and querying the structure of language syntax. It features: Minimal text invalidation Supp

Chime 214 Dec 28, 2022
A Collection of Tree-Sitter Parsers for Syntax Highlighting

CodeEditLanguages A collection of tree-sitter languages for syntax highlighting. Overview This package includes a binary framework CodeLanguagesContai

CodeEdit 16 Dec 30, 2022
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

iLeaf Solutions Pvt. Ltd. 222 Dec 17, 2022
Advanced Natural Motion Animations, Simple Blocks Based Syntax

FlightAnimator Moved to Swift 3.1 Support: For Swift 3.1 - Use tag Version 0.9.9 See Installation Instructions for clarification Introduction FlightAn

Anton 589 Dec 29, 2022
AudioPlayer is syntax and feature sugar over AVPlayer. It plays your audio files (local & remote).

AudioPlayer AudioPlayer is a wrapper around AVPlayer. It also offers cool features such as: Quality control based on number of interruption (buffering

Kevin Delannoy 676 Dec 25, 2022
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

SQLite.swift A type-safe, Swift-language layer over SQLite3. SQLite.swift provides compile-time confidence in SQL statement syntax and intent. Feature

Stephen Celis 8.7k Jan 8, 2023
FlexLayout adds a nice Swift interface to the highly optimized facebook/yoga flexbox implementation. Concise, intuitive & chainable syntax.

FlexLayout adds a nice Swift interface to the highly optimized Yoga flexbox implementation. Concise, intuitive & chainable syntax. Flexbox is an incre

layoutBox 1.7k Dec 30, 2022
Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]

Extremely Fast views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainabl

layoutBox 2.1k Dec 22, 2022
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class.

MisterFusion MisterFusion makes more easier to use AutoLayout in Swift & Objective-C code. Features Simple And Concise Syntax Use in Swift and Objecti

Taiki Suzuki 316 Nov 17, 2022
SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It's time to get rid of Objective-C cruft.

SwiftyTimer Modern Swifty API for NSTimer SwiftyTimer allows you to instantly schedule delays and repeating timers using convenient closure syntax. It

Radek Pietruszewski 1.2k Dec 27, 2022