Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Improved parser and other stuff #18

Open
wants to merge 115 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
85f5f29
remove X dependency
alehed Jan 1, 2016
0a7c57b
fix tests not to include X any more
alehed Jan 3, 2016
2552f1c
revert erroneous import
alehed Jan 3, 2016
4515c1e
small consistency changes
alehed Jan 5, 2016
8de5f90
Get SyntaxKit working
alehed Jan 9, 2016
0b66d45
improve parser (Try II)
alehed Jan 13, 2016
96ae90e
Adjust Parser
alehed Jan 14, 2016
b39d05b
parser try III
alehed Jan 19, 2016
09369bd
get the parser working on the swift test file
alehed Jan 22, 2016
f32ce8c
add extra sanitation check
alehed Jan 22, 2016
6d62499
readjust tests and have the parsing order on a first come first serve…
alehed Jan 23, 2016
3eb0d2f
more fixes, including to grammars
alehed Jan 23, 2016
6f74770
minor adjustments
alehed Jan 24, 2016
48a9416
Add documentation to parser and inline result priority comparisons
alehed Jan 24, 2016
6f90bc1
Reformat hard tabs to soft tabs
alehed Jan 26, 2016
da92e2b
Implement incremental parsing
alehed Jan 31, 2016
ec64f83
greatly simplify parser incremental parsing algorithm
alehed Jan 31, 2016
e0f4449
add some documentation for ScopedString
alehed Jan 31, 2016
ad2cf92
minor comment changes
alehed Jan 31, 2016
13d0071
Fix range related bugs
alehed Feb 1, 2016
dfbc3d2
fix bug where deleting the beginning of a scope leads to an inadequat…
alehed Feb 1, 2016
5e98b64
Fix bug where cursor would temporarily disappear on deleting a newline
alehed Feb 1, 2016
7a1b4c3
Fix parser again and extend the tmLanguage grammar parsing
alehed Feb 6, 2016
878b5e2
Simplify ScopedString interphase and parsing improvements
alehed Feb 12, 2016
833d8f5
adjust whitespace, add comments and encapsulation corrections
alehed Feb 12, 2016
3d4baf6
fixes
alehed Feb 14, 2016
a7d519d
fixes
alehed Feb 14, 2016
bb0fd23
decrease expectations
alehed Feb 14, 2016
7a962c7
remove assert, index may be -1 in certain conditions
alehed Feb 15, 2016
b876333
ridculously slow and stupid implementation
alehed Feb 18, 2016
3b46e50
beautiful fix
alehed Feb 18, 2016
6569331
clean up public interface
alehed Feb 18, 2016
de3e33b
consistency and formatting changes
alehed Feb 18, 2016
3d9904f
Code cleanup
alehed Feb 18, 2016
98b274e
remove deprecations for Swift 3
alehed Mar 25, 2016
22edaf5
Update copyright information and add ability to abort
alehed Mar 28, 2016
2581e5f
Factor out operation part of the parser
alehed Apr 17, 2016
e6dbed0
make build universal again
alehed Apr 17, 2016
c78839d
refactor parts from parser into parsingOperation
alehed May 21, 2016
2cf64a0
Fix various range related bugs
alehed May 22, 2016
e053134
don't skip newlines
alehed Jun 20, 2016
5376bcf
shallow search instead of deep search
alehed Jun 20, 2016
30cbb21
change return to (pattern, start)
alehed Jun 20, 2016
08ae03a
don't use caching
alehed Jun 20, 2016
45b0b68
remove comments
alehed Jun 20, 2016
817a8d3
reintroduce language caching and other performance boosts
alehed Jun 21, 2016
463ca7d
make end prioritized over middle match
alehed Jun 21, 2016
cf12281
make parser use less memory in a stackframe
alehed Jun 23, 2016
049bf1e
add caveats
alehed Jun 23, 2016
21504a1
Remove unneeded assertions
alehed Jun 26, 2016
08aba25
Completely disable bitcode
alehed Jun 29, 2016
da6ab3b
change cache clearing signature
alehed Jul 3, 2016
ecb01b6
include what you use and make copyright implicit
alehed Jul 11, 2016
e4a1daf
start fleshing out comments
alehed Jul 12, 2016
48cd85f
Commenting on pattern
alehed Jul 12, 2016
d9e6943
Document theme and language
alehed Jul 12, 2016
1b6961d
Document BundleManager
alehed Jul 13, 2016
11f1bc0
Make ScopedString struct
alehed Jul 13, 2016
9e7049e
Allow use of non-global bundle manager
alehed Jul 16, 2016
e3cb7ab
comment on ScopedString and small name changes
alehed Jul 16, 2016
a6c8c62
Update readme and small fixes
alehed Jul 16, 2016
cbbe9f7
closes #2
alehed Jul 16, 2016
ee28cae
make logical types more encapsulated
alehed Jul 16, 2016
af90ce6
closes #5
alehed Jul 16, 2016
5f9aea8
closes #1
alehed Jul 16, 2016
efae434
add note about AttributedParsingOperation to Readme
alehed Jul 16, 2016
f0730a6
fix some tests
alehed Jul 16, 2016
06bd0ba
fix premature release and some more tests
alehed Jul 16, 2016
fe7193c
closes #7
alehed Jul 17, 2016
48e95cf
add useful changes from \G parsing branch
alehed Jul 17, 2016
4ebcb82
update baselines for tests
alehed Jul 17, 2016
087ec74
make it compile on all platforms without warnings
alehed Jul 17, 2016
0045e9f
remove caveats from readme
alehed Jul 17, 2016
53b85f4
Enable Bitcode
alehed Jul 17, 2016
8721eec
Merge remote-tracking branch 'github-original/master'
alehed Jul 29, 2016
838b129
update for Carthage and CocoaPods
alehed Jul 29, 2016
6c979a0
adjust version for pr
alehed Aug 7, 2016
c32fbe2
use linter on project
alehed Aug 27, 2016
ace12cf
fix more linter errors
alehed Aug 28, 2016
e582bfe
fix out-of-range bug on backspace and add test for it
alehed Aug 28, 2016
f47721f
add editorconfig
alehed Aug 28, 2016
7729312
get rid of force casts and force unwraps
alehed Sep 10, 2016
7bb4723
Update to Xcode 8 and Swift 3
alehed Sep 13, 2016
d23de4f
update readme and small fix
alehed Sep 13, 2016
46004b3
bump version to 1.0
alehed Sep 13, 2016
da4e922
Pass sender into the operation callback
alehed Sep 24, 2016
54bf2a2
fix tests
alehed Sep 24, 2016
de1b880
follow linter suggestions
alehed Nov 6, 2016
6fde1c8
naming fixes
Nov 9, 2016
9f26067
add kind TMFileType for TextMate files
alehed Nov 11, 2016
59c8f28
Merge branch 'master' of https://github.com/alehed/SyntaxKit
alehed Nov 11, 2016
da1cd52
update file name in xcode
alehed Nov 11, 2016
947940a
update readme
alehed Nov 11, 2016
06eeabb
Module Name
colasbd Dec 22, 2016
9407a98
Merge pull request #1 from colasbd/patch-1
alehed Dec 22, 2016
f47812b
fix linter warnings
alehed Dec 27, 2016
b093293
Merge branch 'master' of https://github.com/alehed/SyntaxKit
alehed Dec 27, 2016
020995f
add performance test to measure #20
alehed Jan 5, 2017
929049c
linter fixes (include order)
alehed Feb 18, 2017
5b14005
use xcode 8.2
alehed Mar 12, 2017
d6bf40c
Use swiftlint and squish warnings
alehed Jun 5, 2017
37b043e
fix all linter warnings!
alehed Jun 6, 2017
144b22d
fix linter errors in latest swiftlint
alehed Jun 19, 2017
cef7722
Swift 4 fixes.
sund4nce Aug 20, 2017
60128e1
Fixed indentation.
sund4nce Aug 21, 2017
44fe7c4
Fixed indentation.
sund4nce Aug 21, 2017
802de65
Merge pull request #4 from mort3m/master
alehed Sep 13, 2017
82fbd91
update recommended project settings
alehed Sep 17, 2017
083fd6b
update readme to say swift 4
alehed Sep 17, 2017
647b11c
Update to new recommended settings
alehed Aug 17, 2018
09d7ffe
Use swift 4 string improvements
alehed Aug 17, 2018
c7c0391
Update to Xcode 10 and Swift 4.2
alehed Sep 14, 2018
7e40f70
Update to Swift 5
alehed Aug 11, 2019
da57a63
Update readme with swift 5 notice
alehed Aug 11, 2019
ea3dc4f
Update test target to swift 5
alehed Aug 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.swift]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
1 change: 0 additions & 1 deletion Cartfile

