JavaScript Highlighter: fix parsing multiple subexpressions in the same array element
This commit is contained in:
parent
7b090bcb4a
commit
cc9e21be16
|
@ -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() != "]" {
|
|
||||||
consumeWhitespace()
|
|
||||||
while currentIndex < text.endIndex {
|
while currentIndex < text.endIndex {
|
||||||
|
consumeWhitespace()
|
||||||
if peek() == "," {
|
if peek() == "," {
|
||||||
consume() // ,
|
consume() // ,
|
||||||
print("Array separator")
|
print("Array separator")
|
||||||
emit(token: .punctuation, range: prevCharRange())
|
emit(token: .punctuation, range: prevCharRange())
|
||||||
break
|
|
||||||
} else if peek() == "]" {
|
} else if peek() == "]" {
|
||||||
break array
|
break array
|
||||||
} else {
|
} else {
|
||||||
indent += " "
|
|
||||||
print("Array element")
|
print("Array element")
|
||||||
|
while let char = peek(), char != ",", char != "]" {
|
||||||
consumeExpression()
|
consumeExpression()
|
||||||
indent = String(indent.dropLast(2))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue