langium icon indicating copy to clipboard operation
langium copied to clipboard

getAllReachableRules should return implicit ID rule

Open cdietrich opened this issue 2 years ago • 1 comments

getAllReachableRules should return implicit ID rule but currently does not. this leads to error initializing a parser based on a imported grammar that only uses rules that call ID implicitely

grammar-util.test.ts

test('ID implicit called should be returned by getAllReachableRules', async () => {
        // [A] is short for [A:ID] thus the ID rule is needed by the parser and getAllReachableRules should return it
        const input = `
            grammar HelloWorld

            entry Model: A|B;
            A: name=STRING;
            B: ref=[A];
            terminal ID: /[_a-zA-Z][\w_]*/;
            terminal STRING: /"(\\.|[^"\\])*"|'(\\.|[^'\\])*'/;
        `;
        const output = await parse(input);

        // act
        const reachableRules = [...getAllReachableRules(output.parseResult.value, true)].map(r => r.name);

        // assert
        expect(reachableRules).toContain('ID');
        // currently fails with AssertionError: expected [ 'Model', 'A', 'B', 'STRING' ] to include 'ID'
    });

cdietrich avatar Aug 15 '23 14:08 cdietrich

As mentioned in #1152, there is no magic/implicit usage of the ID rule. In the given example, Langium uses the STRING rule because that's what is assigned to the name property. I propose to close this issue.

spoenemann avatar Aug 22 '23 07:08 spoenemann