mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-31 19:10:08 +00:00
added quote escaping to macro arg values...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a68ffdea13
commit
b7e63b15c2
38
pwiki2.js
38
pwiki2.js
@ -233,25 +233,31 @@ module.page = {
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX add escaping...
|
||||||
var _MACRO_PATTERN =
|
var _MACRO_PATTERN =
|
||||||
[[
|
[[
|
||||||
// @macro(arg ..)
|
// @macro(arg ..)
|
||||||
'\\\\?@(?<nameInline>$MACROS)\\((?<argsInline>[^)]*)\\)',
|
// XXX add support for '\)' in args...
|
||||||
|
'\\\\?@(?<nameInline>$MACROS)\\((?<argsInline>([^)])*)\\)',
|
||||||
// <macro ..> | <macro ../>
|
// <macro ..> | <macro ../>
|
||||||
'<\\s*(?<nameOpen>$MACROS)(?<argsOpen>\\s+[^>]*)?/?>',
|
// XXX revise escaped > and />
|
||||||
|
'<\\s*(?<nameOpen>$MACROS)(?<argsOpen>\\s+([^>/])*)?/?>',
|
||||||
// </macro>
|
// </macro>
|
||||||
'</\\s*(?<nameClose>$MACROS)\\s*>',
|
'</\\s*(?<nameClose>$MACROS)\\s*>',
|
||||||
].join('|'), 'smig']
|
].join('|'), 'smig']
|
||||||
// XXX add support for escaped quotes...
|
var MACRO_PATTERN_GROUPS = 8
|
||||||
|
// XXX still buggy...
|
||||||
var MACRO_ARGS_PATTERN =
|
var MACRO_ARGS_PATTERN =
|
||||||
RegExp('('+[
|
RegExp('('+[
|
||||||
// named args...
|
// named args...
|
||||||
'(?<nameQuoted>[a-zA-Z-_]+)\\s*=([\'"])(?<valueQupted>[^\\3]*)\\3\\s*',
|
'(?<nameQuoted>[a-zA-Z-_]+)\\s*=([\'"])(?<valueQupted>([^\\3]|\\\\3)*)\\3\\s*',
|
||||||
'(?<nameUnquoted>[a-zA-Z-_]+)\\s*=(?<valueUnquoted>[^\\s]*)',
|
'(?<nameUnquoted>[a-zA-Z-_]+)\\s*=(?<valueUnquoted>[^\\s]*)',
|
||||||
// positional args...
|
// positional args...
|
||||||
'([\'"])(?<argQuoted>[^\\7]*)\\7',
|
'([\'"])(?<argQuoted>([^\\8]|\\\\8)*)\\8',
|
||||||
'(?<arg>[^\\s]+)',
|
'(?<arg>[^\\s]+)',
|
||||||
].join('|') +')', 'smig')
|
].join('|') +')', 'smig')
|
||||||
|
//var MACRO_ARGS_PATTERN_GROUPS = 10
|
||||||
|
var MACRO_ARGS_PATTERN_GROUPS = 12
|
||||||
// XXX do we need basic inline and block commets a-la lisp???
|
// XXX do we need basic inline and block commets a-la lisp???
|
||||||
var COMMENT_PATTERN =
|
var COMMENT_PATTERN =
|
||||||
RegExp('('+[
|
RegExp('('+[
|
||||||
@ -300,7 +306,7 @@ function(str){
|
|||||||
// XXX closure: macros...
|
// XXX closure: macros...
|
||||||
var lex =
|
var lex =
|
||||||
module.lex =
|
module.lex =
|
||||||
function*(str, m=6, a=10){
|
function*(str){
|
||||||
// NOTE: we are doing a separate pass for comments to completely
|
// NOTE: we are doing a separate pass for comments to completely
|
||||||
// decouple them from the base macro syntax, making them fully
|
// decouple them from the base macro syntax, making them fully
|
||||||
// transparent...
|
// transparent...
|
||||||
@ -316,7 +322,7 @@ function*(str, m=6, a=10){
|
|||||||
var macro = false
|
var macro = false
|
||||||
while(lst.length > 0){
|
while(lst.length > 0){
|
||||||
if(macro){
|
if(macro){
|
||||||
var cur = lst.splice(0, m)
|
var cur = lst.splice(0, MACRO_PATTERN_GROUPS)
|
||||||
var match = cur[0]
|
var match = cur[0]
|
||||||
// special case: quoted inline macro -> text...
|
// special case: quoted inline macro -> text...
|
||||||
if(match.startsWith('\\@')){
|
if(match.startsWith('\\@')){
|
||||||
@ -324,19 +330,26 @@ function*(str, m=6, a=10){
|
|||||||
macro = false
|
macro = false
|
||||||
continue }
|
continue }
|
||||||
// group args...
|
// group args...
|
||||||
var _args = (cur[2] || cur[4] || '')
|
|
||||||
|
console.log('--- args:', cur[2] || cur[5] || '')
|
||||||
|
//var _args = (cur[2] || cur[4] || '')
|
||||||
|
var _args = (cur[2] || cur[5] || '')
|
||||||
.split(MACRO_ARGS_PATTERN)
|
.split(MACRO_ARGS_PATTERN)
|
||||||
var args = {}
|
var args = {}
|
||||||
var i = -1
|
var i = -1
|
||||||
while(_args.length > 1){
|
while(_args.length > 1){
|
||||||
i++
|
i++
|
||||||
var arg = _args.splice(0, a)
|
var arg = _args.splice(0, MACRO_ARGS_PATTERN_GROUPS)
|
||||||
|
console.log(' -', arg)
|
||||||
// NOTE: for positional args we use order (i) as key...
|
// NOTE: for positional args we use order (i) as key...
|
||||||
args[ arg[2] || arg[5] || i ] =
|
//args[ arg[2] || arg[5] || i ] =
|
||||||
arg[4] || arg[6] || arg[8] || arg[9] }
|
// arg[4] || arg[6] || arg[8] || arg[9] }
|
||||||
|
args[ arg[2] || arg[6] || i ] =
|
||||||
|
arg[4] || arg[7] || arg[9] || arg[11] }
|
||||||
// macro-spec...
|
// macro-spec...
|
||||||
yield {
|
yield {
|
||||||
name: (cur[1] || cur[3] || cur[5]).toLowerCase(),
|
//name: (cur[1] || cur[3] || cur[5]).toLowerCase(),
|
||||||
|
name: (cur[1] || cur[4] || cur[7]).toLowerCase(),
|
||||||
type: match[0] == '@' ?
|
type: match[0] == '@' ?
|
||||||
'inline'
|
'inline'
|
||||||
: match[1] == '/' ?
|
: match[1] == '/' ?
|
||||||
@ -356,6 +369,7 @@ function*(str, m=6, a=10){
|
|||||||
yield str }
|
yield str }
|
||||||
macro = true } } }
|
macro = true } } }
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// <item> ::=
|
// <item> ::=
|
||||||
// <string>
|
// <string>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user