Browse Source

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

master
Shadowfacts 1 year ago
parent
commit
cc9e21be16
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
2 changed files with 11 additions and 14 deletions
  1. +10
    -13
      MongoView/Synax Highlighting/JavaScriptHighlighter.swift
  2. +1
    -1
      jstest/main.swift

+ 10
- 13
MongoView/Synax Highlighting/JavaScriptHighlighter.swift View File

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


+ 1
- 1
jstest/main.swift View File

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

Loading…
Cancel
Save