Skip to content

Commit fcd423f

Browse files
authored
fix double-casing pascal identifiers (#1403)
Context: https://github.com/NomicFoundation/slang/pull/1388/files/d3dae389c231441b4ba9a684b4be3b7c5dca73fd#r2248599409 > Looks like a few places in the codebase were converting already PascalCase identifiers, which will override the capitalization in the grammar like this. Luckily, fixing it doesn't break existing source code, so we can just do it. I submitted #1403 with the fixes.
1 parent d1b2aea commit fcd423f

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

crates/codegen/runtime/cargo/crate/src/ir/builder.rs.jinja2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,18 @@
7474
let variant = helper.accept_label(EdgeLabel::Variant)?;
7575
let item = match variant.kind() {
7676
{% for type in choice.nonterminal_types -%}
77-
NodeKind::Nonterminal(NonterminalKind::{{ type }}) => {{ parent_type }}::{{ type | pascal_case }}(build_{{ type | snake_case }}(nonterminal_node(variant))?),
77+
NodeKind::Nonterminal(NonterminalKind::{{ type }}) => {{ parent_type }}::{{ type }}(build_{{ type | snake_case }}(nonterminal_node(variant))?),
7878
{%- endfor -%}
7979

8080
{% for type in choice.non_unique_terminal_types -%}
8181
NodeKind::Terminal(TerminalKind::{{ type }}) => {
82-
{{ parent_type }}::{{ type | pascal_case }}(terminal_node_cloned(variant))
82+
{{ parent_type }}::{{ type }}(terminal_node_cloned(variant))
8383
},
8484
{%- endfor -%}
8585

8686
{% for type in choice.unique_terminal_types -%}
8787
NodeKind::Terminal(TerminalKind::{{ type }}) => {
88-
{{ parent_type }}::{{ type | pascal_case }}
88+
{{ parent_type }}::{{ type }}
8989
},
9090
{%- endfor -%}
9191

crates/codegen/runtime/cargo/crate/src/ir/nodes.rs.jinja2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
{%- endif -%}
2727
{%- else -%}
2828
{%- if field.is_optional -%}
29-
Option<{{ field.type | pascal_case }}>,
29+
Option<{{ field.type }}>,
3030
{%- else -%}
31-
{{ field.type | pascal_case }},
31+
{{ field.type }},
3232
{%- endif -%}
3333
{%- endif -%}
3434
{% endfor -%}
@@ -44,7 +44,7 @@
4444
#[derive(Debug)]
4545
pub enum {{ parent_type }} {
4646
{% for nonterminal in choice.nonterminal_types -%}
47-
{{ nonterminal }}({{ nonterminal | pascal_case }}),
47+
{{ nonterminal }}({{ nonterminal }}),
4848
{%- endfor -%}
4949
{% for terminal in choice.non_unique_terminal_types -%}
5050
{{ terminal }}(Rc<TerminalNode>),
@@ -64,7 +64,7 @@
6464
{%- if collection.is_terminal -%}
6565
Rc<TerminalNode>
6666
{%- else -%}
67-
{{ collection.item_type | pascal_case }}
67+
{{ collection.item_type }}
6868
{%- endif -%}
6969
>;
7070
{% endfor %}

crates/codegen/runtime/cargo/crate/src/runtime/cst/nonterminal_kind.rs.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ pub enum NonterminalKind {
2424
Stub3,
2525
{%- else -%}
2626
{%- for variant in model.kinds.nonterminal_kinds -%}
27-
/// Represents a node with kind `{{ variant.id | pascal_case }}`, having the following structure:
27+
/// Represents a node with kind `{{ variant.id }}`, having the following structure:
2828
///
2929
/// ```ebnf
3030
{%- for line in variant.documentation | split(pat="\n") %}
3131
/// {{ line }}
3232
{%- endfor %}
3333
/// ```
34-
{{ variant.id | pascal_case }},
34+
{{ variant.id }},
3535
{%- endfor -%}
3636
{%- endif -%}
3737
}

crates/codegen/runtime/cargo/crate/src/runtime/cst/terminal_kind.rs.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ pub enum TerminalKind {
3131
Stub3,
3232
{%- else -%}
3333
{%- for variant in model.kinds.terminal_kinds -%}
34-
/// Represents a node with kind `{{ variant.id | pascal_case }}`, having the following structure:
34+
/// Represents a node with kind `{{ variant.id }}`, having the following structure:
3535
///
3636
/// ```ebnf
3737
{%- for line in variant.documentation | split(pat="\n") %}
3838
/// {{ line }}
3939
{%- endfor %}
4040
/// ```
41-
{{ variant.id | pascal_case }},
41+
{{ variant.id }},
4242
{%- endfor -%}
4343
{%- endif -%}
4444
}

crates/codegen/runtime/cargo/wasm/src/runtime/interface/cst.wit.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface cst {
1111
stub3,
1212
{%- else %}
1313
{%- for variant in model.kinds.nonterminal_kinds %}
14-
/// Represents a node with kind `{{ variant.id | pascal_case }}`, having the following structure:
14+
/// Represents a node with kind `{{ variant.id }}`, having the following structure:
1515
///
1616
/// ```ebnf
1717
{%- for line in variant.documentation | split(pat="\n") %}
@@ -42,7 +42,7 @@ interface cst {
4242
stub3,
4343
{%- else %}
4444
{%- for variant in model.kinds.terminal_kinds %}
45-
/// Represents a node with kind `{{ variant.id | pascal_case }}`, having the following structure:
45+
/// Represents a node with kind `{{ variant.id }}`, having the following structure:
4646
///
4747
/// ```ebnf
4848
{%- for line in variant.documentation | split(pat="\n") %}

crates/codegen/runtime/generator/src/parser/codegen/precedence_parser_definition.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,20 @@ pub trait PrecedenceParserDefinitionCodegen {
2020

2121
impl PrecedenceParserDefinitionCodegen for PrecedenceParserDefinitionRef {
2222
fn to_parser_code(&self) -> TokenStream {
23-
let code = self.node().to_parser_code(
24-
self.context(),
25-
format_ident!("{name}", name = self.name().to_pascal_case()),
26-
);
23+
let code = self
24+
.node()
25+
.to_parser_code(self.context(), format_ident!("{}", self.name()));
2726

2827
let nonterminal_kind = format_ident!("{}", self.name());
2928
quote! { #code.with_kind(NonterminalKind::#nonterminal_kind) }
3029
}
3130

3231
fn to_precedence_expression_parser_code(&self) -> Vec<(Identifier, TokenStream)> {
3332
let parser_name = format_ident!("{}", self.name().to_snake_case());
34-
let nonterminal_name = format_ident!("{}", self.name().to_pascal_case());
33+
let nonterminal_name = format_ident!("{}", self.name());
3534

3635
self.node().precedence_expression_names.iter().map(|name| {
37-
let op_nonterminal_name = format_ident!("{}", name.to_pascal_case());
36+
let op_nonterminal_name = format_ident!("{name}");
3837

3938
// Ensure that the parser correctly identifies a single node of the expected type,
4039
// which contains a single child node representing the expected precedence operator.

0 commit comments

Comments
 (0)