11import { Abstract_PT_Node , ParsingTree , PT_Closure , PT_Literal } from './ParsingTree' ;
22import {
33 getClosureFromContext ,
4+ getClosureOrUndefinedFromContext ,
45 getEntryFromContext ,
56 getLiteralFromContext ,
7+ getLiteralOrUndefinedFromContext ,
68 getSubContextArrayFromContext ,
79 hasContextEntry ,
810 ValidationContext ,
@@ -18,21 +20,31 @@ import { UnvalidatedInputFieldDeclaration } from './InputFieldDeclarationValidat
1820import { ITemplateSupplier } from './ITemplateSupplier' ;
1921import { InputFieldValidationGraphSupplier } from './validationGraph/InputFieldValidationGraphSupplier' ;
2022import { getTrimmedStructureParserResult , StructureParserResult } from './StructureParser' ;
23+ import {
24+ InputField_Abstract_PT_Node ,
25+ InputField_ParsingTree ,
26+ InputField_PT_Closure ,
27+ InputField_StructureParserResult ,
28+ InputField_ValidationContext ,
29+ InputField_ValidationContextClosureEntry ,
30+ InputField_ValidationContextLiteralEntry ,
31+ InputField_ValidationGraph ,
32+ } from './InputFieldParserHelperTypes' ;
2133
2234export class InputFieldStructureParser {
2335 templateSupplier : ITemplateSupplier < UnvalidatedInputFieldDeclaration > ;
2436 graphSupplier : InputFieldValidationGraphSupplier ;
2537
2638 fullDeclaration : string ;
2739 tokens : InputFieldToken [ ] ;
28- parsingTree : ParsingTree < InputFieldTokenType , InputFieldToken > ;
40+ parsingTree : InputField_ParsingTree ;
2941
30- inputFieldType ?: StructureParserResult < InputFieldTokenType , InputFieldToken > ;
31- bindTargetFile ?: StructureParserResult < InputFieldTokenType , InputFieldToken > ;
32- bindTargetPath ?: StructureParserResult < InputFieldTokenType , InputFieldToken > ;
42+ inputFieldType ?: InputField_StructureParserResult ;
43+ bindTargetFile ?: InputField_StructureParserResult ;
44+ bindTargetPath ?: InputField_StructureParserResult ;
3345 arguments : {
34- name : StructureParserResult < InputFieldTokenType , InputFieldToken > ;
35- value ?: StructureParserResult < InputFieldTokenType , InputFieldToken > ;
46+ name : InputField_StructureParserResult ;
47+ value ?: InputField_StructureParserResult ;
3648 } [ ] ;
3749 errorCollection : ErrorCollection ;
3850
@@ -41,7 +53,7 @@ export class InputFieldStructureParser {
4153 graphSupplier : InputFieldValidationGraphSupplier ,
4254 fullDeclaration : string ,
4355 tokens : InputFieldToken [ ] ,
44- parsingTree : ParsingTree < InputFieldTokenType , InputFieldToken > ,
56+ parsingTree : InputField_ParsingTree ,
4557 errorCollection : ErrorCollection
4658 ) {
4759 this . templateSupplier = templateSupplier ;
@@ -109,7 +121,7 @@ export class InputFieldStructureParser {
109121 return this . buildDeclaration ( ) ;
110122 }
111123
112- private parseTemplate ( closure : PT_Closure < InputFieldTokenType , InputFieldToken > ) : void {
124+ private parseTemplate ( closure : InputField_PT_Closure ) : void {
113125 const validationContext = this . validateNodeAndThrow ( closure , this . graphSupplier . templateNameValidationGraph ) ;
114126
115127 if ( hasContextEntry ( validationContext , 'templateName' ) ) {
@@ -143,7 +155,7 @@ export class InputFieldStructureParser {
143155 }
144156 }
145157
146- private parsePartialDeclaration ( closure : PT_Closure < InputFieldTokenType , InputFieldToken > ) : void {
158+ private parsePartialDeclaration ( closure : InputField_PT_Closure ) : void {
147159 const validationContext = this . validateNodeAndThrow ( closure , this . graphSupplier . partialDeclarationValidationGraph ) ;
148160
149161 if ( hasContextEntry ( validationContext , 'type' ) ) {
@@ -159,7 +171,7 @@ export class InputFieldStructureParser {
159171 }
160172 }
161173
162- private parseDeclaration ( closure : PT_Closure < InputFieldTokenType , InputFieldToken > ) : void {
174+ private parseDeclaration ( closure : InputField_PT_Closure ) : void {
163175 const validationContext = this . validateNodeAndThrow ( closure , this . graphSupplier . declarationValidationGraph ) ;
164176
165177 this . inputFieldType = this . parseInputFieldType ( getLiteralFromContext ( validationContext , 'type' ) ) ;
@@ -183,18 +195,21 @@ export class InputFieldStructureParser {
183195 * @private
184196 */
185197 private parseBindTarget (
186- closure : PT_Closure < InputFieldTokenType , InputFieldToken > ,
187- validationContext : ValidationContext < InputFieldTokenType , InputFieldToken , string > ,
188- bindTargetSeparatorContextEntry : ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Literal < InputFieldTokenType , InputFieldToken > >
198+ closure : InputField_PT_Closure ,
199+ validationContext : InputField_ValidationContext < string > ,
200+ bindTargetSeparatorContextEntry : InputField_ValidationContextLiteralEntry
189201 ) : void {
190202 const separatorIndex = bindTargetSeparatorContextEntry . inputIndex ;
191203 if ( closure . children [ separatorIndex ] === undefined ) {
192204 // there is no bind target
193205 return ;
194206 }
195207
196- const bindTargetContextEntry = getLiteralFromContext ( validationContext , 'bindTarget' ) ;
197- const bindTargetFileContextEntry = getLiteralFromContext ( validationContext , 'bindTargetFile' ) ;
208+ const bindTargetContextEntry : InputField_ValidationContextLiteralEntry = getLiteralFromContext ( validationContext , 'bindTarget' ) ;
209+ const bindTargetFileContextEntry : InputField_ValidationContextLiteralEntry | undefined = getLiteralOrUndefinedFromContext (
210+ validationContext ,
211+ 'bindTargetFile'
212+ ) ;
198213
199214 // parsing the bind target with this parser sucks
200215 let bindTargetLiteral = '' ;
@@ -209,7 +224,7 @@ export class InputFieldStructureParser {
209224 } ;
210225 }
211226
212- private parseArguments ( contextEntry : ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Closure < InputFieldTokenType , InputFieldToken > > ) : void {
227+ private parseArguments ( contextEntry : InputField_ValidationContextClosureEntry ) : void {
213228 const closure = contextEntry . element ;
214229 if ( closure . children . length === 0 ) {
215230 return ;
@@ -220,23 +235,17 @@ export class InputFieldStructureParser {
220235 const subContextArray = getSubContextArrayFromContext ( validationContext , 'arguments' ) ;
221236
222237 for ( const x of subContextArray ) {
223- const typeContextEntry : ValidationContextEntry <
224- InputFieldTokenType ,
225- InputFieldToken ,
226- PT_Literal < InputFieldTokenType , InputFieldToken >
227- > = getLiteralFromContext ( x , 'name' ) ;
228- const valueContextEntry :
229- | ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Closure < InputFieldTokenType , InputFieldToken > >
230- | undefined = getClosureFromContext ( x , 'value' ) ;
238+ const typeContextEntry : InputField_ValidationContextLiteralEntry = getLiteralFromContext ( x , 'name' ) ;
239+ const valueContextEntry : InputField_ValidationContextClosureEntry | undefined = getClosureOrUndefinedFromContext ( x , 'value' ) ;
231240
232241 this . arguments . push ( this . parseArgument ( typeContextEntry , valueContextEntry ) ) ;
233242 }
234243 }
235244
236245 private parseArgument (
237- nameContextEntry : ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Literal < InputFieldTokenType , InputFieldToken > > ,
238- valueContextEntry : ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Closure < InputFieldTokenType , InputFieldToken > > | undefined
239- ) : { name : StructureParserResult < InputFieldTokenType , InputFieldToken > ; value ?: StructureParserResult < InputFieldTokenType , InputFieldToken > } {
246+ nameContextEntry : InputField_ValidationContextLiteralEntry ,
247+ valueContextEntry : InputField_ValidationContextClosureEntry | undefined
248+ ) : { name : InputField_StructureParserResult ; value ?: InputField_StructureParserResult } {
240249 if ( valueContextEntry ?. element ) {
241250 let valueString = '' ;
242251 for ( const child of valueContextEntry . element . children ) {
@@ -258,9 +267,9 @@ export class InputFieldStructureParser {
258267 }
259268
260269 private validateNodeAndThrow < Key extends string > (
261- astNode : Abstract_PT_Node < InputFieldTokenType , InputFieldToken > ,
262- validationGraph : ValidationGraph < InputFieldTokenType , InputFieldToken , Key >
263- ) : ValidationContext < InputFieldTokenType , InputFieldToken , Key > {
270+ astNode : InputField_Abstract_PT_Node ,
271+ validationGraph : InputField_ValidationGraph < Key >
272+ ) : InputField_ValidationContext < Key > {
264273 const valRes = validationGraph . validateParsingTreeAndExtractContext ( astNode ) ;
265274
266275 if ( valRes . acceptedState === undefined ) {
@@ -270,9 +279,7 @@ export class InputFieldStructureParser {
270279 return valRes . acceptedState . context ;
271280 }
272281
273- private parseInputFieldType (
274- contextEntry : ValidationContextEntry < InputFieldTokenType , InputFieldToken , PT_Literal < InputFieldTokenType , InputFieldToken > >
275- ) : StructureParserResult < InputFieldTokenType , InputFieldToken > {
282+ private parseInputFieldType ( contextEntry : InputField_ValidationContextLiteralEntry ) : InputField_StructureParserResult {
276283 return getTrimmedStructureParserResult ( contextEntry ) ;
277284 }
278285}
0 commit comments