Permalink
Browse files

Merge pull request #152 from davedelong/swift4

Swift 4
  • Loading branch information...
davedelong committed Apr 7, 2018
2 parents 440253e + 31053a8 commit 0f2e8562393796a0467a1c418a5f8ce552dcfbb1
Showing with 2,532 additions and 275 deletions.
  1. +296 −18 DDMathParser.xcodeproj/project.pbxproj
  2. +3 −3 DDMathParser.xcodeproj/xcshareddata/xcschemes/MathParser.xcscheme
  3. +75 −0 Demo/AnalyzerFlowViewController.swift
  4. +51 −0 Demo/AnalyzerFlowViewController.xib
  5. +33 −0 Demo/AnalyzerViewController.swift
  6. +29 −0 Demo/AppDelegate.swift
  7. +58 −0 Demo/Assets.xcassets/AppIcon.appiconset/Contents.json
  8. +678 −0 Demo/Base.lproj/MainMenu.xib
  9. +10 −0 Demo/Demo.entitlements
  10. +108 −0 Demo/DemoViewController.swift
  11. +63 −0 Demo/DemoViewController.xib
  12. +92 −0 Demo/ExpressionAnalyzerViewController.swift
  13. +72 −0 Demo/ExpressionAnalyzerViewController.xib
  14. +100 −0 Demo/GroupedTokenAnalyzerViewController.swift
  15. +72 −0 Demo/GroupedTokenAnalyzerViewController.xib
  16. +30 −0 Demo/Info.plist
  17. +57 −0 Demo/RawTokenAnalyzerViewController.swift
  18. +72 −0 Demo/RawTokenAnalyzerViewController.xib
  19. +67 −0 Demo/ResolvedTokenAnalyzerViewController.swift
  20. +72 −0 Demo/ResolvedTokenAnalyzerViewController.xib
  21. +127 −0 Demo/VariableAnalyzerViewController.swift
  22. +126 −0 Demo/VariableAnalyzerViewController.xib
  23. +6 −6 MathParser/{NumberExtractor.swift → DecimalNumberExtractor.swift}
  24. +2 −2 MathParser/ExponentExtractor.swift
  25. +4 −8 MathParser/Expressionizer.swift
  26. +6 −6 MathParser/{SpecialNumberExtractor.swift → FractionNumberExtractor.swift}
  27. +12 −12 MathParser/Functions+Defaults.swift
  28. +3 −3 MathParser/HexNumberExtractor.swift
  29. +3 −3 MathParser/IdentifierExtractor.swift
  30. +2 −4 MathParser/LocalizedNumberExtractor.swift
  31. +6 −0 MathParser/MathParserErrors.swift
  32. +3 −3 MathParser/OctalNumberExtractor.swift
  33. +3 −3 MathParser/OperatorExtractor.swift
  34. +2 −2 MathParser/OperatorTokenSet.swift
  35. +4 −4 MathParser/QuotedVariableExtractor.swift
  36. +16 −15 MathParser/RawToken.swift
  37. +4 −22 MathParser/ResolvedToken.swift
  38. +2 −2 MathParser/TokenCharacterBuffer.swift
  39. +1 −1 MathParser/TokenExtractor.swift
  40. +1 −1 MathParser/TokenGrouper.swift
  41. +0 −75 MathParser/TokenIterator.swift
  42. +23 −24 MathParser/TokenResolver.swift
  43. +57 −2 MathParser/Tokenizer.swift
  44. +4 −4 MathParser/VariableExtractor.swift
  45. +9 −0 MathParserTests/EvaluatorTests.swift
  46. +22 −5 MathParserTests/GithubIssues.swift
  47. +1 −1 MathParserTests/TestHelpers.swift
  48. +45 −46 MathParserTests/TokenizerTests.swift

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0800"
+ LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,8 +26,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- shouldUseLaunchSchemeArgsEnv = "YES"
- codeCoverageEnabled = "YES">
+ codeCoverageEnabled = "YES"
+ shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
@@ -0,0 +1,75 @@
+//
+// AnalyzerFlowViewController.swift
+// Demo
+//
+// Created by Dave DeLong on 11/21/17.
+//
+
+import Cocoa
+import MathParser
+
+class AnalyzerFlowViewController: AnalyzerViewController, AnalyzerDelegate, NSTabViewDelegate {
+
+ @IBOutlet var tabView: NSTabView?
+
+ private var analyzers = Array<AnalyzerViewController>()
+ private var currentAnalyzedString = ""
+ private var currentAnalyzer: AnalyzerViewController?
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+ // Do view setup here.
+
+ while let item = tabView?.tabViewItems.first {
+ tabView?.removeTabViewItem(item)
+ }
+
+ analyzers = [
+ RawTokenAnalyzerViewController(),
+ ResolvedTokenAnalyzerViewController(),
+ GroupedTokenAnalyzerViewController(),
+ ExpressionAnalyzerViewController(),
+ VariableAnalyzerViewController()
+ ]
+
+ for analyzer in analyzers {
+ analyzer.analyzerDelegate = self
+ let item = NSTabViewItem(viewController: analyzer)
+ tabView?.addTabViewItem(item)
+ }
+
+ tabView?.selectTabViewItem(at: 0)
+ handleSwitchToAnalyzer(analyzers[0])
+ }
+
+ override func analyzeString(_ string: String) {
+ currentAnalyzedString = string
+ analyzerDelegate?.analyzerViewController(self, wantsHighlightedRanges: [])
+ analyzerDelegate?.analyzerViewController(self, wantsErrorPresented: nil)
+ currentAnalyzer?.analyzeString(string)
+ }
+
+ private func handleSwitchToAnalyzer(_ analyzer: AnalyzerViewController) {
+ currentAnalyzer = analyzer
+ analyzerDelegate?.analyzerViewController(self, wantsHighlightedRanges: [])
+ analyzerDelegate?.analyzerViewController(self, wantsErrorPresented: nil)
+ analyzer.analyzeString(currentAnalyzedString)
+ }
+
+ func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
+ guard let vc = tabViewItem?.viewController else { return }
+ guard let analyzer = vc as? AnalyzerViewController else { return }
+ handleSwitchToAnalyzer(analyzer)
+ }
+
+ func analyzerViewController(_ analyzer: AnalyzerViewController, wantsHighlightedRanges ranges: Array<Range<Int>>) {
+ guard analyzer == currentAnalyzer else { return }
+ analyzerDelegate?.analyzerViewController(self, wantsHighlightedRanges: ranges)
+ }
+
+ func analyzerViewController(_ analyzer: AnalyzerViewController, wantsErrorPresented error: MathParserError?) {
+ guard analyzer == currentAnalyzer else { return }
+ analyzerDelegate?.analyzerViewController(self, wantsErrorPresented: error)
+ }
+
+}
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13529"/>
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+ </dependencies>
+ <objects>
+ <customObject id="-2" userLabel="File's Owner" customClass="AnalyzerFlowViewController" customModule="Demo" customModuleProvider="target">
+ <connections>
+ <outlet property="tabView" destination="F47-tz-4dT" id="wcl-ke-dE7"/>
+ <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
+ </connections>
+ </customObject>
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+ <customView id="Hz6-mo-xeY">
+ <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <subviews>
+ <tabView translatesAutoresizingMaskIntoConstraints="NO" id="F47-tz-4dT">
+ <rect key="frame" x="-7" y="-10" width="494" height="288"/>
+ <font key="font" metaFont="system"/>
+ <tabViewItems>
+ <tabViewItem label="Tab" identifier="" id="5fg-L6-x4k">
+ <view key="view" id="5Va-za-mco">
+ <rect key="frame" x="10" y="33" width="474" height="242"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ </view>
+ </tabViewItem>
+ <tabViewItem label="View" identifier="" id="07B-Fq-NzN">
+ <view key="view" id="02V-W9-6OY">
+ <rect key="frame" x="10" y="33" width="157" height="78"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ </view>
+ </tabViewItem>
+ </tabViewItems>
+ <connections>
+ <outlet property="delegate" destination="-2" id="94f-0H-3Zo"/>
+ </connections>
+ </tabView>
+ </subviews>
+ <constraints>
+ <constraint firstItem="F47-tz-4dT" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="AaL-Tb-stR"/>
+ <constraint firstAttribute="bottom" secondItem="F47-tz-4dT" secondAttribute="bottom" id="Fmk-9Z-e49"/>
+ <constraint firstAttribute="trailing" secondItem="F47-tz-4dT" secondAttribute="trailing" id="ZbV-4C-OXE"/>
+ <constraint firstItem="F47-tz-4dT" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="nOG-Mx-ic3"/>
+ </constraints>
+ <point key="canvasLocation" x="-37" y="161"/>
+ </customView>
+ </objects>
+</document>
@@ -0,0 +1,33 @@
+//
+// AnalyzerViewController.swift
+// Demo
+//
+// Created by Dave DeLong on 11/21/17.
+//
+
+import Cocoa
+import MathParser
+
+protocol AnalyzerDelegate: class {
+
+ func analyzerViewController(_ analyzer: AnalyzerViewController, wantsHighlightedRanges ranges: Array<Range<Int>>)
+ func analyzerViewController(_ analyzer: AnalyzerViewController, wantsErrorPresented error: MathParserError?)
+}
+
+class AnalyzerViewController: NSViewController {
+
+ weak var analyzerDelegate: AnalyzerDelegate?
+
+ init() {
+ let nibName = NSNib.Name(rawValue: "\(type(of: self))")
+ let bundle = Bundle(for: type(of: self))
+ super.init(nibName: nibName, bundle: bundle)
+ }
+
+ required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
+
+ func analyzeString(_ string: String) {
+ fatalError("Subclasses must override \(#function)")
+ }
+
+}
View
@@ -0,0 +1,29 @@
+//
+// AppDelegate.swift
+// Demo
+//
+// Created by Dave DeLong on 11/20/17.
+//
+
+import Cocoa
+import MathParser
+
+@NSApplicationMain
+class AppDelegate: NSObject, NSApplicationDelegate {
+
+ var demoWindow: NSWindowController?
+
+ func applicationDidFinishLaunching(_ aNotification: Notification) {
+ // Insert code here to initialize your application
+
+ let window = NSWindow(contentViewController: DemoViewController())
+ window.title = "Demo"
+ demoWindow = NSWindowController(window: window)
+ demoWindow?.showWindow(self)
+ }
+
+ func applicationWillTerminate(_ aNotification: Notification) {
+ // Insert code here to tear down your application
+ }
+}
+
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
Oops, something went wrong.

0 comments on commit 0f2e856

Please sign in to comment.