All Projects → johnpatrickmorgan → Sparse

johnpatrickmorgan / Sparse

Licence: mit
Sparse is a simple parser-combinator library written in Swift.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Sparse

Shsearchbar
The search bar that doesn't suck.
Stars: ✭ 206 (+98.08%)
Mutual labels:  cocoapods, spm
Simpleimageviewer
A snappy image viewer with zoom and interactive dismissal transition.
Stars: ✭ 408 (+292.31%)
Mutual labels:  cocoapods, spm
Aksidemenu
Beautiful iOS side menu library with parallax effect. Written in Swift
Stars: ✭ 216 (+107.69%)
Mutual labels:  cocoapods, spm
Buymeacoffee
Buy Me a Coffee framework for iOS
Stars: ✭ 145 (+39.42%)
Mutual labels:  cocoapods, spm
Swiftysound
SwiftySound is a simple library that lets you play sounds with a single line of code.
Stars: ✭ 995 (+856.73%)
Mutual labels:  cocoapods, spm
Modernavplayer
ModernAVPlayer is a persistence AVPlayer wrapper
Stars: ✭ 179 (+72.12%)
Mutual labels:  cocoapods, spm
Gzipswift
Swift framework that enables gzip/gunzip Data using zlib
Stars: ✭ 356 (+242.31%)
Mutual labels:  cocoapods, spm
Color
Color utilities for macOS, iOS, tvOS, and watchOS
Stars: ✭ 145 (+39.42%)
Mutual labels:  cocoapods, spm
Parsel
Create complex parsers by combining simple ones with Parsel!
Stars: ✭ 21 (-79.81%)
Mutual labels:  cocoapods, spm
Validatedpropertykit
Easily validate your Properties with Property Wrappers 👮
Stars: ✭ 701 (+574.04%)
Mutual labels:  cocoapods, spm
Swiftuiblurview
This view is also part of SwiftUIKit: https://github.com/danielsaidi/SwiftUIKit
Stars: ✭ 120 (+15.38%)
Mutual labels:  cocoapods, spm
Sheeeeeeeeet
Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.
Stars: ✭ 1,177 (+1031.73%)
Mutual labels:  cocoapods, spm
M3u8parser
A light weight M3U8 parser. Support X-Key & X-Session-Key.
Stars: ✭ 187 (+79.81%)
Mutual labels:  parser, cocoapods
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+417.31%)
Mutual labels:  cocoapods, spm
Sketchkit
A lightweight auto-layout DSL library for iOS & tvOS.
Stars: ✭ 40 (-61.54%)
Mutual labels:  cocoapods, spm
Sstoastmessage
SSToastMessage is written purely in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to be simple, lightweight, and easy to use. It will be a popup with a single line of code.
Stars: ✭ 82 (-21.15%)
Mutual labels:  cocoapods, spm
Vue Docgen Api
Toolbox to extract information from Vue component files for documentation generation purposes.
Stars: ✭ 100 (-3.85%)
Mutual labels:  parser
Datepicker
A Date Picker with Calendar for iPhone and iPad Apps.
Stars: ✭ 103 (-0.96%)
Mutual labels:  cocoapods
Nsfwdetector
A NSFW (aka porn) detector with CoreML
Stars: ✭ 1,364 (+1211.54%)
Mutual labels:  cocoapods
Mention
Twitter like mentions and #hashtags parser for Go(Golang)
Stars: ✭ 99 (-4.81%)
Mutual labels:  parser

✂️ Sparse ✂️

Version License Swift

Sparse is a simple parsing library, written in Swift. It is based on the parser-combinator approach used by Haskell's Parsec. Its focus is on natural language parser creation and descriptive error messages.

Example

Here is a CSV parser:

let quote = character("\"")

let illegalCellCharacters = CharacterSet.newlines.union(CharacterSet(charactersIn: ","))
let unquotedCellCharacter = characterNot(in: illegalCellCharacters)
    .named("cell character")
let unquotedCell = many(unquotedCellCharacter).asString()
    .map { $0.trimmingCharacters(in: .whitespaces) }

let escapedQuote = quote.skipThen(quote)
    .named("escaped quote")
let quotedCellCharacter = characterNot("\"")
    .named("quoted cell character")
    .otherwise(escapedQuote)

let quotedCell = many(quotedCellCharacter, boundedBy: quote).asString()

let cell = quotedCell.otherwise(unquotedCell)

let cellSeparator = whitespaces().then(character(",")).then(whitespaces())
    .named("cell separator")
let line = many(cell, separator: cellSeparator)

let ending = optional(newline()).then(end())
let csv = many(line, separator: newline()).thenSkip(ending)

public func parseCSV(input: String) throws -> [[String]] {
    return try csv.parse(input)
}

Naming the component parsers allows for more descriptive error messages, e.g.:

Line 8, Column 12
r8c1 , "r8"c2" , r8c3 ,r8c4,r8c5,r8c6,r8c7 , r8c8
~~~~~~~~~~~^
Expected: '"' in escaped quote
Expected: whitespace in cell separator
Expected: ',' in cell separator
Expected: newline
Expected: EOF: file

Installation

Swift Package Manager

Add Sparse as a dependency in Package.swift:

.package(url: "https://github.com/johnpatrickmorgan/sparse.git", from: "0.3.0"),

CocoaPods

Add the following line to your Podfile:

pod "Sparse"

Credit

Sparse is based on Haskell's Parsec.

License

Sparse is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].