JavaScript Highlighter: fix parsing multiple subexpressions in the same array element

This commit is contained in:
Shadowfacts 2020-04-05 13:50:00 -04:00
부모 7b090bcb4a
커밋 cc9e21be16
로그인 계정: shadowfacts
GPG 키 ID: 94A5AB95422746E5
2개의 변경된 파일11개의 추가작업 그리고 14개의 파일을 삭제

파일 보기

@ -316,21 +316,18 @@ class JavaScriptHighlighter {
emit(token: .punctuation, range: prevCharRange())
indent += " "
array:
while currentIndex < text.endIndex && peek() != "]" {
while currentIndex < text.endIndex {
consumeWhitespace()
while currentIndex < text.endIndex {
if peek() == "," {
consume() // ,
print("Array separator")
emit(token: .punctuation, range: prevCharRange())
break
} else if peek() == "]" {
break array
} else {
indent += " "
print("Array element")
if peek() == "," {
consume() // ,
print("Array separator")
emit(token: .punctuation, range: prevCharRange())
} else if peek() == "]" {
break array
} else {
print("Array element")
while let char = peek(), char != ",", char != "]" {
consumeExpression()
indent = String(indent.dropLast(2))
}
}
}

파일 보기

@ -8,7 +8,7 @@
import Foundation
let source = ".1 + .2"
let source = "[1 + 2, 3,]"
let highlighter = JavaScriptHighlighter(text: source)
highlighter.debug = true
highlighter.highlight()