Skip to main content

token2str

Function token2str 

Source
pub fn token2str(_ls: &LexState, token: i32) -> Vec<u8> 
Expand description

Produce a human-readable token description (for error messages and the parser).

Single-byte printable tokens are formatted as 'X'; non-printable as '<\N>'. Reserved words and multi-char symbols are formatted as 'kw'. Literal tokens (<name>, <string>, etc.) return the bare label.

§C source


//   if (token < FIRST_RESERVED) {
//     if (lisprint(token))
//       return luaO_pushfstring(ls->L, "'%c'", token);
//     else
//       return luaO_pushfstring(ls->L, "'<\\%d>'", token);
//   }
//   else {
//     const char *s = luaX_tokens[token - FIRST_RESERVED];
//     if (token < TK_EOS)
//       return luaO_pushfstring(ls->L, "'%s'", s);
//     else
//       return s;
//   }
// }

PORT NOTE: The LexState parameter is retained in the signature for API parity with the C export, but is unused in Rust because we don’t push onto the Lua stack. The real formatting is in [token2str_raw].