src/sys/dotnet/fanx/serial/Tokenizer.cs
/// <summary>
/// Parse an escapse sequence which starts with a \
/// </summary>
Parse an escapse sequence which starts with a \
Parse an escapse sequence which starts with a \
char escape()
    {
      if (cur != '\\') throw err("Internal error");
      consume();
      switch (cur)
      {
        case 'b':   consume(); return '\b';
        case 'f':   consume(); return '\f';
        case 'n':   consume(); return '\n';
        case 'r':   consume(); return '\r';
        case 't':   consume(); return '\t';
        case '$':   consume(); return '$';
        case '"':   consume(); return '"';
        case '\'':  consume(); return '\'';
        case '`':   consume(); return '`';
        case '\\':  consume(); return '\\';
      }
      if (cur == 'u')
      {
        consume();
        int n3 = hex(cur); consume();
        int n2 = hex(cur); consume();
        int n1 = hex(cur); consume();
        int n0 = hex(cur); consume();
        if (n3 < 0 || n2 < 0 || n1 < 0 || n0 < 0) throw err("Invalid hex value for \\uxxxx");
        return (char)((n3 << 12) | (n2 << 8) | (n1 << 4) | n0);
      }
      throw err("Invalid escape sequence");
    }
char escape ( ) { if ( cur != ' \\ ' ) throw err ( " " ) ; consume ( ) ; switch ( cur ) { case ' ' : consume ( ) ; return ' \b ' ; case ' ' : consume ( ) ; return ' \f ' ; case ' ' : consume ( ) ; return ' \n ' ; case ' ' : consume ( ) ; return ' \r ' ; case ' ' : consume ( ) ; return ' \t ' ; case ' ' : consume ( ) ; return ' ' ; case ' ' : consume ( ) ; return ' ' ; case ' \' ' : consume ( ) ; return ' \' ' ; case ' ' : consume ( ) ; return ' ' ; case ' \\ ' : consume ( ) ; return ' \\ ' ; } if ( cur == ' ' ) { consume ( ) ; int n3 = hex ( cur ) ; consume ( ) ; int n2 = hex ( cur ) ; consume ( ) ; int n1 = hex ( cur ) ; consume ( ) ; int n0 = hex ( cur ) ; consume ( ) ; if ( n3 < 0 || n2 < 0 || n1 < 0 || n0 < 0 ) throw err ( " \\ " ) ; return ( char ) ( ( n3 << 12 ) | ( n2 << 8 ) | ( n1 << 4 ) | n0 ) ; } throw err ( " " ) ; }
Parse an escapse sequence which starts with a \
Parse an escapse sequence which starts with a \
// consume slash // check basics // check for uxxxx