mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 11:00:08 +00:00 
			
		
		
		
	experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									5dcfd94cfd
								
							
						
					
					
						commit
						9c0ffbb88c
					
				| @ -589,6 +589,58 @@ module.BaseParser = { | |||||||
| 	// 		| { data: <ast> }
 | 	// 		| { data: <ast> }
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// XXX should this also resolve e.data???
 | 	// XXX should this also resolve e.data???
 | ||||||
|  | 	/* XXX EXPERIMENTAL... | ||||||
|  | 	resolve: function(page, ast, state={}){ | ||||||
|  | 		var that = this | ||||||
|  | 		ast = ast  | ||||||
|  | 			?? this.expand(page, null, state) | ||||||
|  | 		ast = typeof(ast) != 'object' ? | ||||||
|  | 			this.expand(page, ast, state) | ||||||
|  | 			: ast | ||||||
|  | 
 | ||||||
|  | 		var handleItem = function(e){ | ||||||
|  | 			// expand delayed sections...
 | ||||||
|  | 			e = typeof(e) == 'function' ? | ||||||
|  | 				e.call(page, state) | ||||||
|  | 				: e | ||||||
|  | 			// expand arrays...
 | ||||||
|  | 			if(e instanceof Array  | ||||||
|  | 					| e instanceof types.Generator){ | ||||||
|  | 				return that.resolve(page, e, state) | ||||||
|  | 			// data -- unwrap content...
 | ||||||
|  | 			} else if(e instanceof Object && 'data' in e){ | ||||||
|  | 				return that.resolve(page, e.data, state) | ||||||
|  | 					.then(function(e){ | ||||||
|  | 						return { data: e } }) | ||||||
|  | 			// skipped items...
 | ||||||
|  | 			} else if(e instanceof Object && e.skip){ | ||||||
|  | 				return [] | ||||||
|  | 			} else { | ||||||
|  | 				return [e] } } | ||||||
|  | 
 | ||||||
|  | 		// XXX do we need this???
 | ||||||
|  | 		var issync = ast instanceof Array  | ||||||
|  | 			&& ast.reduce(function(e, res){ | ||||||
|  | 				return res === false ? | ||||||
|  | 					res | ||||||
|  | 					: e instanceof Promise }, true) | ||||||
|  | 
 | ||||||
|  | 		// NOTE: we need to await for ast here as we need stage 2 of 
 | ||||||
|  | 		// 		parsing to happen AFTER everything else completes...
 | ||||||
|  | 		// 		XXX
 | ||||||
|  | 		return issync ? | ||||||
|  | 				Promise.all(ast) | ||||||
|  | 					.then(function(ast){ | ||||||
|  | 						return ast.map(handleItem) | ||||||
|  | 							.flat() }) | ||||||
|  | 			: ast instanceof Array ? | ||||||
|  | 				ast.map(handleItem) | ||||||
|  | 					.flat() | ||||||
|  | 			: ast.then(function(ast){ | ||||||
|  | 					return ast.map(handleItem) | ||||||
|  | 						.flat() }) | ||||||
|  | 				.iter() }, | ||||||
|  | 	/*/ | ||||||
| 	resolve: async function*(page, ast, state={}){ | 	resolve: async function*(page, ast, state={}){ | ||||||
| 		ast = ast  | 		ast = ast  | ||||||
| 			?? this.expand(page, null, state) | 			?? this.expand(page, null, state) | ||||||
| @ -598,12 +650,10 @@ module.BaseParser = { | |||||||
| 
 | 
 | ||||||
| 		// NOTE: we need to await for ast here as we need stage 2 of 
 | 		// NOTE: we need to await for ast here as we need stage 2 of 
 | ||||||
| 		// 		parsing to happen AFTER everything else completes...
 | 		// 		parsing to happen AFTER everything else completes...
 | ||||||
| 		/* XXX GENERATOR -- this breaks the parser... | 		// XXX GENERATOR -- this breaks the parser...
 | ||||||
| 		//		...investigate the data flow...
 | 		//		...investigate the data flow...
 | ||||||
| 		for await (var e of ast){ | 		//for await (var e of ast){
 | ||||||
| 		/*/ |  | ||||||
| 		for(var e of await ast){ | 		for(var e of await ast){ | ||||||
| 		//*/
 |  | ||||||
| 			// expand delayed sections...
 | 			// expand delayed sections...
 | ||||||
| 			e = typeof(e) == 'function' ? | 			e = typeof(e) == 'function' ? | ||||||
| 				e.call(page, state) | 				e.call(page, state) | ||||||
| @ -620,6 +670,7 @@ module.BaseParser = { | |||||||
| 				continue | 				continue | ||||||
| 			} else { | 			} else { | ||||||
| 				yield e } } }, | 				yield e } } }, | ||||||
|  | 	//*/
 | ||||||
| 
 | 
 | ||||||
| 	// Fully parse a page...
 | 	// Fully parse a page...
 | ||||||
| 	//
 | 	//
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user