mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-19 17:41:38 +00:00
added comments...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4d53500b70
commit
fc62068d5e
101
pwiki2.js
101
pwiki2.js
@ -236,13 +236,12 @@ module.page = {
|
|||||||
var _MACRO_PATTERN =
|
var _MACRO_PATTERN =
|
||||||
[[
|
[[
|
||||||
// @macro(arg ..)
|
// @macro(arg ..)
|
||||||
//'\\\\?\\\\?@(?<nameInline>$MACROS)\\((?<argsInline>[^)]*)\\)',
|
|
||||||
'\\\\?@(?<nameInline>$MACROS)\\((?<argsInline>[^)]*)\\)',
|
'\\\\?@(?<nameInline>$MACROS)\\((?<argsInline>[^)]*)\\)',
|
||||||
// <macro ..> | <macro ../>
|
// <macro ..> | <macro ../>
|
||||||
'<\\s*(?<nameOpen>$MACROS)(?<argsOpen>\\s+[^>]*)?/?>',
|
'<\\s*(?<nameOpen>$MACROS)(?<argsOpen>\\s+[^>]*)?/?>',
|
||||||
// </macro>
|
// </macro>
|
||||||
'</\\s*(?<nameClose>$MACROS)\\s*>',
|
'</\\s*(?<nameClose>$MACROS)\\s*>',
|
||||||
].join('|'), 'mg']
|
].join('|'), 'smig']
|
||||||
// XXX add support for escaped quotes...
|
// XXX add support for escaped quotes...
|
||||||
var MACRO_ARGS_PATTERN =
|
var MACRO_ARGS_PATTERN =
|
||||||
RegExp('('+[
|
RegExp('('+[
|
||||||
@ -252,30 +251,68 @@ var MACRO_ARGS_PATTERN =
|
|||||||
// positional args...
|
// positional args...
|
||||||
'([\'"])(?<argQuoted>[^\\7]*)\\7',
|
'([\'"])(?<argQuoted>[^\\7]*)\\7',
|
||||||
'(?<arg>[^\\s]+)',
|
'(?<arg>[^\\s]+)',
|
||||||
].join('|') +')', 'g')
|
].join('|') +')', 'smig')
|
||||||
|
// XXX do we need basic inline and block commets a-la lisp???
|
||||||
|
var COMMENT_PATTERN =
|
||||||
|
RegExp('('+[
|
||||||
|
// <!--[pwiki[ .. ]]-->
|
||||||
|
'<!--\\[pwiki\\[(?<uncomment>.*)\\]\\]-->',
|
||||||
|
|
||||||
|
// <pwiki-comment> .. </pwiki-comment>
|
||||||
|
'<\\s*pwiki-comment[^>]*>.*<\\/\\s*pwiki-comment\\s*>',
|
||||||
|
// <pwiki-comment .. />
|
||||||
|
'<\\s*pwiki-comment[^\\/>]*\\/>',
|
||||||
|
].join('|') +')', 'smig')
|
||||||
|
|
||||||
|
|
||||||
var macros = {
|
|
||||||
now: function(){},
|
|
||||||
macro: function(){},
|
|
||||||
filter: function(){},
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX move into the parser...
|
var clearComments =
|
||||||
var MACRO_PATTERN =
|
module.clearComments =
|
||||||
module.MACRO_PATTERN =
|
function(str){
|
||||||
new RegExp(
|
return str
|
||||||
'('+ _MACRO_PATTERN[0]
|
.replace(COMMENT_PATTERN, function(...a){
|
||||||
.replace(/\$MACROS/g, Object.keys(macros).join('|')) +')',
|
var groups = a.pop()
|
||||||
_MACRO_PATTERN[1])
|
return groups.uncomment ?
|
||||||
|
groups.uncomment
|
||||||
|
: ''}) }
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// <item> ::=
|
||||||
|
// <string>
|
||||||
|
// | {
|
||||||
|
// name: <string>,
|
||||||
|
// type: 'inline'
|
||||||
|
// | 'element'
|
||||||
|
// | 'opening'
|
||||||
|
// | 'closing',
|
||||||
|
// args: {
|
||||||
|
// <index>: <value>,
|
||||||
|
// <key>: <value>,
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
// match: <string>,
|
||||||
|
// }
|
||||||
|
//
|
||||||
// XXX need m and a to be calculated automatically rather than hardcoded...
|
// XXX need m and a to be calculated automatically rather than hardcoded...
|
||||||
|
// ...can we use .replace(..) for its access to named groups???
|
||||||
// XXX feels a bit ugly...
|
// XXX feels a bit ugly...
|
||||||
|
// XXX closure: macros...
|
||||||
var lex =
|
var lex =
|
||||||
module.lex =
|
module.lex =
|
||||||
function*(str, m=6, a=10){
|
function*(str, m=6, a=10){
|
||||||
var lst = str.split(MACRO_PATTERN)
|
// NOTE: we are doing a separate pass for comments to completely
|
||||||
|
// decouple them from the base macro syntax, making them fully
|
||||||
|
// transparent...
|
||||||
|
str = clearComments(str)
|
||||||
|
|
||||||
|
var lst = str.split(
|
||||||
|
// XXX cache this???
|
||||||
|
new RegExp(
|
||||||
|
'('+ _MACRO_PATTERN[0]
|
||||||
|
.replace(/\$MACROS/g, Object.keys(macros).join('|')) +')',
|
||||||
|
_MACRO_PATTERN[1]))
|
||||||
|
|
||||||
var macro = false
|
var macro = false
|
||||||
while(lst.length > 0){
|
while(lst.length > 0){
|
||||||
if(macro){
|
if(macro){
|
||||||
@ -299,13 +336,13 @@ function*(str, m=6, a=10){
|
|||||||
arg[4] || arg[6] || arg[8] || arg[9] }
|
arg[4] || arg[6] || arg[8] || arg[9] }
|
||||||
// macro-spec...
|
// macro-spec...
|
||||||
yield {
|
yield {
|
||||||
name: cur[1] || cur[3] || cur[5],
|
name: (cur[1] || cur[3] || cur[5]).toLowerCase(),
|
||||||
type: match[0] == '@' ?
|
type: match[0] == '@' ?
|
||||||
'inline'
|
'inline'
|
||||||
: match[1] == '/' ?
|
: match[1] == '/' ?
|
||||||
'closing'
|
'closing'
|
||||||
: match[match.length-2] == '/' ?
|
: match[match.length-2] == '/' ?
|
||||||
'self-closing'
|
'element'
|
||||||
: 'opening',
|
: 'opening',
|
||||||
args,
|
args,
|
||||||
match,
|
match,
|
||||||
@ -319,7 +356,20 @@ function*(str, m=6, a=10){
|
|||||||
yield str }
|
yield str }
|
||||||
macro = true } } }
|
macro = true } } }
|
||||||
|
|
||||||
// XXX normalize lex to be a generator...
|
//
|
||||||
|
// <item> ::=
|
||||||
|
// <string>
|
||||||
|
// | {
|
||||||
|
// type: 'inline'
|
||||||
|
// | 'element'
|
||||||
|
// | 'block',
|
||||||
|
// block: [ .. ],
|
||||||
|
//
|
||||||
|
// // rest of items are the same as for lex(..)
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// XXX normalize lex to be a generator???
|
||||||
var group =
|
var group =
|
||||||
module.group =
|
module.group =
|
||||||
function*(lex, to=false){
|
function*(lex, to=false){
|
||||||
@ -345,6 +395,7 @@ function*(lex, to=false){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// XXX
|
||||||
var expandPage =
|
var expandPage =
|
||||||
module.expandPage =
|
module.expandPage =
|
||||||
function(page){
|
function(page){
|
||||||
@ -362,8 +413,20 @@ var WIKIWORD_PATTERN =
|
|||||||
].join('|') +')', 'g')
|
].join('|') +')', 'g')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
var macros = {
|
||||||
|
now: function(){},
|
||||||
|
filter: function(){},
|
||||||
|
include: function(){},
|
||||||
|
source: function(){},
|
||||||
|
quote: function(){},
|
||||||
|
macro: function(){},
|
||||||
|
slot: function(){},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user