This file was deleted.

1 change: 0 additions & 1 deletion Cartfile.resolved

This file was deleted.

24 changes: 14 additions & 10 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

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

SyntaxKit was abstracted from [Whiskey](http://usewhiskey.com).
SyntaxKit was originally abstracted from [Whiskey](http://usewhiskey.com).


## Building

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


## Installation
Expand All @@ -35,19 +35,20 @@ SyntaxKit uses `tmLanguage` and `tmTheme` files to highlight source code. None a

### Basic Parsing

Once you have a language, you can get started:
Once you have a BundleManager, you can get started:

```swift
import SyntaxKit

let path = "path to your .tmLanguage file"
let plist = NSDictionary(contentsOfFile: path)! as [NSObject: AnyObject]
let yaml = Language(dictionary: plist)
let manager = BundleManager() { identifier, isLanguage in
NSURL(string: "Location of Bundles/" + identifier + ".plist")
}
let yaml = manager.language(withIdentifier: "source.yaml")!

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:
`Parser` is a class that calls a block when it finds something the language file knows about. Let's print all of the elements in this string:

```swift
let input = "title: \"Hello World\"\n"
Expand All @@ -64,24 +65,27 @@ parser.parse(input) { scope, range in
SyntaxKit also comes with `AttributedParser`. This is a simple subclass of `Parser` that knows how to work with themes.

```swift
let tomorrow = Theme(dictionary: themePlist)
let tomorrow = manager.theme(withIdentifier: "tomorrow")!
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.
Notice that `attributes` is the third parameter to the block now. This is a dictionary of attributes you can give to `NSAttributedString`.

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

```swift
let attributedString = attributedParser.attributedStringForString(input)
let attributedString = attributedParser.attributedString(for: 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.

### Parsing Operations

There is also a `AttributedParsingOperation` subclass of NSOperation that facilitates multithreaded parsing.

### Custom Parsers

Expand Down
2 changes: 1 addition & 1 deletion SyntaxKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'SyntaxKit'
spec.version = '0.1.0'
spec.version = '1.0'
spec.authors = {'Sam Soffes' => '[email protected]'}
spec.homepage = 'https://github.com/soffes/SyntaxKit'
spec.summary = 'TextMate-style syntax highlighting.'
Expand Down
346 changes: 187 additions & 159 deletions SyntaxKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>IncrementalParsingTests</key>
<dict>
<key>testPerformanceBeginEnd()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.003</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPerformanceEdgeCases()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.002</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPerformanceExample()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.002</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPerformanceInScope()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.002</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPerformanceSingleLine()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.003</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>SwiftBaselineHighlightingTests</key>
<dict>
<key>testHighlightingPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.065</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>IncrementalParsingTests</key>
<dict>
<key>testPerformanceEdgeCases()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.0023728</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testPerformanceInScope()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.0030039</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>SwiftBaselineHighlightingTests</key>
<dict>
<key>testHighlightingPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.085269</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>runDestinationsByUUID</key>
<dict>
<key>36C0E679-EC89-495E-854F-FFBDEA1A4F58</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>100</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>6-Core Intel Xeon E5</string>
<key>cpuSpeedInMHz</key>
<integer>3500</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>12</integer>
<key>modelCode</key>
<string>MacPro6,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>6</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>i386</string>
<key>targetDevice</key>
<dict>
<key>modelCode</key>
<string>iPad2,1</string>
<key>platformIdentifier</key>
<string>com.apple.platform.iphonesimulator</string>
</dict>
</dict>
<key>39CEC1B4-ED87-4CDB-A7E7-9A4ED4F3BEC8</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>100</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>6-Core Intel Xeon E5</string>
<key>cpuSpeedInMHz</key>
<integer>3500</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>12</integer>
<key>modelCode</key>
<string>MacPro6,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>6</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>x86_64</string>
<key>targetDevice</key>
<dict>
<key>modelCode</key>
<string>iPhone8,2</string>
<key>platformIdentifier</key>
<string>com.apple.platform.iphonesimulator</string>
</dict>
</dict>
</dict>
</dict>
</plist>
14 changes: 2 additions & 12 deletions SyntaxKit.xcodeproj/xcshareddata/xcschemes/SyntaxKit-iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,8 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -80,15 +79,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211989A61B2EC3B600F0D786"
BuildableName = "SyntaxKit.framework"
BlueprintName = "SyntaxKit-iOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211826D91D257A71003F2BF2"
BuildableName = "SyntaxKit-tvOS.framework"
BuildableName = "SyntaxKit.framework"
BlueprintName = "SyntaxKit-tvOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
Expand All @@ -33,7 +33,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211826E21D257A71003F2BF2"
BuildableName = "SyntaxKitTests-tvOS.xctest"
BuildableName = "SyntaxKitTests.xctest"
BlueprintName = "SyntaxKitTests-tvOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
Expand All @@ -43,7 +43,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211826D91D257A71003F2BF2"
BuildableName = "SyntaxKit-tvOS.framework"
BuildableName = "SyntaxKit.framework"
BlueprintName = "SyntaxKit-tvOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
Expand All @@ -65,7 +65,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211826D91D257A71003F2BF2"
BuildableName = "SyntaxKit-tvOS.framework"
BuildableName = "SyntaxKit.framework"
BlueprintName = "SyntaxKit-tvOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
Expand All @@ -83,7 +83,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "211826D91D257A71003F2BF2"
BuildableName = "SyntaxKit-tvOS.framework"
BuildableName = "SyntaxKit.framework"
BlueprintName = "SyntaxKit-tvOS"
ReferencedContainer = "container:SyntaxKit.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading