mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-11-05 04:51:40 +03:00
Support longer and shorter escape sequences
This commit is contained in:
parent
eef36e6b3b
commit
1fa587400d
@ -36,7 +36,7 @@ pub enum Token {
|
||||
#[regex(r#""([^"\\]|\\t|\\u|\\n|\\")*""#, |lex| normalized_string(lex).ok())]
|
||||
Str(String),
|
||||
|
||||
#[regex(r#"'(.|\\t|\\u[0-9a-fA-F]{4}|\\n|\\')'"#, normalized_char)]
|
||||
#[regex(r#"'(.|\\t|\\u[0-9a-fA-F]{1,8}|\\n|\\')'"#, normalized_char)]
|
||||
Char(u64),
|
||||
|
||||
#[token("#")]
|
||||
@ -145,7 +145,7 @@ fn normalized_string(lexer: &mut Lexer<Token>) -> Result<String, ParseIntError>
|
||||
Some('n') => s.push('\n'),
|
||||
Some('t') => s.push('\t'),
|
||||
Some('u') => {
|
||||
let hex = chars.take(4).collect::<String>();
|
||||
let hex = chars.take(8).collect::<String>();
|
||||
let hex_val = u32::from_str_radix(&hex, 16)?;
|
||||
let char = char::from_u32(hex_val).unwrap_or(char::REPLACEMENT_CHARACTER);
|
||||
s.push(char);
|
||||
@ -219,7 +219,7 @@ fn normalized_char(lexer: &mut Lexer<Token>) -> Option<u64> {
|
||||
Some('t') => '\t',
|
||||
Some('\'') => '\'',
|
||||
Some('u') => {
|
||||
let hex = chars.take(4).collect::<String>();
|
||||
let hex = chars.take(8).collect::<String>();
|
||||
let hex_val = u32::from_str_radix(&hex, 16).unwrap();
|
||||
char::from_u32(hex_val).unwrap_or(char::REPLACEMENT_CHARACTER)
|
||||
}
|
||||
|
1
tests/golden_tests/run_file/world.hvm
Normal file
1
tests/golden_tests/run_file/world.hvm
Normal file
@ -0,0 +1 @@
|
||||
main = (1, @#str s ('\u1F30E', s))
|
5
tests/snapshots/run_file__world.hvm.snap
Normal file
5
tests/snapshots/run_file__world.hvm.snap
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/run_file/world.hvm
|
||||
---
|
||||
"🌎"
|
Loading…
Reference in New Issue
Block a user