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

Commit

Permalink
Merge pull request #14 from zachwaugh/fix-range-calculation
Browse files Browse the repository at this point in the history
Change how range is calculated to fix crash
  • Loading branch information
soffes authored Jul 12, 2016
2 parents af9b320 + 0634d78 commit 4371a7c
Show file tree
Hide file tree
Showing 5 changed files with 716 additions and 1 deletion.
12 changes: 12 additions & 0 deletions SyntaxKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
21F28DDB1B7AC7F8009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDA1B7AC7F8009DD1E9 /* X.framework */; };
21F28DDD1B7AC802009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDC1B7AC802009DD1E9 /* X.framework */; };
21F28DDF1B7AC80B009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDE1B7AC80B009DD1E9 /* X.framework */; };
92EC79D41CC9060600E058ED /* JavaScript.tmLanguage in Resources */ = {isa = PBXBuildFile; fileRef = 92EC79D31CC9060600E058ED /* JavaScript.tmLanguage */; };
92EC79D51CC9060600E058ED /* JavaScript.tmLanguage in Resources */ = {isa = PBXBuildFile; fileRef = 92EC79D31CC9060600E058ED /* JavaScript.tmLanguage */; };
92EC79D71CC9061D00E058ED /* test.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 92EC79D61CC9061D00E058ED /* test.js.txt */; };
92EC79D81CC9061D00E058ED /* test.js.txt in Resources */ = {isa = PBXBuildFile; fileRef = 92EC79D61CC9061D00E058ED /* test.js.txt */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -182,6 +186,8 @@
21F28DDA1B7AC7F8009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/iOS/X.framework; sourceTree = "<group>"; };
21F28DDC1B7AC802009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/Mac/X.framework; sourceTree = "<group>"; };
21F28DDE1B7AC80B009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/watchOS/X.framework; sourceTree = "<group>"; };
92EC79D31CC9060600E058ED /* JavaScript.tmLanguage */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = JavaScript.tmLanguage; sourceTree = "<group>"; };
92EC79D61CC9061D00E058ED /* test.js.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test.js.txt; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -284,6 +290,8 @@
210BF26C1B37C04E008AA4F0 /* test.rb.txt */,
2119897E1B2EAF0900F0D786 /* Tomorrow.tmTheme */,
2119897F1B2EAF0900F0D786 /* YAML.tmLanguage */,
92EC79D31CC9060600E058ED /* JavaScript.tmLanguage */,
92EC79D61CC9061D00E058ED /* test.js.txt */,
);
path = Fixtures;
sourceTree = "<group>";
Expand Down Expand Up @@ -628,8 +636,10 @@
files = (
210BF2711B37C0A2008AA4F0 /* Ruby.tmLanguage in Resources */,
211989C91B2EC40900F0D786 /* Tomorrow.tmTheme in Resources */,
92EC79D81CC9061D00E058ED /* test.js.txt in Resources */,
210BF26E1B37C04E008AA4F0 /* test.rb.txt in Resources */,
211989CA1B2EC40900F0D786 /* YAML.tmLanguage in Resources */,
92EC79D51CC9060600E058ED /* JavaScript.tmLanguage in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -646,8 +656,10 @@
files = (
210BF2701B37C0A2008AA4F0 /* Ruby.tmLanguage in Resources */,
211989801B2EAF0900F0D786 /* Tomorrow.tmTheme in Resources */,
92EC79D71CC9061D00E058ED /* test.js.txt in Resources */,
210BF26D1B37C04E008AA4F0 /* test.rb.txt in Resources */,
211989811B2EAF0900F0D786 /* YAML.tmLanguage in Resources */,
92EC79D41CC9060600E058ED /* JavaScript.tmLanguage in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion SyntaxKit/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class Parser {
beginRange = beginResults.range else { continue }

let location = NSMaxRange(beginRange)
let endBounds = NSMakeRange(location, bounds.length - location - bounds.location)
let endBounds = NSMakeRange(location, NSMaxRange(bounds) - location)

guard let endResults = parse(string, inRange: endBounds, expression: end, captures: pattern.endCaptures),
endRange = endResults.range else { /* TODO: Rewind? */ continue }
Expand Down
6 changes: 6 additions & 0 deletions SyntaxKit/Tests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ class ParserTests: XCTestCase {
let input = fixture("test.rb", "txt")
parser.parse(input, match: { _, _ in return })
}

func testJavaScript() {
let parser = Parser(language: language("JavaScript"))
let input = fixture("test.js", "txt")
parser.parse(input, match: { _, _ in return })
}
}
Loading

0 comments on commit 4371a7c

Please sign in to comment.