mirror of
https://github.com/flynx/pWiki.git
synced 2026-01-10 12:01:07 +00:00
added macro nested blocks (still experimenting)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b7e63b15c2
commit
c199f97802
25
pwiki2.js
25
pwiki2.js
@ -377,13 +377,16 @@ function*(str){
|
|||||||
// type: 'inline'
|
// type: 'inline'
|
||||||
// | 'element'
|
// | 'element'
|
||||||
// | 'block',
|
// | 'block',
|
||||||
// block: [ .. ],
|
// block: [
|
||||||
|
// <item>,
|
||||||
|
// ...
|
||||||
|
// ],
|
||||||
//
|
//
|
||||||
// // rest of items are the same as for lex(..)
|
// // rest of items are the same as for lex(..)
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// XXX normalize lex to be a generator???
|
// XXX normalize lex to be a generator (???)
|
||||||
var group =
|
var group =
|
||||||
module.group =
|
module.group =
|
||||||
function*(lex, to=false){
|
function*(lex, to=false){
|
||||||
@ -391,15 +394,27 @@ function*(lex, to=false){
|
|||||||
// generator even if the end is not reached...
|
// generator even if the end is not reached...
|
||||||
while(true){
|
while(true){
|
||||||
var {value, done} = lex.next()
|
var {value, done} = lex.next()
|
||||||
|
// check if unclosed blocks remaining...
|
||||||
if(done){
|
if(done){
|
||||||
if(to){
|
if(to){
|
||||||
throw new Error('Premature end of unpit: Expected closing "'+ to +'"') }
|
throw new Error(
|
||||||
|
'Premature end of unpit: Expected closing "'+ to +'"') }
|
||||||
return }
|
return }
|
||||||
|
// assert nesting rules...
|
||||||
|
if(macros[value.name] instanceof Array
|
||||||
|
&& macros[value.name].includes(to)){
|
||||||
|
throw new Error(
|
||||||
|
'Unexpected "'+ value.name +'" macro'
|
||||||
|
+(to ?
|
||||||
|
' in "'+to+'"'
|
||||||
|
: '')) }
|
||||||
|
// open block...
|
||||||
if(value.type == 'opening'){
|
if(value.type == 'opening'){
|
||||||
value.body = [...group(lex, value.name)]
|
value.body = [...group(lex, value.name)]
|
||||||
value.type = 'block'
|
value.type = 'block'
|
||||||
yield value
|
yield value
|
||||||
continue
|
continue
|
||||||
|
// close block...
|
||||||
} else if(value.type == 'closing'){
|
} else if(value.type == 'closing'){
|
||||||
if(value.name != to){
|
if(value.name != to){
|
||||||
throw new Error('Unexpected closing "'+ value.name +'"') }
|
throw new Error('Unexpected closing "'+ value.name +'"') }
|
||||||
@ -409,6 +424,7 @@ function*(lex, to=false){
|
|||||||
|
|
||||||
|
|
||||||
var parse =
|
var parse =
|
||||||
|
module.parse =
|
||||||
function*(str){
|
function*(str){
|
||||||
yield* group(lex(str)) }
|
yield* group(lex(str)) }
|
||||||
|
|
||||||
@ -442,6 +458,9 @@ var macros = {
|
|||||||
quote: function(){},
|
quote: function(){},
|
||||||
macro: function(){},
|
macro: function(){},
|
||||||
slot: function(){},
|
slot: function(){},
|
||||||
|
|
||||||
|
// nesting rules...
|
||||||
|
'else': ['macro'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user