Skip to content

Commit 7a0224c

Browse files
Escape ' in generated dbscheme names
`escape_name` maps `"` to `dquote` but leaves `'` untouched, so a grammar whose node types contain a single quote generates an invalid dbscheme identifier. Lua hits this: its `string` node has `'` as a delimiter token, and the generator emits `@lua_string_'`, which the dbscheme parser rejects with ERROR: token recognition error at: ''' No shipped language contains a bare `'` in a node type, which is why this has not surfaced before. Found while building an out-of-tree extractor. Adds the missing mapping and a test covering both string delimiters.
1 parent a281f7c commit 7a0224c

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎shared/tree-sitter-extractor/src/node_types.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ fn escape_name(name: &str) -> String {
386386
':' => result.push_str("colon"),
387387
';' => result.push_str("semicolon"),
388388
'"' => result.push_str("dquote"),
389+
'\'' => result.push_str("squote"),
389390
'*' => result.push_str("star"),
390391
'+' => result.push_str("plus"),
391392
'-' => result.push_str("minus"),
@@ -448,6 +449,14 @@ fn dbscheme_name_to_class_name(dbscheme_name: &str) -> String {
448449
.join("")
449450
}
450451

452+
#[test]
453+
fn escape_name_quotes_test() {
454+
// Both string delimiters need a name: a grammar whose node types contain
455+
// `'` used to produce the invalid dbscheme identifier `@lang_string_'`.
456+
assert_eq!("dquote", escape_name("\""));
457+
assert_eq!("squote", escape_name("'"));
458+
}
459+
451460
#[test]
452461
fn to_snake_case_test() {
453462
assert_eq!("ruby", to_snake_case("Ruby"));

0 commit comments

Comments
 (0)