mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 11:00:08 +00:00 
			
		
		
		
	reworked macro bool argument handling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									901933c5c9
								
							
						
					
					
						commit
						bd62886a75
					
				| @ -950,7 +950,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 		// XXX need a way to make encode option transparent...
 | 		// XXX need a way to make encode option transparent...
 | ||||||
| 		include: Macro( | 		include: Macro( | ||||||
| 			['src', 'recursive', 'join',  | 			['src', 'recursive', 'join',  | ||||||
| 				['s', 'strict', 'nonstrict', 'isolated']], | 				['s', 'strict', 'isolated']], | ||||||
| 			async function*(args, body, state, key='included', handler){ | 			async function*(args, body, state, key='included', handler){ | ||||||
| 				var macro = 'include' | 				var macro = 'include' | ||||||
| 				if(typeof(args) == 'string'){ | 				if(typeof(args) == 'string'){ | ||||||
| @ -971,7 +971,6 @@ object.Constructor('Page', BasePage, { | |||||||
| 				var recursive = args.recursive ?? body | 				var recursive = args.recursive ?? body | ||||||
| 				var isolated = args.isolated  | 				var isolated = args.isolated  | ||||||
| 				var strict = args.strict | 				var strict = args.strict | ||||||
| 					&& !args.nonstrict |  | ||||||
| 				var strquotes = args.s | 				var strquotes = args.s | ||||||
| 				var join = args.join  | 				var join = args.join  | ||||||
| 					&& await base.parse(args.join, state) | 					&& await base.parse(args.join, state) | ||||||
| @ -1059,7 +1058,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 		source: Macro( | 		source: Macro( | ||||||
| 			// XXX should this have the same args as include???
 | 			// XXX should this have the same args as include???
 | ||||||
| 			['src', 'recursive', 'join',  | 			['src', 'recursive', 'join',  | ||||||
| 				['s', 'strict', 'nonstrict']], | 				['s', 'strict']], | ||||||
| 			//['src'],
 | 			//['src'],
 | ||||||
| 			async function*(args, body, state){ | 			async function*(args, body, state){ | ||||||
| 				var that = this | 				var that = this | ||||||
| @ -1075,7 +1074,7 @@ object.Constructor('Page', BasePage, { | |||||||
| 		// NOTE: this is essentially the same as @source(..) but returns ''.
 | 		// NOTE: this is essentially the same as @source(..) but returns ''.
 | ||||||
| 		// XXX revise name...
 | 		// XXX revise name...
 | ||||||
| 		load: Macro( | 		load: Macro( | ||||||
| 			['src', ['strict', 'nonstrict']], | 			['src', ['strict']], | ||||||
| 			async function*(args, body, state){ | 			async function*(args, body, state){ | ||||||
| 				var that = this | 				var that = this | ||||||
| 				yield* this.macros.include.call(this,  | 				yield* this.macros.include.call(this,  | ||||||
| @ -1314,15 +1313,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 		// 		</else>
 | 		// 		</else>
 | ||||||
| 		// 	</macro>
 | 		// 	</macro>
 | ||||||
| 		//
 | 		//
 | ||||||
| 		// NOTE: if both strict and nonstrict are given the later takes 
 |  | ||||||
| 		// 		precedence.
 |  | ||||||
| 		// NOTE: if both isolated (default) and unisolated are given 
 |  | ||||||
| 		// 		then isolated has priority.
 |  | ||||||
| 		//
 |  | ||||||
| 		// XXX SORT sorting not implemented yet....
 | 		// XXX SORT sorting not implemented yet....
 | ||||||
| 		macro: Macro( | 		macro: Macro( | ||||||
| 			['name', 'src', 'sort', 'text', 'join', 'else',  | 			['name', 'src', 'sort', 'text', 'join', 'else',  | ||||||
| 				['strict', 'nonstrict', 'isolated', 'unisolated']], | 				['strict', 'isolated', 'inheritmacros' ]], | ||||||
| 			async function*(args, body, state){ | 			async function*(args, body, state){ | ||||||
| 				var that = this | 				var that = this | ||||||
| 
 | 
 | ||||||
| @ -1348,7 +1342,9 @@ object.Constructor('Page', BasePage, { | |||||||
| 					return block } | 					return block } | ||||||
| 
 | 
 | ||||||
| 				var base = this.get(this.path.split(/\*/).shift()) | 				var base = this.get(this.path.split(/\*/).shift()) | ||||||
| 
 | 				var macros = state.macros =  | ||||||
|  | 					state.macros  | ||||||
|  | 						?? {} | ||||||
| 				var depends = state.depends =  | 				var depends = state.depends =  | ||||||
| 					state.depends  | 					state.depends  | ||||||
| 						?? new Set() | 						?? new Set() | ||||||
| @ -1374,39 +1370,42 @@ object.Constructor('Page', BasePage, { | |||||||
| 						// NOTE: we do not need to worry about saving 
 | 						// NOTE: we do not need to worry about saving 
 | ||||||
| 						// 		stateful text here because it is only 
 | 						// 		stateful text here because it is only 
 | ||||||
| 						// 		grouped and not expanded...
 | 						// 		grouped and not expanded...
 | ||||||
| 						;(state.macros = state.macros ?? {})[name] =  | 						macros[name] =  | ||||||
| 							// XXX should we store all the args???
 | 							[ text,  | ||||||
| 							[text, _getBlock('join'), JSON.parse(JSON.stringify(args))] | 								_getBlock('join'),  | ||||||
|  | 								JSON.parse(JSON.stringify(args)), ] | ||||||
| 					// use existing macro...
 | 					// use existing macro...
 | ||||||
| 					} else if(state.macros  | 					} else if(macros  | ||||||
| 							&& name in state.macros){ | 							&& name in macros){ | ||||||
| 						;[itext, join, iargs] = state.macros[name] } } | 						;[itext, join, iargs] = macros[name] } } | ||||||
| 
 | 
 | ||||||
|  | 				// inheritable args...
 | ||||||
| 				// XXX is there a point in overloading text???
 | 				// XXX is there a point in overloading text???
 | ||||||
| 				text = text.length > 0 ?  | 				text = text.length > 0 ?  | ||||||
| 					text  | 					text  | ||||||
| 					: itext | 					: itext | ||||||
| 				// inheritable args...
 |  | ||||||
| 				var sort = (args.sort  | 				var sort = (args.sort  | ||||||
| 						?? iargs.sort  | 						?? iargs.sort  | ||||||
| 						?? '') | 						?? '') | ||||||
| 					.split(/\s+/g) | 					.split(/\s+/g) | ||||||
| 					.filter(function(e){  | 					.filter(function(e){  | ||||||
| 						return e != '' }) | 						return e != '' }) | ||||||
| 				// default is false...
 |  | ||||||
| 				var strict =  | 				var strict =  | ||||||
| 					('strict' in args || 'nonstrict' in args) ? | 					('strict' in args ? | ||||||
| 						args.strict  | 							args.strict  | ||||||
| 							&& !args.nonstrict  | 							: iargs.strict) | ||||||
| 						: iargs.strict  | 						?? false | ||||||
| 							&& !iargs.nonstrict |  | ||||||
| 				// default is true...
 |  | ||||||
| 				var isolated =  | 				var isolated =  | ||||||
| 					('isolated' in args || 'unisolated' in args) ? | 					('isolated' in args ? | ||||||
| 						args.isolated | 							args.isolated | ||||||
| 						|| !args.unisolated | 							: iargs.isolated) | ||||||
| 					: iargs.isolated | 						?? true | ||||||
| 						|| !iargs.unisolated | 				// XXX INHERITMACROS EXPERIMENTAL
 | ||||||
|  | 				var inheritmacros =  | ||||||
|  | 					('inheritmacros' in args ? | ||||||
|  | 							args.inheritmacros | ||||||
|  | 							: iargs.inheritmacros) | ||||||
|  | 						?? false | ||||||
| 
 | 
 | ||||||
| 				if(src){ | 				if(src){ | ||||||
| 					src = await base.parse(src, state) | 					src = await base.parse(src, state) | ||||||
| @ -1443,6 +1442,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 								seen: state.seen,  | 								seen: state.seen,  | ||||||
| 								depends, | 								depends, | ||||||
| 								renderer: state.renderer, | 								renderer: state.renderer, | ||||||
|  | 								// XXX INHERITMACROS EXPERIMENTAL
 | ||||||
|  | 								macros: args.inheritmacros ? | ||||||
|  | 									{__proto__: macros} | ||||||
|  | 									: {}, | ||||||
| 							} | 							} | ||||||
| 							yield this.__parser__.parse(page,  | 							yield this.__parser__.parse(page,  | ||||||
| 								this.__parser__.expand(page,  | 								this.__parser__.expand(page,  | ||||||
|  | |||||||
| @ -149,6 +149,11 @@ module.BaseParser = { | |||||||
| 	// Spec format:
 | 	// Spec format:
 | ||||||
| 	// 	[<orderd>, ... [<keyword>, ...]]
 | 	// 	[<orderd>, ... [<keyword>, ...]]
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	// Keyword arguments if given without a value are true by default, 
 | ||||||
|  | 	// explicitly setting a keyword argument to 'true' or 'yes' will set 
 | ||||||
|  | 	// it to true, explicitly setting to 'false' or 'no' will set it to 
 | ||||||
|  | 	// false, any other value will be set as-is...
 | ||||||
|  | 	//
 | ||||||
| 	// NOTE: the input to this is formatted by .lex(..)
 | 	// NOTE: the input to this is formatted by .lex(..)
 | ||||||
| 	// NOTE: arg pre-parsing is dome by .lex(..) but at that stage we do not
 | 	// NOTE: arg pre-parsing is dome by .lex(..) but at that stage we do not
 | ||||||
| 	// 		yet touch the actual macros (we need them to get the .arg_spec)
 | 	// 		yet touch the actual macros (we need them to get the .arg_spec)
 | ||||||
| @ -174,6 +179,17 @@ module.BaseParser = { | |||||||
| 						(res[value] = true) | 						(res[value] = true) | ||||||
| 						// positional...
 | 						// positional...
 | ||||||
| 						: (pos[key*1] = value)) | 						: (pos[key*1] = value)) | ||||||
|  | 					// keyword/bool default values...
 | ||||||
|  | 					: bools.has(key) ? | ||||||
|  | 						(res[key] =  | ||||||
|  | 							// value escaping...
 | ||||||
|  | 							value[0] == '\\' ? | ||||||
|  | 								value.slice(1) | ||||||
|  | 							: (value == 'true' || value == 'yes') ? | ||||||
|  | 								true | ||||||
|  | 							: (value == 'false' || value == 'no') ? | ||||||
|  | 								false | ||||||
|  | 							: value) | ||||||
| 					// keyword...
 | 					// keyword...
 | ||||||
| 					: (res[key] = value) | 					: (res[key] = value) | ||||||
| 				return pos }, []) | 				return pos }, []) | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ | |||||||
| * 		- CLI										-  | * 		- CLI										-  | ||||||
| * | * | ||||||
| * | * | ||||||
|  | * XXX would be nice for bool arguments to accept yes/no true/false values... | ||||||
| * XXX macro: should macro isolation be one-directional??? | * XXX macro: should macro isolation be one-directional??? | ||||||
| * 			...i.e. iterations see/overload things defined above but  | * 			...i.e. iterations see/overload things defined above but  | ||||||
| * 			can not affect the above context... | * 			can not affect the above context... | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user