From 2524efd1d75747ed1de7e20eefe7bdf09534e6ff Mon Sep 17 00:00:00 2001 From: swananan Date: Tue, 19 May 2026 19:16:04 +0800 Subject: [PATCH] fix: allow underscore-prefixed DSL identifiers --- ghostscope-compiler/src/script/grammar.pest | 2 +- ghostscope-compiler/src/script/parser.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ghostscope-compiler/src/script/grammar.pest b/ghostscope-compiler/src/script/grammar.pest index fae1556d..a7ceb6ee 100644 --- a/ghostscope-compiler/src/script/grammar.pest +++ b/ghostscope-compiler/src/script/grammar.pest @@ -113,7 +113,7 @@ address_of = { "&" ~ ( "(" ~ expr ~ ")" | complex_variable | identifier ) } add_op = { "+" | "-" } mul_op = { "*" | "/" } -identifier = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* } +identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* } // Integer literals int = @{ ASCII_DIGIT+ } hex_int = @{ "0x" ~ ASCII_HEX_DIGIT+ } diff --git a/ghostscope-compiler/src/script/parser.rs b/ghostscope-compiler/src/script/parser.rs index 0b978735..7a00ed81 100644 --- a/ghostscope-compiler/src/script/parser.rs +++ b/ghostscope-compiler/src/script/parser.rs @@ -2058,6 +2058,23 @@ trace foo { assert!(parse(s5).is_ok()); } + #[test] + fn parse_identifiers_can_start_with_underscore() { + let function = r#"trace __UpdateTicketInformation { print "OK"; }"#; + assert!(parse(function).is_ok()); + + let wildcard = r#"trace __builtin_* { print "W"; }"#; + assert!(parse(wildcard).is_ok()); + + let script = r#" +trace _start { + let _ticket = __dwarf_value; + print _ticket; +} +"#; + assert!(parse(script).is_ok()); + } + #[test] fn parse_module_hex_address_overflow_should_error() { // Address exceeds u64 (17 hex digits) -> parse error, not 0 fallback