Skip to content

Conversation

Gashmob
Copy link

@Gashmob Gashmob commented May 9, 2025

With a grammar like this:

rule: (VAL | VAR {
        is_constant = false;
    }) name=IDENTIFIER (COLON type {
        type_name = $type.text; <-- we look this line
    })? (EQ value=expression {
        value = $value.tree;
    })?

When generating for Cpp target we get this specific result:

type_name = (antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext != nullptr ? _input->getText(antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->start, antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->stop) : nullptr);

If input doesn't match the type branch then we fallback on nullptr. As of cpp23 standard this line doesn't compile as it waits for std::string.

AS Token::getText returns std::string, then fallback value should be empty string

@Gashmob Gashmob force-pushed the 4777_cpp_rule_text branch from f2e213b to f0ed454 Compare May 9, 2025 18:56
@ericvergnaud
Copy link
Contributor

@Gashmob can you touch this PR in order to re-run the CI ?

With a grammar like this:

```antlr
rule: (VAL | VAR {
        is_constant = false;
    }) name=IDENTIFIER (COLON type {
        type_name = $type.text; <-- we look this line
    })? (EQ value=expression {
        value = $value.tree;
    })?
```

When generating for Cpp target we get this specific result:

```cpp
type_name = (antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext != nullptr ? _input->getText(antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->start, antlrcpp::downCast<Variable_declarationContext *>(_localctx)->typeContext->stop) : nullptr);
```

If input doesn't match the `type` branch then we fallback on nullptr. As
of cpp23 standard this line doesn't compile as it waits for
`std::string`.

AS `Token::getText` returns `std::string`, then fallback value should be
empty string

Signed-off-by: Kevin Traini <[email protected]>
@Gashmob Gashmob force-pushed the 4777_cpp_rule_text branch from f0ed454 to 4808a13 Compare June 25, 2025 19:01
@Gashmob
Copy link
Author

Gashmob commented Oct 10, 2025

Up, this issue blocks one of my project, did you know when it is planned for review and merge ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants