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
parent 7b090bcb4a
commit cc9e21be16
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 11 additions and 14 deletions

View File

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

View File

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