JavaScript Highlighter: Fix numbers starting with dot

This commit is contained in:
Shadowfacts 2020-04-05 12:12:26 -04:00
parent 7b54a18bcc
commit 7b090bcb4a
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 14 additions and 3 deletions

View File

@ -295,8 +295,19 @@ class JavaScriptHighlighter {
private func consumeDotLookup() { private func consumeDotLookup() {
consume() // . consume() // .
guard let char = peek() else { return }
if identifierStarts.contains(char) {
print("Dot lookup") print("Dot lookup")
emit(token: .punctuation, range: prevCharRange()) 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() {

View File

@ -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()