JavaScript Highlighter: disable debug prints by default

This commit is contained in:
Shadowfacts 2020-04-05 11:54:22 -04:00
parent 83cfba74a8
commit 7b54a18bcc
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 8 additions and 4 deletions

View File

@ -27,6 +27,7 @@ class JavaScriptHighlighter {
private var currentIndex: String.Index! private var currentIndex: String.Index!
private var indent = "" private var indent = ""
private(set) var tokens = [(token: TokenType, range: NSRange)]() private(set) var tokens = [(token: TokenType, range: NSRange)]()
var debug = false
init(text: String) { init(text: String) {
self.text = text self.text = text
@ -38,8 +39,10 @@ class JavaScriptHighlighter {
self.attributed = mutableAttributed self.attributed = mutableAttributed
} }
private func print(_ str: String) { private func print(_ str: @autoclosure () -> String) {
Swift.print("\(indent)\(str)") if debug {
Swift.print("\(indent)\(str())")
}
} }
private func range(from: String.Index, to: String.Index) -> NSRange { private func range(from: String.Index, to: String.Index) -> NSRange {

View File

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