|
6 | 6 |
|
7 | 7 | import type { TokenType, TokenVocabulary } from 'chevrotain'; |
8 | 8 | import type { AstNode, CstNode, GenericAstNode, Grammar, GrammarAST, LangiumParser, ParseResult, TokenBuilderOptions } from 'langium'; |
9 | | -import { EmptyFileSystem, DefaultTokenBuilder, GrammarUtils } from 'langium'; |
| 9 | +import { EmptyFileSystem, DefaultTokenBuilder, GrammarUtils, CstUtils } from 'langium'; |
10 | 10 | import { describe, expect, test, onTestFailed, beforeAll } from 'vitest'; |
11 | 11 | import { createLangiumGrammarServices, createServicesForGrammar } from 'langium/grammar'; |
12 | 12 | import { expandToString } from 'langium/generate'; |
@@ -926,6 +926,21 @@ describe('Unassigned subrules', () => { |
926 | 926 |
|
927 | 927 | }); |
928 | 928 |
|
| 929 | +describe('Handling hidden nodes', () => { |
| 930 | + test('Should find comment node of element affected by an assigned action', async () => { |
| 931 | + const grammar = createLangiumGrammarServices(EmptyFileSystem); |
| 932 | + const parser = parseHelper(grammar.grammar); |
| 933 | + const doc = await parser("Test returns string: /** comment 1 */ 'A' | /** comment 2 */ 'B' | /** comment 3 */ 'C';"); |
| 934 | + expect(doc).toBeDefined(); |
| 935 | + const value = doc.parseResult.value as Grammar; |
| 936 | + const ruleDef = value.rules[0].definition as GrammarAST.Alternatives; |
| 937 | + const a = ruleDef.elements[0]; |
| 938 | + const commentNode = CstUtils.findCommentNode(a.$cstNode, ['ML_COMMENT']); |
| 939 | + expect(commentNode).toBeDefined(); |
| 940 | + expect(commentNode!.text).toBe('/** comment 1 */'); |
| 941 | + }); |
| 942 | +}); |
| 943 | + |
929 | 944 | describe('Handling EOF', () => { |
930 | 945 | test('Use EOF as last part of the entry rule definition', async () => { |
931 | 946 | const grammar = ` |
|
0 commit comments