Giter Site home page Giter Site logo

syntaxkit's Introduction

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.

syntaxkit's People

Contributors

soffes avatar younata avatar zachwaugh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

syntaxkit's Issues

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";
}

Create Demo Project

Would be great to have a demo project in order to see how to apply live syntax coloring with the help of this library.

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.

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!

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

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
}

[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  

Live syntax coloring

Any idea how this will perform with live syntax coloring? Any issues with partial/invalid syntax?

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

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.

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.