<commit_before>//  Copyright (C) 2016 <NAME>. All rights reserved.


// MARK: - Parser

public struct Parser<C: Collection>: ParserProtocol {
	private let satisfy: (C.Iterator.Element) -> Bool
	
	public init(_ satisfy: @escaping (C.Iterator.Element) -> Bool) {
		self.satisfy = satisfy
	}
	
	// MARK: ParserProtocol
	
	public typealias Targets = C
	public typealias Tree = C.Iterator.Element
	
	public func parse<A>(_ input: C, at index: C.Index, ifSuccess: (C.Iterator.Element, C.Index) throws -> A) throws -> A {
		guard let nextIndex = input.index(index, offsetBy: 1, limitedBy: input.endIndex) else {
			throw ParsingError.rangeOver(index)
		}
		
		let x = input[index]
		
		guard satisfy(x) else {
			throw ParsingError.notEqual(index)
		}
		
		return try ifSuccess(x, nextIndex)
	}
}

// MARK: - Constructor

public func satisfy<C>(_ pred: @escaping (C.Iterator.Element) -> Bool) -> Parser<C> {
	return Parser(pred)
}

public func oneOf<C>(_ input: C) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { elem in
		input.contains(where: { $0 == elem })
	}
}

public func noneOf<C>(_ input: C) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { elem in
		!input.contains(where: { $0 == elem })
	}
}

public prefix func % <C>(literal: C.Iterator.Element) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { $0 == literal }
}

public prefix func % <C>(range: Range<C.Iterator.Element>) -> Parser<C> {
	return satisfy(range.contains)
}

public prefix func % <C>(range: ClosedRange<C.Iterator.Element>) -> Parser<C> {
	return satisfy(range.contains)
}<commit_msg>Add any()<commit_after>//  Copyright (C) 2016 <NAME>. All rights reserved.

import Prelude

// MARK: - Parser

public struct Parser<C: Collection>: ParserProtocol {
	private let satisfy: (C.Iterator.Element) -> Bool
	
	public init(_ satisfy: @escaping (C.Iterator.Element) -> Bool) {
		self.satisfy = satisfy
	}
	
	// MARK: ParserProtocol
	
	public typealias Targets = C
	public typealias Tree = C.Iterator.Element
	
	public func parse<A>(_ input: C, at index: C.Index, ifSuccess: (C.Iterator.Element, C.Index) throws -> A) throws -> A {
		guard let nextIndex = input.index(index, offsetBy: 1, limitedBy: input.endIndex) else {
			throw ParsingError.rangeOver(index)
		}
		
		let x = input[index]
		
		guard satisfy(x) else {
			throw ParsingError.notEqual(index)
		}
		
		return try ifSuccess(x, nextIndex)
	}
}

// MARK: - Constructor

public func satisfy<C>(_ pred: @escaping (C.Iterator.Element) -> Bool) -> Parser<C> {
	return Parser(pred)
}

public func oneOf<C>(_ input: C) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { elem in
		input.contains(where: { $0 == elem })
	}
}

public func noneOf<C>(_ input: C) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { elem in
		!input.contains(where: { $0 == elem })
	}
}

public func any<C>() -> Parser<C> {
	return satisfy(const(true))
}

public prefix func % <C>(literal: C.Iterator.Element) -> Parser<C> where C.Iterator.Element: Equatable {
	return satisfy { $0 == literal }
}

public prefix func % <C>(range: Range<C.Iterator.Element>) -> Parser<C> {
	return satisfy(range.contains)
}

public prefix func % <C>(range: ClosedRange<C.Iterator.Element>) -> Parser<C> {
	return satisfy(range.contains)
}
{'fraction_non_alphanumeric': 0.14566334239951648, 'fraction_numerical': 0.004835297673012995, 'mean_word_length': 3.882005899705015, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '72043', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1113, 'n_words': 307}