langium icon indicating copy to clipboard operation
langium copied to clipboard

Comment not extracted from first alternative

Open ydaveluy opened this issue 1 year ago • 0 comments

When defining a grammar with some alternatives, the first alternative comment is not properly extracted

Langium version: 3.1 Package name: langium

Steps To Reproduce

  1. Define this rule in the grammar:
Test returns string:
    /** comment 1 */ 'A' | /** comment 2 */  'B' | /** comment 3 */ 'C';
  1. Check the generated grammar.ts
...
    {
      "$type": "ParserRule",
      "name": "Test",
      "dataType": "string",
      "definition": {
        "$type": "Alternatives",
        "elements": [
          {
            "$type": "Keyword",
            "value": "A"
          },
          {
            "$type": "Keyword",
            "value": "B",
            "$comment": "/**comment 2 */"
          },
          {
            "$type": "Keyword",
            "value": "C",
            "$comment": "/** comment 3 */"
          }
        ]
      },
      "definesHiddenTokens": false,
      "entry": false,
      "fragment": false,
      "hiddenTokens": [],
      "parameters": [],
      "wildcard": false
    },
...

The current behavior

comment 1 is not extracted from the grammar. comment 2 and comment 3 are properly extracted.

The expected behavior

comment 1 should be extracted from the grammar.

...
    {
      "$type": "ParserRule",
      "name": "Test",
      "dataType": "string",
      "definition": {
        "$type": "Alternatives",
        "elements": [
          {
            "$type": "Keyword",
            "value": "A",
            "$comment": "/**comment 1 */"
          },
          {
            "$type": "Keyword",
            "value": "B",
            "$comment": "/**comment 2 */"
          },
          {
            "$type": "Keyword",
            "value": "C",
            "$comment": "/** comment 3 */"
          }
        ]
      },
      "definesHiddenTokens": false,
      "entry": false,
      "fragment": false,
      "hiddenTokens": [],
      "parameters": [],
      "wildcard": false
    },
...

ydaveluy avatar Aug 25 '24 09:08 ydaveluy