Open jellybobbin opened 2 years ago
I think the main problem is that your Tokens::Words
contains a &str
, which means it references a direct slice of the input. That's not what you want though, you want to apply transformations to the input (unescaping unicode escapes), so you'll have to copy the data into a String
.
@Xiretza
Even if I don't use it & str
, the parser returns char. When the input is escape Unicode, it cannot become a continuous string;
let input = "\"H\\u{65}llo \\u{20} rust\\n"\";
I want get:Vec[
Tokens::Words(String::from("Hello")),
Tokens::Spaces(3),
Tokens::Words(String::from("rust")),
NewLine
]
Vec[
Tokens::Words(String::from("H")),
Tokens::Words(String::from("e")),
Tokens::Words(String::from("llo")),
Tokens::Spaces(1),
Tokens::Spaces(1),
Tokens::Spaces(1),
Tokens::Words(String::from("rust")),
NewLine
]
You can do post-parsing transformations on it, for instance
let input = "\"H\\u{65}llo \\u{20} rust\\n"\";
I want this result:
Is this feasible?Here is the simple code:
I'll close it as soon as possible, thx!!!