You can partly achieve this for double quoted strings with the raw string call 
syntax:
    
    
    import unicode
    
    template u(s: string): seq[Rune] =
      toRunes(s)
    
    echo u"abcd"
    
    
    Run

I don't think you can do the same with single quoted strings, however you can 
define a very simple macro that turns it into a character literal.
    
    
    import unicode, macros
    
    macro uc(s: string{lit}): untyped =
      result = newCall(bindSym("Rune"), newLit(s.strVal[0]))
    
    echo uc"a"
    
    
    Run

If you want your character literal to be able to be more than 1 ASCII character 
you can use compile time evaluation:
    
    
    import unicode, macros
    
    macro uc(s: string{lit}): untyped =
      result = newCall(bindSym("Rune"), newLit(runeAt(s.strVal, 0).int16))
    
    echo uc"漢"
    
    
    Run

Reply via email to