Browse Source

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

master
Shadowfacts 1 month ago
parent
commit
cc9e21be16
Signed by: Shadowfacts <me@shadowfacts.net> 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 {
316 316
         emit(token: .punctuation, range: prevCharRange())
317 317
         indent += "  "
318 318
         array:
319
-        while currentIndex < text.endIndex && peek() != "]" {
319
+        while currentIndex < text.endIndex {
320 320
             consumeWhitespace()
321
-            while currentIndex < text.endIndex {
322
-                if peek() == "," {
323
-                    consume() // ,
324
-                    print("Array separator")
325
-                    emit(token: .punctuation, range: prevCharRange())
326
-                    break
327
-                } else if peek() == "]" {
328
-                    break array
329
-                } else {
330
-                    indent += "  "
331
-                    print("Array element")
321
+            if peek() == "," {
322
+                consume() // ,
323
+                print("Array separator")
324
+                emit(token: .punctuation, range: prevCharRange())
325
+            } else if peek() == "]" {
326
+                break array
327
+            } else {
328
+                print("Array element")
329
+                while let char = peek(), char != ",", char != "]" {
332 330
                     consumeExpression()
333
-                    indent = String(indent.dropLast(2))
334 331
                 }
335 332
             }
336 333
         }

+ 1
- 1
jstest/main.swift View File

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

Loading…
Cancel
Save