cleanup and fixed a couple of bugs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-02 23:56:32 +03:00
parent fe8684f6ce
commit eb6fc8819c

View File

@ -520,9 +520,9 @@ module.BaseParser = {
// /(?<quote>['"])(\\\k<quote>|[^\1])*\k<quote>/ // /(?<quote>['"])(\\\k<quote>|[^\1])*\k<quote>/
// ...this will work but we'll also need to remove the \ in the // ...this will work but we'll also need to remove the \ in the
// final string... // final string...
MACRO_ARGS: ['(',[ MACRO_ARGS: ['(\\s*(',[
// arg='val' | arg="val" | arg=val // arg='val' | arg="val" | arg=val
'\\s+(?<PREFIXArgName>[a-z]+)\\s*=\\s*(?<PREFIXArgValue>'+([ '(?<PREFIXArgName>[a-z]+)\\s*=\\s*(?<PREFIXArgValue>'+([
// XXX CHROME/NODE BUG: this does not work yet... // XXX CHROME/NODE BUG: this does not work yet...
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>', //'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
"'(?<PREFIXSingleQuotedValue>[^']*)'", "'(?<PREFIXSingleQuotedValue>[^']*)'",
@ -532,15 +532,15 @@ module.BaseParser = {
// "arg" | 'arg' // "arg" | 'arg'
// XXX CHROME/NODE BUG: this does not work yet... // XXX CHROME/NODE BUG: this does not work yet...
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>', //'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
'\\s+"(?<PREFIXDoubleQuotedArg>[^"]*)"', '"(?<PREFIXDoubleQuotedArg>[^"]*)"',
"\\s+'(?<PREFIXSingleQuotedArg>[^']*)'", "'(?<PREFIXSingleQuotedArg>[^']*)'",
// arg // arg
// NOTE: this is last because it could eat up parts of the above // NOTE: this is last because it could eat up parts of the above
// alternatives... // alternatives...
//'|\\s+[^\\s\\/>\'"]+', //'|\\s+[^\\s\\/>\'"]+',
'\\s+(?<PREFIXArg>[^\\sSTOP\'"]+)', '(?<PREFIXArg>[^\\sSTOP\'"]+)',
].join('|'), ].join('|'),
')'].join(''), '))'].join(''),
MACRO_ARGS_PATTERN: undefined, MACRO_ARGS_PATTERN: undefined,
// //
// .buildArgsPattern(<prefix>[, <stop>[, <flags>]]) // .buildArgsPattern(<prefix>[, <stop>[, <flags>]])
@ -562,6 +562,10 @@ module.BaseParser = {
// MACROS // MACROS
// INLINE_ARGS -- MACRO_ARGS.replace(/STOP/, ')') // INLINE_ARGS -- MACRO_ARGS.replace(/STOP/, ')')
// ARGS -- MACRO_ARGS.replace(/STOP/, '\\/>') // ARGS -- MACRO_ARGS.replace(/STOP/, '\\/>')
//
// XXX BUG: this fails to match inline macros with non-empty args @moo(a)
// ...the problem seems to be with the lack of whitespace
// between ( and the first arg -- @moo( a) is matched fine...
MACRO: '('+([ MACRO: '('+([
// @macro(arg ..) // @macro(arg ..)
'\\\\?@(?<nameInline>MACROS)\\((?<argsInline>INLINE_ARGS)\\)', '\\\\?@(?<nameInline>MACROS)\\((?<argsInline>INLINE_ARGS)\\)',
@ -986,6 +990,7 @@ object.Constructor('Page', BasePage, {
// //
// XXX support .NO_FILTERS ... // XXX support .NO_FILTERS ...
filter: function*(args, body, state, expand=true){ filter: function*(args, body, state, expand=true){
var that = this
var filters = state.filters = var filters = state.filters =
state.filters ?? [] state.filters ?? []
// separate local filters... // separate local filters...
@ -1009,6 +1014,8 @@ object.Constructor('Page', BasePage, {
[...this.__parser__.expand(this, body, state)] [...this.__parser__.expand(this, body, state)]
: body instanceof Array ? : body instanceof Array ?
body body
// NOTE: wrapping the body in an array effectively
// escapes it from parsing...
: [body] : [body]
filters = state.filters filters = state.filters
@ -1018,11 +1025,10 @@ object.Constructor('Page', BasePage, {
yield function(state){ yield function(state){
var outer_filters = state.filters var outer_filters = state.filters
state.filters = this.__parser__.normalizeFilters(filters) state.filters = this.__parser__.normalizeFilters(filters)
var res = (expand ? var res =
[...this.__parser__.parse(this, ast, state)] [...this.__parser__.parse(this, ast, state)]
: ast) .flat()
.flat() .join('')
.join('')
state.filters = outer_filters state.filters = outer_filters
return { data: res } } } }, return { data: res } } } },
// //
@ -1127,17 +1133,14 @@ object.Constructor('Page', BasePage, {
return } return }
var filters = args.filter var filters = args.filter
&& args.filter && Object.fromEntries(
.trim() Object.entries(
.split(/\\s+/g) args.filter
.trim()
.split(/\s+/g)))
return filters ? return filters ?
[...this.macros.filter.call(this, [...this.macros.filter.call(this, filters, text, state, false)]
Object.fromEntries(
Object.entries(filters ?? [])),
text,
state,
false)]
: text }, : text },
// //
// <slot name=<name>/> // <slot name=<name>/>