diff --git a/ghostscope-compiler/src/script/grammar.pest b/ghostscope-compiler/src/script/grammar.pest index fae1556..a7ceb6e 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 0b97873..7a00ed8 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