JavaScript Highlighter: Fix numbers starting with dot
This commit is contained in:
parent
7b54a18bcc
commit
7b090bcb4a
|
@ -295,8 +295,19 @@ class JavaScriptHighlighter {
|
||||||
|
|
||||||
private func consumeDotLookup() {
|
private func consumeDotLookup() {
|
||||||
consume() // .
|
consume() // .
|
||||||
print("Dot lookup")
|
guard let char = peek() else { return }
|
||||||
emit(token: .punctuation, range: prevCharRange())
|
if identifierStarts.contains(char) {
|
||||||
|
print("Dot lookup")
|
||||||
|
emit(token: .punctuation, range: prevCharRange())
|
||||||
|
consumeIdentifier()
|
||||||
|
} else if CharacterSet.decimalDigits.contains(char) {
|
||||||
|
let numberStart = text.index(before: currentIndex)
|
||||||
|
while let char = peek(), CharacterSet.decimalDigits.contains(char) {
|
||||||
|
consume()
|
||||||
|
}
|
||||||
|
print("Number: \(text[numberStart..<currentIndex])")
|
||||||
|
emit(token: .number, range: range(from: numberStart, to: currentIndex))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func consumeArray() {
|
private func consumeArray() {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
let source = "`$foo ${blah} bar`"
|
let source = ".1 + .2"
|
||||||
let highlighter = JavaScriptHighlighter(text: source)
|
let highlighter = JavaScriptHighlighter(text: source)
|
||||||
highlighter.debug = true
|
highlighter.debug = true
|
||||||
highlighter.highlight()
|
highlighter.highlight()
|
||||||
|
|
Loading…
Reference in New Issue