Skip to content

Commit

Permalink
Updated for 0.12.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Feb 5, 2018
1 parent 58a0dc3 commit 0e0f08e
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.12.2](/~https://github.com/nicklockwood/Expression/releases/tag/0.12.2) (2018-02-05)

- AnyExpression now supports subscripting of `ArraySlice` and `Dictionary` values
- AnyExpression's `evaluate()` type casting now supports almost all numeric types
- Improved AnyExpression error messaging, especially array subscripting errors

## [0.12.1](/~https://github.com/nicklockwood/Expression/releases/tag/0.12.1) (2018-01-31)

- Reduced initialization time for `Expression` and `AnyExpression` instances
Expand Down
1 change: 0 additions & 1 deletion Examples/Calculator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Expression
import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet private var inputField: UITextField!
@IBOutlet private var outputView: UITextView!

Expand Down
1 change: 0 additions & 1 deletion Examples/Colors/ColorLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit

class ColorLabel: UILabel {

private func updateColor() {
do {
backgroundColor = .clear
Expand Down
1 change: 0 additions & 1 deletion Examples/Colors/UIColor+Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private let functions: [AnyExpression.Symbol: AnyExpression.SymbolEvaluator] = [
]

public extension UIColor {

public convenience init(rgba: UInt32) {
let red = CGFloat((rgba & 0xFF000000) >> 24) / 255
let green = CGFloat((rgba & 0x00FF0000) >> 16) / 255
Expand Down
1 change: 0 additions & 1 deletion Examples/Colors/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Expand Down
2 changes: 0 additions & 2 deletions Examples/Layout/View+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Expression
import UIKit

fileprivate class LayoutData: NSObject {

private weak var view: UIView!
private var inProgress = Set<String>()

Expand Down Expand Up @@ -179,7 +178,6 @@ fileprivate class LayoutData: NSObject {

@IBDesignable
public extension UIView {

fileprivate var layout: LayoutData? {
return layout(create: false)
}
Expand Down
1 change: 0 additions & 1 deletion Examples/Layout/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet private var leftField: UITextField!
@IBOutlet private var topField: UITextField!
@IBOutlet private var widthField: UITextField!
Expand Down
4 changes: 2 additions & 2 deletions Expression.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Expression",
"version": "0.12.1",
"version": "0.12.2",
"license": {
"type": "MIT",
"file": "LICENSE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "/~https://github.com/nicklockwood/Expression.git",
"tag": "0.12.1"
"tag": "0.12.2"
},
"source_files": "Sources",
"requires_arc": true,
Expand Down
8 changes: 3 additions & 5 deletions Sources/AnyExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AnyExpression.swift
// Expression
//
// Version 0.12.1
// Version 0.12.2
//
// Created by Nick Lockwood on 18/04/2017.
// Copyright © 2017 Nick Lockwood. All rights reserved.
Expand Down Expand Up @@ -182,7 +182,7 @@ public struct AnyExpression: CustomStringConvertible {
let symbol = Symbol.infix("==").description
throw Error.message(
String(symbol.first!).uppercased() +
"\(symbol.dropFirst()) can only be used with arguments that implement Hashable"
"\(symbol.dropFirst()) can only be used with arguments that implement Hashable"
)
}
throw Error.typeMismatch(.infix("=="), [lhs, rhs])
Expand Down Expand Up @@ -397,11 +397,10 @@ public struct AnyExpression: CustomStringConvertible {

// Internal API
extension AnyExpression.Error {

/// Standard error message for mismatched argument types
static func typeMismatch(_ symbol: AnyExpression.Symbol, _ args: [Any]) -> AnyExpression.Error {
let types = args.map {
AnyExpression.stringify(AnyExpression.isNil($0) ? $0 : type(of: $0))
AnyExpression.stringify(AnyExpression.isNil($0) ? $0 : type(of: $0))
}
if types.count == 1 {
if case .array = symbol {
Expand All @@ -427,7 +426,6 @@ extension AnyExpression.Error {

// Private API
private extension AnyExpression {

// Value storage
final class NanBox {
private static let mask = (-Double.nan).bitPattern
Expand Down
17 changes: 2 additions & 15 deletions Sources/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Expression.swift
// Expression
//
// Version 0.12.1
// Version 0.12.2
//
// Created by Nick Lockwood on 15/09/2016.
// Copyright © 2016 Nick Lockwood. All rights reserved.
Expand Down Expand Up @@ -87,7 +87,6 @@ public final class Expression: CustomStringConvertible {

/// Symbols that make up an expression
public enum Symbol: CustomStringConvertible, Hashable {

/// A named variable
case variable(String)

Expand Down Expand Up @@ -171,7 +170,6 @@ public final class Expression: CustomStringConvertible {

/// Runtime error when parsing or evaluating an expression
public enum Error: Swift.Error, CustomStringConvertible, Equatable {

/// An application-specific error
case message(String)

Expand Down Expand Up @@ -252,7 +250,6 @@ public final class Expression: CustomStringConvertible {

/// Options for configuring an expression
public struct Options: OptionSet {

/// Disable optimizations such as constant substitution
public static let noOptimize = Options(rawValue: 1 << 1)

Expand Down Expand Up @@ -445,7 +442,6 @@ public final class Expression: CustomStringConvertible {
/// Returns an opaque struct that cannot be evaluated but can be queried
/// for symbols or used to construct an executable Expression instance
public static func parse(_ expression: String, usingCache: Bool = true) -> ParsedExpression {

// Check cache
if usingCache {
var cachedExpression: Subexpression?
Expand Down Expand Up @@ -476,7 +472,6 @@ public final class Expression: CustomStringConvertible {
_ input: inout Substring.UnicodeScalarView,
upTo delimiters: String...
) -> ParsedExpression {

var unicodeScalarView = UnicodeScalarView(input)
let start = unicodeScalarView
var subexpression: Subexpression
Expand Down Expand Up @@ -590,7 +585,6 @@ public final class Expression: CustomStringConvertible {

// Private API
private extension Expression {

// Produce a printable number, without redundant decimal places
static func stringify(_ number: Double) -> String {
if let int = Int64(exactly: number) {
Expand All @@ -611,7 +605,6 @@ private extension Expression {
])

static func `operator`(_ lhs: String, takesPrecedenceOver rhs: String) -> Bool {

// /~https://github.com/apple/swift-evolution/blob/master/proposals/0077-operator-precedence.md
func precedence(of op: String) -> Int {
switch op {
Expand Down Expand Up @@ -901,7 +894,6 @@ private enum Subexpression: CustomStringConvertible {
withImpureSymbols impureSymbols: (Expression.Symbol) -> Expression.SymbolEvaluator?,
pureSymbols: (Expression.Symbol) -> Expression.SymbolEvaluator?
) -> Subexpression {

guard case .symbol(let symbol, var args, _) = self else {
return self
}
Expand Down Expand Up @@ -1013,11 +1005,8 @@ private extension Substring.UnicodeScalarView {

// Expression parsing logic
private extension UnicodeScalarView {

// Placeholder evaluator function
private func placeholder(_: [Double]) throws -> Double {
preconditionFailure()
}
private func placeholder(_: [Double]) throws -> Double { preconditionFailure() }

mutating func scanCharacters(_ matching: (UnicodeScalar) -> Bool) -> String? {
var index = startIndex
Expand Down Expand Up @@ -1088,7 +1077,6 @@ private extension UnicodeScalarView {
}

mutating func parseNumericLiteral() -> Subexpression? {

func scanInteger() -> String? {
return scanCharacters {
if case "0" ... "9" = $0 {
Expand Down Expand Up @@ -1382,7 +1370,6 @@ private extension UnicodeScalarView {
parseIdentifier() ??
parseOperator() ??
parseEscapedIdentifier() {

// Prepare for next iteration
var followedByWhitespace = skipWhitespace() || isEmpty

Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.12.1</string>
<string>0.12.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
1 change: 0 additions & 1 deletion Tests/AnyExpressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ class AnyExpressionTests: XCTestCase {
XCTAssertEqual(try expression.evaluate() as Double, 5)
}


func testCastNilResultAsOptionalDouble() {
let expression = AnyExpression("nil")
XCTAssertEqual(try expression.evaluate() as Double?, nil)
Expand Down

0 comments on commit 0e0f08e

Please sign in to comment.