Skip to content

Commit 1578635

Browse files
authored
extend label to take number segments (#2372)
1 parent 37f05db commit 1578635

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

crates/wasm-wave/src/lex.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub type Lexer<'source> = logos::Lexer<'source, Token>;
1212
#[logos(error = Option<Span>)]
1313
#[logos(skip r"[ \t\n\r]+")]
1414
#[logos(skip r"//[^\n]*")]
15-
#[logos(subpattern label_word = r"[a-z][a-z0-9]*|[A-Z][A-Z0-9]*")]
15+
#[logos(subpattern first_label_word = r"[a-z][a-z0-9]*|[A-Z][A-Z0-9]*")]
16+
#[logos(subpattern label_word = r"[a-z0-9]+|[A-Z0-9]+")]
1617
#[logos(subpattern char_escape = r#"\\['"tnr\\]|\\u\{[0-9a-fA-F]{1,6}\}"#)]
1718
pub enum Token {
1819
/// The `{` symbol
@@ -50,7 +51,7 @@ pub enum Token {
5051
Number,
5152

5253
/// A label or keyword
53-
#[regex(r"%?(?&label_word)(-(?&label_word))*")]
54+
#[regex(r"%?(?&first_label_word)(-(?&label_word))*")]
5455
LabelOrKeyword,
5556

5657
/// A char literal

crates/wasm-wave/src/parser.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,21 @@ mod tests {
591591

592592
#[test]
593593
fn parse_percent_identifiers() {
594-
let ty = Type::record([("red", Type::S32), ("green", Type::CHAR)]).unwrap();
594+
let ty = Type::record([
595+
("red", Type::S32),
596+
("green", Type::CHAR),
597+
("color-42-2A-5d", Type::BOOL),
598+
])
599+
.unwrap();
595600
// Test identifiers with '%' prefixes.
596601
assert_eq!(
597-
parse_value("{ %red: 0, %green: 'a' }", &ty),
602+
parse_value("{ %red: 0, %green: 'a', %color-42-2A-5d: true }", &ty),
598603
Value::make_record(
599604
&ty,
600605
[
601606
("red", Value::make_s32(0)),
602-
("green", Value::make_char('a'))
607+
("green", Value::make_char('a')),
608+
("color-42-2A-5d", Value::make_bool(true))
603609
]
604610
)
605611
.unwrap()

0 commit comments

Comments
 (0)