notes, tweaking and experimenting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-11-20 02:14:50 +03:00
parent d21565ab64
commit 652ccfae88
4 changed files with 36 additions and 9 deletions

View File

@ -838,8 +838,9 @@ object.Constructor('Page', BasePage, {
// -> <func>(<state>)
// -> ...
//
// XXX do we need to make .macro.__proto__ module level object???
// XXX ASYNC make these support async page getters...
macros: {
macros: { __proto__: {
//
// @(<name>[ <default>][ local])
// @(name=<name>[ default=<default>][ local])
@ -855,6 +856,7 @@ object.Constructor('Page', BasePage, {
// - .renderer
// - .root
//
// NOTE: default value is parsed when accessed...
arg: Macro(
['name', 'default', ['local']],
function(args){
@ -868,7 +870,8 @@ object.Constructor('Page', BasePage, {
args.name
: v
return v
|| args.default }),
|| (args.default
&& this.parse(args.default)) }),
'': Macro(
['name', 'default', ['local']],
function(args){
@ -887,6 +890,7 @@ object.Constructor('Page', BasePage, {
// <filter> <filter-spec>
// | -<filter> <filter-spec>
//
// XXX REVISE...
filter: function(args, body, state, expand=true){
var that = this
@ -1299,6 +1303,9 @@ object.Constructor('Page', BasePage, {
'content': ['slot'],
// XXX EXPERIMENTAL...
//
// NOTE: var value is parsed only on assignment and not on dereferencing...
//
// XXX INC_DEC do we need inc/dec and parent???
'var': Macro(
['name', 'text',
@ -1616,7 +1623,23 @@ object.Constructor('Page', BasePage, {
// nesting rules...
'else': ['macro'],
'join': ['macro'],
},
} },
// XXX EXPERIMENTAL...
//
// Define a global macro...
// .defmacro(<name>, <func>)
// .defmacro(<name>, <args>, <func>)
// -> this
//
// XXX do we need this???
defmacro: function(name, args, func){
this.macros[name] =
arguments.length == 2 ?
arguments[1]
: Macro(args, func)
return this },
// direct actions...
//
@ -2413,8 +2436,8 @@ module.System = {
text: object.doc`
<slot title/>
<div class="error">
<div class="msg" wikiwords="no">ParseError: @(msg)</div>
Page: [@(path)]
<div class="msg" wikiwords="no">ParseError: @(msg "no message")</div>
Page: [@(path "@source(./path)")]
</div> `,},
RecursionError: {
text: 'RECURSION ERROR: @source(../path)' },

View File

@ -256,7 +256,7 @@ module.BaseParser = {
// XXX should this be cached???
var macro_pattern = this.MACRO_PATTERN
?? this.buildMacroPattern(Object.keys(page.macros))
?? this.buildMacroPattern(Object.deepKeys(page.macros))
var macro_pattern_groups = this.MACRO_PATTERN_GROUPS
?? this.countMacroPatternGroups()
var macro_args_pattern = this.MACRO_ARGS_PATTERN
@ -482,7 +482,7 @@ module.BaseParser = {
// XXX add line number and page path...
'@include("./ParseError'
+':path='
// XXX use pwiki.encodeElem(..) ???
// XXX use pwpath.encodeElem(..) ???
+ page.path
+':msg='
+ err.message

View File

@ -158,7 +158,7 @@ body.loading .page.spinner span {
.error {
background: lightyellow;
padding: 1em;
box-shadow: inset 3px 5px 15px 5px rgba(0,0,0,0.05);
box-shadow: inset 3px 5px 15px 5px rgba(0,0,0,0.03);
border: dashed red 1px;
}

View File

@ -36,8 +36,9 @@
* -
*
*
* XXX BUG? can't use < and > (both?) in page title...
* XXX parser: error handling: revise page quoting...
* ...need a standard mechanism to quote urls, url-args and paths...
* XXX BUG? can't use < and > (both?) in page title...
* XXX parser: error handling: add line number + context... (???)
* XXX BUG: parser:
* This will break:
@ -45,6 +46,9 @@
* This will not:
* await pwiki.parse('<macro src="../tags" join=", ">@source(.)</macro>')
* XXX ASAP test: can we store the file handler with permissions in a ServiceWorker??
* XXX Q: do we need macros for printing errors and the like???
* XXX Q: do we need a macro to define user macros???
* ...see: <page>.defmacro(..)
* XXX the parser should handle all action return values, including:
* - lists -- XXX
* - strings -- DONE