-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These tests use files from the top-repos corpus and annotate lines that have intentional highlight formatting. Highlight tests can only run on tree-sitter 0.20.4+ (before that there were bugs that made it very slow), so must be disabled during the check on older tree-sitter versions.
- Loading branch information
1 parent
c0d7451
commit c5c2cf7
Showing
20 changed files
with
507 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/highlight/* linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ node_modules | |
!/src/scanner.c | ||
*.swp | ||
/build | ||
/test | ||
Cargo.lock | ||
/target/* | ||
*.a | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Cocoa | ||
// ^ include | ||
import GRDB | ||
|
||
@NSApplicationMain | ||
// ^ type | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
// ^ keyword | ||
// ^ type | ||
// ^ punctuation.delimiter | ||
// ^ type | ||
// ^ punctuation.delimiter | ||
// ^ punctuation.bracket | ||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
// ^ keyword.function | ||
// ^ method | ||
// ^ parameter | ||
// ^ parameter | ||
_ = try! DatabaseQueue() | ||
// ^ operator | ||
// ^ operator | ||
// ^ function.call | ||
_ = FTS5() | ||
_ = sqlite3_preupdate_new(nil, 0, nil) | ||
// ^ variable.builtin | ||
// ^ number | ||
} | ||
// ^ punctuation.bracket | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
// | ||
// Bag.swift | ||
// Platform | ||
// | ||
// Created by Krunoslav Zaher on 2/28/15. | ||
// Copyright © 2015 Krunoslav Zaher. All rights reserved. | ||
// | ||
|
||
import Swift | ||
|
||
let arrayDictionaryMaxSize = 30 | ||
|
||
struct BagKey { | ||
// ^ keyword | ||
/** | ||
Unique identifier for object added to `Bag`. | ||
|
||
It's underlying type is UInt64. If we assume there in an idealized CPU that works at 4GHz, | ||
it would take ~150 years of continuous running time for it to overflow. | ||
*/ | ||
// ^ comment | ||
fileprivate let rawValue: UInt64 | ||
// ^ keyword | ||
// ^ keyword | ||
// ^ property | ||
} | ||
|
||
/** | ||
Data structure that represents a bag of elements typed `T`. | ||
|
||
Single element can be stored multiple times. | ||
|
||
Time and space complexity of insertion and deletion is O(n). | ||
|
||
It is suitable for storing small number of elements. | ||
*/ | ||
struct Bag<T> : CustomDebugStringConvertible { | ||
// ^ type | ||
/// Type of identifier for inserted elements. | ||
// ^ comment | ||
typealias KeyType = BagKey | ||
|
||
typealias Entry = (key: BagKey, value: T) | ||
|
||
private var _nextKey: BagKey = BagKey(rawValue: 0) | ||
// ^ keyword | ||
// ^ keyword | ||
// ^ property | ||
|
||
// data | ||
|
||
// first fill inline variables | ||
var _key0: BagKey? | ||
var _value0: T? | ||
|
||
// then fill "array dictionary" | ||
var _pairs = ContiguousArray<Entry>() | ||
|
||
// last is sparse dictionary | ||
var _dictionary: [BagKey: T]? | ||
|
||
var _onlyFastPath = true | ||
|
||
/// Creates new empty `Bag`. | ||
init() { | ||
// ^ constructor | ||
} | ||
|
||
/** | ||
Inserts `value` into bag. | ||
|
||
- parameter element: Element to insert. | ||
- returns: Key that can be used to remove element from bag. | ||
*/ | ||
mutating func insert(_ element: T) -> BagKey { | ||
// ^ operator | ||
let key = _nextKey | ||
|
||
_nextKey = BagKey(rawValue: _nextKey.rawValue &+ 1) | ||
// ^ operator | ||
|
||
if _key0 == nil { | ||
// ^ conditional | ||
_key0 = key | ||
_value0 = element | ||
return key | ||
// ^ keyword.return | ||
} | ||
|
||
_onlyFastPath = false | ||
|
||
if _dictionary != nil { | ||
_dictionary![key] = element | ||
return key | ||
} | ||
|
||
if _pairs.count < arrayDictionaryMaxSize { | ||
_pairs.append((key: key, value: element)) | ||
return key | ||
} | ||
|
||
_dictionary = [key: element] | ||
|
||
return key | ||
} | ||
|
||
/// - returns: Number of elements in bag. | ||
var count: Int { | ||
let dictionaryCount: Int = _dictionary?.count ?? 0 | ||
return (_value0 != nil ? 1 : 0) + _pairs.count + dictionaryCount | ||
} | ||
|
||
/// Removes all elements from bag and clears capacity. | ||
mutating func removeAll() { | ||
_key0 = nil | ||
_value0 = nil | ||
|
||
_pairs.removeAll(keepingCapacity: false) | ||
_dictionary?.removeAll(keepingCapacity: false) | ||
} | ||
|
||
/** | ||
Removes element with a specific `key` from bag. | ||
|
||
- parameter key: Key that identifies element to remove from bag. | ||
- returns: Element that bag contained, or nil in case element was already removed. | ||
*/ | ||
mutating func removeKey(_ key: BagKey) -> T? { | ||
if _key0 == key { | ||
_key0 = nil | ||
let value = _value0! | ||
_value0 = nil | ||
return value | ||
} | ||
|
||
if let existingObject = _dictionary?.removeValue(forKey: key) { | ||
return existingObject | ||
} | ||
|
||
for i in 0 ..< _pairs.count where _pairs[i].key == key { | ||
let value = _pairs[i].value | ||
_pairs.remove(at: i) | ||
return value | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
extension Bag { | ||
// ^ keyword | ||
// ^ type | ||
/// A textual representation of `self`, suitable for debugging. | ||
var debugDescription : String { | ||
"\(self.count) elements in Bag" | ||
// ^ string | ||
// ^ punctuation.bracket | ||
// ^ variable.builtin | ||
} | ||
} | ||
|
||
extension Bag { | ||
/// Enumerates elements inside the bag. | ||
/// | ||
/// - parameter action: Enumeration closure. | ||
func forEach(_ action: (T) -> Void) { | ||
if _onlyFastPath { | ||
if let value0 = _value0 { | ||
action(value0) | ||
} | ||
return | ||
} | ||
|
||
let value0 = _value0 | ||
let dictionary = _dictionary | ||
|
||
if let value0 = value0 { | ||
action(value0) | ||
} | ||
|
||
for i in 0 ..< _pairs.count { | ||
action(_pairs[i].value) | ||
} | ||
|
||
if dictionary?.count ?? 0 > 0 { | ||
for element in dictionary!.values { | ||
action(element) | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension BagKey: Hashable { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(rawValue) | ||
} | ||
} | ||
|
||
func ==(lhs: BagKey, rhs: BagKey) -> Bool { | ||
lhs.rawValue == rhs.rawValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2016 Luke Zhao <me@lkzhao.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import Foundation | ||
|
||
public protocol HeroStringConvertible { | ||
static func from(node: ExprNode) -> Self? | ||
// ^ keyword | ||
} | ||
|
||
extension String { | ||
func parse<T: HeroStringConvertible>() -> [T]? { | ||
// ^ punctuation.delimiter | ||
// ^ type | ||
let lexer = Lexer(input: self) | ||
let parser = Parser(tokens: lexer.tokenize()) | ||
// ^ punctuation.delimiter | ||
// ^ function.call | ||
do { | ||
// ^ keyword | ||
let nodes = try parser.parse() | ||
// ^ operator | ||
var results = [T]() | ||
// ^ punctuation.bracket | ||
for node in nodes { | ||
if let modifier = T.from(node: node) { | ||
results.append(modifier) | ||
} else { | ||
print("\(node.name) doesn't exist in \(T.self)") | ||
// ^ string | ||
} | ||
} | ||
return results | ||
} catch let error { | ||
// ^ keyword | ||
// ^ keyword | ||
// ^ variable | ||
print("failed to parse \"\(self)\", error: \(error)") | ||
} | ||
return nil | ||
} | ||
|
||
func parseOne<T: HeroStringConvertible>() -> T? { | ||
return parse()?.last | ||
} | ||
} |
Oops, something went wrong.