@@ -40,6 +40,18 @@ handlers:
40
40
lex.kind = tkString
41
41
result = lex.kind
42
42
break
43
+ of '#' :
44
+ if lex.buf[lex.bufpos - 1 ] == ' ' :
45
+ lex.token = lex.token.strip
46
+ inc lex.bufpos
47
+ while true :
48
+ case lex.buf[lex.bufpos]
49
+ of EndOfFile , NewLines : break
50
+ else :
51
+ inc lex.bufpos
52
+ else :
53
+ add lex.token, lex.buf[lex.bufpos]
54
+ inc lex.bufpos
43
55
of ':' :
44
56
lex.kind = tkIdentifier
45
57
result = lex.kind
@@ -363,16 +375,17 @@ proc parseUnquotedStrings(p: var Parser,
363
375
proc parse (p: var Parser , inArray = false ): Node
364
376
proc parseObject (p: var Parser , this: TokenTuple , inArray = false ): Node
365
377
378
+ template checkInlineString {.dirty .} =
379
+ if p.next.kind notin {tkEOF, tkComment} and p.next.line == p.curr.line:
380
+ let this = p.curr
381
+ return p.parseUnquotedStrings (this, {tkComment})
382
+
366
383
proc parseString (p: var Parser ): Node =
384
+ checkInlineString ()
367
385
result = p.newNode String
368
386
result .vStr = p.curr.value
369
387
walk p
370
388
371
- template checkInlineString {.dirty .} =
372
- if p.next.kind notin {tkEOF, tkComment} and p.next.line == p.curr.line:
373
- let this = p.curr
374
- return p.parseUnquotedStrings (this)
375
-
376
389
proc parseInt (p: var Parser ): Node =
377
390
checkInlineString ()
378
391
result = p.newNode Int
@@ -397,10 +410,10 @@ proc parseVariable(p: var Parser, this: TokenTuple, inArray = false): Node =
397
410
walk p
398
411
if inArray:
399
412
if p.curr.line == this.line and p.curr.kind notin {tkComment, tkEOF, tkRB, tkComma}:
400
- result .varRight.add p.parseUnquotedStrings (this, {tkRB, tkComma})
413
+ result .varRight.add p.parseUnquotedStrings (this, {tkRB, tkComma, tkComment })
401
414
else :
402
415
if p.curr.line == this.line and p.curr.kind notin {tkComment, tkEOF}:
403
- result .varRight.add p.parseUnquotedStrings (this)
416
+ result .varRight.add p.parseUnquotedStrings (this, {tkComment} )
404
417
405
418
proc parseArray (p: var Parser , node: Node , this: TokenTuple ) =
406
419
while p.curr.kind == tkHyphen and p.curr.pos == node.meta.pos:
@@ -412,7 +425,7 @@ proc parseArray(p: var Parser, node: Node, this: TokenTuple) =
412
425
elif p.curr.kind == tkIdentifier:
413
426
if p.next.kind != tkColon:
414
427
# handle unquoted strings.
415
- node.items.add p.parseUnquotedStrings (this, {tkHyphen})
428
+ node.items.add p.parseUnquotedStrings (this, {tkHyphen, tkComment })
416
429
else :
417
430
# handle objects
418
431
let
@@ -450,7 +463,7 @@ proc parseInlineArray(p: var Parser, this: TokenTuple): Node =
450
463
elif p.curr.kind == tkVariable:
451
464
result .items.add p.parseVariable (this, true )
452
465
else :
453
- result .items.add p.parseUnquotedStrings (this, {tkRB, tkComma}) # todo fails to find tkRB
466
+ result .items.add p.parseUnquotedStrings (this, {tkRB, tkComma, tkComment }) # todo fails to find tkRB
454
467
if p.curr.kind == tkComma: walk p
455
468
walk p # ]
456
469
@@ -527,7 +540,7 @@ proc parseObject(p: var Parser, this: TokenTuple, inArray = false): Node =
527
540
else :
528
541
result = p.newNode (Field , this)
529
542
result .fieldKey = this.value
530
- result .fieldValue.add p.parseUnquotedStrings (this)
543
+ result .fieldValue.add p.parseUnquotedStrings (this, {tkComment} )
531
544
else :
532
545
result = p.newNode (Object , this)
533
546
result .key = this.value
0 commit comments