Browse Source

JavaScript Highlighter: disable debug prints by default

master
Shadowfacts 2 months ago
parent
commit
7b54a18bcc
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5
2 changed files with 8 additions and 4 deletions
  1. 5
    2
      MongoView/Synax Highlighting/JavaScriptHighlighter.swift
  2. 3
    2
      jstest/main.swift

+ 5
- 2
MongoView/Synax Highlighting/JavaScriptHighlighter.swift View File

@@ -27,6 +27,7 @@ class JavaScriptHighlighter {
27 27
     private var currentIndex: String.Index!
28 28
     private var indent = ""
29 29
     private(set) var tokens = [(token: TokenType, range: NSRange)]()
30
+    var debug = false
30 31
     
31 32
     init(text: String) {
32 33
         self.text = text
@@ -38,8 +39,10 @@ class JavaScriptHighlighter {
38 39
         self.attributed = mutableAttributed
39 40
     }
40 41
     
41
-    private func print(_ str: String) {
42
-        Swift.print("\(indent)\(str)")
42
+    private func print(_ str: @autoclosure () -> String) {
43
+        if debug {
44
+            Swift.print("\(indent)\(str())")
45
+        }
43 46
     }
44 47
     
45 48
     private func range(from: String.Index, to: String.Index) -> NSRange {

+ 3
- 2
jstest/main.swift View File

@@ -9,5 +9,6 @@
9 9
 import Foundation
10 10
 
11 11
 let source = "`$foo ${blah} bar`"
12
-_ = JavaScriptHighlighter(text: source).highlight()
13
-
12
+let highlighter = JavaScriptHighlighter(text: source)
13
+highlighter.debug = true
14
+highlighter.highlight()

Loading…
Cancel
Save