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

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jun 15, 2015
1 parent d17d9ea commit c8b331d
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 237 deletions.
18 changes: 13 additions & 5 deletions SyntaxKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@
210299CB1B2E8924009C61EE /* SyntaxKit.h */,
210299C81B2E8924009C61EE /* Parser.swift */,
210299C41B2E8924009C61EE /* AttributedParser.swift */,
210299C51B2E8924009C61EE /* Capture.swift */,
210299C61B2E8924009C61EE /* CaptureCollection.swift */,
210299C71B2E8924009C61EE /* Language.swift */,
210299C91B2E8924009C61EE /* Pattern.swift */,
210299CA1B2E8924009C61EE /* Result.swift */,
210299E71B2E929C009C61EE /* ResultSet.swift */,
210299CC1B2E8924009C61EE /* Theme.swift */,
2119897B1B2E99CC00F0D786 /* Internal */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -124,6 +120,18 @@
path = Fixtures;
sourceTree = "<group>";
};
2119897B1B2E99CC00F0D786 /* Internal */ = {
isa = PBXGroup;
children = (
210299C91B2E8924009C61EE /* Pattern.swift */,
210299C51B2E8924009C61EE /* Capture.swift */,
210299C61B2E8924009C61EE /* CaptureCollection.swift */,
210299CA1B2E8924009C61EE /* Result.swift */,
210299E71B2E929C009C61EE /* ResultSet.swift */,
);
name = Internal;
sourceTree = "<group>";
};
2122A6D41B22B9320006409B = {
isa = PBXGroup;
children = (
Expand Down
192 changes: 107 additions & 85 deletions SyntaxKit/Sources/AttributedParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,136 +2,158 @@
// AttributedParser.swift
// SyntaxKit
//
// Created by Sam Soffes on 6/5/15.
// Copyright (c) 2015 Sam Soffes. All rights reserved.
// Created by Sam Soffes on 9/24/14.
// Copyright © 2014-2015 Sam Soffes. All rights reserved.
//

public class AttributedParser: Parser {
// - (instancetype)initWithLanguageName:(NSString *)languageName {
// if ((self = [super init])) {
// self.language = [SYNLanguage languageWithName:languageName];
// #pragma mark - Accessors
//
// @synthesize baseAttributes = _baseAttributes;
// @synthesize attributes = _attributes;
// @synthesize fontFamily = _fontFamily;
//
// - (void)setTheme:(SYNTheme *)theme {
// _theme = theme;
// [self updateTheme];
// }
//
//
// if (!self.language) {
// return (self = nil);
// - (void)setFontFamily:(NOMFontFamily *)fontFamily {
// _fontFamily = fontFamily;
// [self updateTheme];
// }
//
//
// #pragma mark - Initializers
//
// - (instancetype)initWithLanguageName:(NSString *)languageName themeName:(NSString *)themeName {
// if ((self = [super initWithLanguageName:languageName])) {
// self.attributes = [[NSMutableDictionary alloc] init];
// self.theme = [SYNTheme themeWithName:themeName];
// }
// return self;
// }
//
//
// - (void)parse:(NSString *)string match:(SYNParserMatchCallback)callback {
// NSParameterAssert(string);
// NSParameterAssert(callback);
// - (instancetype)initWithLanguageName:(NSString *)languageName {
// return (self = [self initWithLanguageName:languageName themeName:nil]);
// }
//
// // Loop through paragraphs
// NSUInteger length = [string length];
// NSUInteger paragraphStart = 0;
// NSUInteger paragraphEnd = 0;
// NSUInteger contentsEnd = 0;
// while (paragraphEnd < length) {
// [string getParagraphStart:&paragraphStart end:&paragraphEnd
// contentsEnd:&contentsEnd forRange:NSMakeRange(paragraphEnd, 0)];
// NSRange paragraphRange = NSMakeRange(paragraphStart, contentsEnd - paragraphStart);
// NSUInteger limit = NSMaxRange(paragraphRange);
// NSRange range = paragraphRange;
//
// // Loop through the line until we reach the end
// while (range.length > 0 && range.location < limit) {
// NSUInteger location = [self parse:string inRange:range callback:callback];
// range.location = location;
// range.length = fmax(0, range.length - paragraphRange.location - range.location);
// }
// }
// - (void)setAttributes:(NSDictionary *)attributes forScope:(NSString *)scope {
// self.attributes[scope] = attributes;
// }
//
//
// #pragma mark - Private
// #pragma mark - Parsing
//
// // Returns new location
// - (NSUInteger)parse:(NSString *)string inRange:(NSRange)bounds callback:(SYNParserMatchCallback)callback {
// for (SYNPattern *pattern in self.language.patterns) {
// // Single pattern
// if (pattern.match) {
// SYNResultSet *resultSet = [self parse:string inRange:bounds scope:pattern.name expression:pattern.match captures:pattern.captures];
// if (!resultSet) {
// continue;
// - (void)parse:(NSString *)string attributedMatch:(SYNAttributedParserMatchCallback)match {
// [self parse:string match:^(NSString *scope, NSRange range) {
// NSDictionary *attributes = [self attributesForScope:scope];
// if (attributes) {
// match(scope, range, attributes);
// }
// return [self applyResults:resultSet callback:callback];
// }];
// }
//
// // Begin & end
// if (pattern.begin && pattern.end) {
// SYNResultSet *begin = [self parse:string inRange:bounds scope:nil expression:pattern.begin captures:pattern.beginCaptures];
// if (!begin) {
// continue;
// }
//
// NSRange endRange = bounds;
// endRange.location = NSMaxRange(begin.range);
// endRange.length -= endRange.location - bounds.location;
// #pragma mark - Attributes
//
// SYNResultSet *end = [self parse:string inRange:endRange scope:nil expression:pattern.end captures:pattern.endCaptures];
// if (!end) {
// // TODO: Rewind?
// continue;
// - (NSDictionary *)attributesForScope:(NSString *)scope {
// if (!scope) {
// return nil;
// }
//
// SYNResultSet *resultSet = [[SYNResultSet alloc] init];
// NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
// NSArray *components = [scope componentsSeparatedByString:@"."];
//
// // Add whole scope before start and end
// if (pattern.name) {
// [resultSet addResultWithScope:pattern.name range:NSUnionRange(begin.range, end.range)];
// NSUInteger count = [components count];
// if (count == 0) {
// return nil;
// }
//
// [resultSet addResultsFromResultSet:begin];
// [resultSet addResultsFromResultSet:end];
// for (NSUInteger i = 0; i < count; i++) {
// NSString *key = [[components subarrayWithRange:NSMakeRange(0, count - 1 - i)] componentsJoinedByString:@"."];
// [attributes addEntriesFromDictionary:self.attributes[key]];
// }
//
// return [self applyResults:resultSet callback:callback];
// if ([attributes count] == 0) {
// return nil;
// }
//
// return attributes;
// }
//
// return NSMaxRange(bounds);
//
// - (void)removeAttributesForScope:(NSString *)scope {
// [self.attributes removeObjectForKey:scope];
// }
//
//
// // Parse an expression with captures
// - (SYNResultSet *)parse:(NSString *)string inRange:(NSRange)bounds scope:(NSString *)scope expression:(NSString *)pattern captures:(SYNCaptureCollection *)captures {
// NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionAnchorsMatchLines error:nil];
// NSArray *matches = [expression matchesInString:string options:kNilOptions range:bounds];
// NSTextCheckingResult *result = [matches firstObject];
// if (!result) {
// return nil;
// - (NSAttributedString *)attributedStringForString:(NSString *)string {
// NSMutableAttributedString *output = [[NSMutableAttributedString alloc] initWithString:string attributes:self.baseAttributes];
//
// [self parse:string match:^(NSString *scope, NSRange range) {
// NSDictionary *attributes = [self attributesForScope:scope];
// if (attributes) {
// [output addAttributes:attributes range:range];
// }
// }];
//
// SYNResultSet *resultSet = [[SYNResultSet alloc] init];
// if (scope && result.range.location != NSNotFound) {
// [resultSet addResultWithScope:scope range:result.range];
// return output;
// }
//
// for (NSNumber *index in [captures captureIndexes]) {
// NSRange range = [result rangeAtIndex:[index integerValue]];
// if (range.location == NSNotFound) {
//
// #pragma mark - Private
//
// - (void)updateTheme {
// for (NSDictionary *item in self.theme.settings) {
// NSString *scopes = item[@"scope"];
// NSDictionary *settings = item[@"settings"];
// NSDictionary *attributes = [self attributesFromSettings:settings];
// if (!scopes) {
// [self setBaseAttributes:attributes];
// continue;
// }
//
// scope = [[captures captureAtIndex:[index integerValue]] name];
// [resultSet addResultWithScope:scope range:range];
// NSArray *components = [scopes componentsSeparatedByString:@","];
// for (NSString *component in components) {
// NSString *scope = [component stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// [self setAttributes:attributes forScope:scope];
// }
//
// if (![resultSet isEmpty]) {
// return resultSet;
// }
//
// return nil;
// }
//
// - (NSDictionary *)attributesFromSettings:(NSDictionary *)settings {
// static NSDictionary *map;
// static dispatch_once_t onceToken;
// dispatch_once(&onceToken, ^{
// map = @{
// @"foreground": NSForegroundColorAttributeName,
// @"background": NSBackgroundColorAttributeName
// // TODO: caret, invisibles, lightHighlight, selection
// };
// });
//
// - (NSUInteger)applyResults:(SYNResultSet *)resultSet callback:(SYNParserMatchCallback)callback {
// NSUInteger max = 0;
// for (SYNResult *result in resultSet.results) {
// callback(result.scope, result.range);
// max = fmax(NSMaxRange(result.range), max);
// NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithCapacity:[settings count]];
// for (NSString *key in settings) {
// NSString *name = map[key];
// if (name) {
// attributes[name] = [NOMColor colorWithHex:settings[key]];
// continue;
// }
//
// if (self.fontFamily && [key isEqualToString:@"fontStyle"]) {
// NSString *value = settings[key];
// if ([value isEqualToString:@"italic"]) {
// NOMFont *font = [self.fontFamily fontForStyle:NOMFontStyleItalic];
// if (font) {
// attributes[NSFontAttributeName] = font;
// }
// }
// }
// }
// return max;
// return attributes;
// }
}
10 changes: 5 additions & 5 deletions SyntaxKit/Sources/Capture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
// Capture.swift
// SyntaxKit
//
// Created by Sam Soffes on 6/5/15.
// Copyright (c) 2015 Sam Soffes. All rights reserved.
// Created by Sam Soffes on 9/18/14.
// Copyright © 2014-2015 Sam Soffes. All rights reserved.
//

import Foundation

public struct Capture {
struct Capture {

// MARK: - Properties

public let name: String
let name: String


// MARK: - Initializers

public init?(dictionary: [NSObject: AnyObject]) {
init?(dictionary: [NSObject: AnyObject]) {
guard let name = dictionary["name"] as? String else { return nil }
self.name = name
}
Expand Down
12 changes: 6 additions & 6 deletions SyntaxKit/Sources/CaptureCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// CaptureCollection.swift
// SyntaxKit
//
// Created by Sam Soffes on 6/5/15.
// Copyright (c) 2015 Sam Soffes. All rights reserved.
// Created by Sam Soffes on 9/19/14.
// Copyright © 2014-2015 Sam Soffes. All rights reserved.
//

import Foundation

public struct CaptureCollection {
struct CaptureCollection {

// MARK: - Properties

private let captures: [UInt: Capture]

public var captureIndexes: [UInt] {
var captureIndexes: [UInt] {
var keys = captures.keys.array
keys.sortInPlace() { $0 < $1 }
return keys
Expand All @@ -23,7 +23,7 @@ public struct CaptureCollection {

// MARK: - Initializers

public init?(dictionary: [NSObject: AnyObject]) {
init?(dictionary: [NSObject: AnyObject]) {
guard let dictionary = dictionary as? [String: [String: String]] else { return nil }

var captures = [UInt: Capture]()
Expand All @@ -38,7 +38,7 @@ public struct CaptureCollection {

// MARK: - Accessing Captures

public subscript(index: UInt) -> Capture? {
subscript(index: UInt) -> Capture? {
return captures[index]
}
}
8 changes: 4 additions & 4 deletions SyntaxKit/Sources/Language.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Language.swift
// SyntaxKit
//
// Created by Sam Soffes on 6/5/15.
// Copyright (c) 2015 Sam Soffes. All rights reserved.
// Created by Sam Soffes on 9/18/14.
// Copyright © 2014-2015 Sam Soffes. All rights reserved.
//

import Foundation

public typealias Repository = [String: Pattern]
typealias Repository = [String: Pattern]

public struct Language {
// #pragma mark - Factory
Expand Down Expand Up @@ -58,7 +58,7 @@ public struct Language {
public let UUID: String
public let name: String
public let scopeName: String
public let patterns: [Pattern]
let patterns: [Pattern]


// MARK: - Initializers
Expand Down
Loading

0 comments on commit c8b331d

Please sign in to comment.