@@ -12,7 +12,7 @@ import { collectAst, collectTypeHierarchy, findReferenceTypes, isAstType, mergeT
12
12
import { generatedHeader } from './node-util.js' ;
13
13
import { collectKeywords , collectTerminalRegexps } from './langium-util.js' ;
14
14
15
- export function generateAst ( services : LangiumCoreServices , grammars : Grammar [ ] , config : LangiumConfig ) : string {
15
+ export function generateAst ( services : LangiumCoreServices , grammars : Grammar [ ] , config : LangiumConfig , ) : string {
16
16
const astTypes = collectAst ( grammars , services . shared . workspace . LangiumDocuments ) ;
17
17
const importFrom = config . langiumInternal ? `../../syntax-tree${ config . importExtension } ` : 'langium' ;
18
18
@@ -26,7 +26,7 @@ export function generateAst(services: LangiumCoreServices, grammars: Grammar[],
26
26
${ generateTerminalConstants ( grammars , config ) }
27
27
28
28
${ joinToNode ( astTypes . unions , union => union . toAstTypesString ( isAstType ( union . type ) ) , { appendNewLineIfNotEmpty : true } ) }
29
- ${ joinToNode ( astTypes . interfaces , iFace => iFace . toAstTypesString ( true , config . optionalProperties ) , { appendNewLineIfNotEmpty : true } ) }
29
+ ${ joinToNode ( astTypes . interfaces , iFace => iFace . toAstTypesString ( true , false ) , { appendNewLineIfNotEmpty : true } ) }
30
30
${
31
31
astTypes . unions = astTypes . unions . filter ( e => isAstType ( e . type ) ) ,
32
32
generateAstReflection ( config , astTypes )
@@ -35,6 +35,30 @@ export function generateAst(services: LangiumCoreServices, grammars: Grammar[],
35
35
return toString ( fileNode ) ;
36
36
/* eslint-enable @typescript-eslint/indent */
37
37
}
38
+ export function generateAstPartial ( services : LangiumCoreServices , grammars : Grammar [ ] , config : LangiumConfig , ) : string {
39
+ const astTypes = collectAst ( grammars , services . shared . workspace . LangiumDocuments ) ;
40
+ const importFrom = config . langiumInternal ? `../../syntax-tree${ config . importExtension } ` : 'langium' ;
41
+
42
+ /* eslint-disable @typescript-eslint/indent */
43
+ const fileNode = expandToNode `
44
+ ${ generatedHeader }
45
+
46
+ /* eslint-disable */
47
+ import * as langium from '${ importFrom } ';
48
+ import * as ast from './ast.js';
49
+
50
+ ${ generateTerminalConstantsPartial ( grammars , config ) }
51
+
52
+ ${ joinToNode ( astTypes . unions , union => union . toAstTypesString ( isAstType ( union . type ) , true ) , { appendNewLineIfNotEmpty : true } ) }
53
+ ${ joinToNode ( astTypes . interfaces , iFace => iFace . toAstTypesString ( true , true ) , { appendNewLineIfNotEmpty : true } ) }
54
+ ${
55
+ astTypes . unions = astTypes . unions . filter ( e => isAstType ( e . type ) ) ,
56
+ generateAstReflectionPartial ( config , astTypes )
57
+ }
58
+ ` ;
59
+ return toString ( fileNode ) ;
60
+ /* eslint-enable @typescript-eslint/indent */
61
+ }
38
62
39
63
function generateAstReflection ( config : LangiumConfig , astTypes : AstTypes ) : Generated {
40
64
const typeNames : string [ ] = astTypes . interfaces . map ( t => t . name )
@@ -69,6 +93,14 @@ function generateAstReflection(config: LangiumConfig, astTypes: AstTypes): Gener
69
93
` . appendNewLine ( ) ;
70
94
}
71
95
96
+ function generateAstReflectionPartial ( config : LangiumConfig , _astTypes : AstTypes ) : Generated {
97
+
98
+ return expandToNode `
99
+
100
+ export type { ${ config . projectName } AstType, ${ config . projectName } AstReflection } from './ast.js';
101
+ export const reflection = ast.reflection;
102
+ ` . appendNewLine ( ) ;
103
+ }
72
104
function buildTypeMetaDataMethod ( astTypes : AstTypes ) : Generated {
73
105
/* eslint-disable @typescript-eslint/indent */
74
106
return expandToNode `
@@ -253,3 +285,9 @@ function generateTerminalConstants(grammars: Grammar[], config: LangiumConfig):
253
285
export type ${ config . projectName } TokenNames = ${ config . projectName } TerminalNames | ${ config . projectName } KeywordNames;
254
286
` . appendNewLine ( ) ;
255
287
}
288
+
289
+ function generateTerminalConstantsPartial ( grammars : Grammar [ ] , config : LangiumConfig ) : Generated {
290
+ return expandToNode `
291
+ export { ${ config . projectName } Terminals, type ${ config . projectName } TerminalNames, type ${ config . projectName } KeywordNames, type ${ config . projectName } TokenNames } from './ast.js';
292
+ ` . appendNewLine ( ) ;
293
+ }
0 commit comments