@@ -35,7 +35,7 @@ protected SyntaxToken(IReadOnlyList<Diagnostic> diagnostics)
3535 public virtual object Value => this . Text ;
3636
3737 /// <summary>
38- /// The text of the literal value (does not include type prefixes/quotes)
38+ /// The text of the literal without prefix, parentheses or encoding.
3939 /// </summary>
4040 public virtual string ValueText => this . Text ;
4141
@@ -151,7 +151,7 @@ public SyntaxToken GetPreviousToken(bool includeZeroWidthTokens = false)
151151 return GetPreviousToken ( null , this , includeZeroWidthTokens ) ;
152152 }
153153
154- public static SyntaxToken From ( Parsing . LexicalToken token , Diagnostic diagnostic = null )
154+ public static SyntaxToken From ( LexicalToken token , Diagnostic diagnostic = null )
155155 {
156156 var dx = token . Diagnostics ;
157157 if ( diagnostic != null )
@@ -385,32 +385,6 @@ public override object Value
385385 }
386386 }
387387
388- private string valueText ;
389-
390- public override string ValueText
391- {
392- get
393- {
394- if ( this . valueText == null )
395- {
396- if ( GetPrefixLength ( this . Text ) > 0 )
397- {
398- this . valueText = GetValueText ( this . Text ) ;
399- }
400- else if ( this . Kind == SyntaxKind . StringLiteralToken )
401- {
402- this . valueText = ( string ) this . Value ;
403- }
404- else
405- {
406- this . valueText = this . Text ;
407- }
408- }
409-
410- return valueText ;
411- }
412- }
413-
414388 private object GetValue ( )
415389 {
416390 if ( this . Kind != SyntaxKind . StringLiteralToken
@@ -445,6 +419,43 @@ private object GetValue()
445419 }
446420 }
447421
422+ private string valueText ;
423+
424+ public override string ValueText
425+ {
426+ get
427+ {
428+ if ( this . valueText == null )
429+ {
430+ this . valueText = GetValueText ( ) ;
431+ }
432+
433+ return valueText ;
434+ }
435+ }
436+
437+ private string GetValueText ( )
438+ {
439+ switch ( this . Kind )
440+ {
441+ case SyntaxKind . BooleanLiteralToken :
442+ case SyntaxKind . IntLiteralToken :
443+ case SyntaxKind . LongLiteralToken :
444+ case SyntaxKind . RealLiteralToken :
445+ case SyntaxKind . DecimalLiteralToken :
446+ return GetInteriorText ( text ) ;
447+ case SyntaxKind . TimespanLiteralToken :
448+ case SyntaxKind . DateTimeLiteralToken :
449+ case SyntaxKind . GuidLiteralToken :
450+ case SyntaxKind . RawGuidLiteralToken :
451+ return Destringify ( GetInteriorText ( text ) ) ;
452+ case SyntaxKind . StringLiteralToken :
453+ return ( string ) this . Value ;
454+ default :
455+ throw new InvalidOperationException ( $ "Unhandled literal syntax kind: { this . Kind } ") ;
456+ }
457+ }
458+
448459 public override string Prefix
449460 {
450461 get
@@ -495,7 +506,7 @@ private static void GetValueSpan(string text, out int start, out int length)
495506 start = prefixLen + 1 ; // include (
496507
497508 // trim leading whitespace
498- while ( start < text . Length && Parsing . TextFacts . IsWhitespace ( text [ start ] ) )
509+ while ( start < text . Length && TextFacts . IsWhitespace ( text [ start ] ) )
499510 start ++ ;
500511
501512 if ( text . EndsWith ( ")" ) )
@@ -504,22 +515,35 @@ private static void GetValueSpan(string text, out int start, out int length)
504515 }
505516
506517 // trim trailing whitespace
507- while ( end > start + 1 && Parsing . TextFacts . IsWhitespace ( text [ end - 1 ] ) )
518+ while ( end > start + 1 && TextFacts . IsWhitespace ( text [ end - 1 ] ) )
508519 end -- ;
509520 }
510521
511522 length = end - start ;
512523 }
513524
514- private static string GetValueText ( string text )
525+ private static string GetInteriorText ( string text )
515526 {
516527 int start ;
517528 int length ;
518529 GetValueSpan ( text , out start , out length ) ;
519530
520531 return ( start == 0 && length == text . Length )
521532 ? text
522- : text . Substring ( start , length ) ;
533+ : Destringify ( text . Substring ( start , length ) ) ;
534+ }
535+
536+ /// <summary>
537+ /// Returns the string literal value if the text is a string literal, otherwise just the text itself.
538+ /// </summary>
539+ private static string Destringify ( string text )
540+ {
541+ var trimmed = text . Trim ( ) ;
542+
543+ // if the interior text is a string literal, then decode it.
544+ return ( trimmed . Length >= 2 && TokenParser . ScanStringLiteral ( trimmed ) == trimmed . Length )
545+ ? KustoFacts . GetStringLiteralValue ( trimmed )
546+ : text ;
523547 }
524548
525549 private static bool IsNull ( string text )
@@ -542,13 +566,13 @@ private static object GetBooleanValue(string text)
542566 }
543567 else
544568 {
545- return null ;
569+ return false ;
546570 }
547571 }
548572
549- private static int GetIntValue ( string text )
573+ private static int ? GetIntValue ( string text )
550574 {
551- var valueText = GetValueText ( text ) ;
575+ var valueText = GetInteriorText ( text ) ;
552576 switch ( valueText )
553577 {
554578 case "min" :
@@ -564,7 +588,7 @@ private static int GetIntValue(string text)
564588
565589 private static long GetLongValue ( string text )
566590 {
567- var valueText = GetValueText ( text ) ;
591+ var valueText = GetInteriorText ( text ) ;
568592 switch ( valueText )
569593 {
570594 case "min" :
@@ -580,7 +604,7 @@ private static long GetLongValue(string text)
580604
581605 private static double GetRealValue ( string text )
582606 {
583- var valueText = GetValueText ( text ) ;
607+ var valueText = GetInteriorText ( text ) ;
584608 switch ( valueText )
585609 {
586610 case "min" :
@@ -596,7 +620,7 @@ private static double GetRealValue(string text)
596620
597621 private static decimal GetDecimalValue ( string text )
598622 {
599- var valueText = GetValueText ( text ) ;
623+ var valueText = GetInteriorText ( text ) ;
600624 switch ( valueText )
601625 {
602626 case "min" :
@@ -612,7 +636,7 @@ private static decimal GetDecimalValue(string text)
612636
613637 private static TimeSpan GetTimeSpanValue ( string text )
614638 {
615- var valueText = GetValueText ( text ) ;
639+ var valueText = Destringify ( GetInteriorText ( text ) ) ;
616640
617641#if ! BRIDGE
618642 TimeSpan result ;
@@ -695,7 +719,7 @@ private static TimeSpan GetTimeSpanValue(string text)
695719
696720 private static DateTime GetDateTimeValue ( string text )
697721 {
698- var valueText = GetValueText ( text ) ;
722+ var valueText = Destringify ( GetInteriorText ( text ) ) ;
699723 switch ( valueText )
700724 {
701725 case "min" :
@@ -711,7 +735,7 @@ private static DateTime GetDateTimeValue(string text)
711735
712736 private static Guid GetGuidValue ( string text )
713737 {
714- var valueText = GetValueText ( text ) ;
738+ var valueText = Destringify ( GetInteriorText ( text ) ) ;
715739 Guid result ;
716740 Guid . TryParse ( valueText , out result ) ;
717741 return result ;
0 commit comments