From c57b42cfd1f072d9f79e4c8db8921913067a6853 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 26 Sep 2018 02:08:46 +0300 Subject: [PATCH] updated format pattern... Signed-off-by: Alex A. Naanou --- diff.js | 1 + format.js | 54 +++++++++++++++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/diff.js b/diff.js index 2c94dcf..72350d7 100644 --- a/diff.js +++ b/diff.js @@ -719,6 +719,7 @@ object.makeConstructor('IN', Object.assign(Object.create(LogicType.prototype), { // cmp(X, {'moo', 333}) // ...this would also break on checking a recursive structure against // a recursive pattern... +// XXX should this also check inherited keys??? // XXX support Maps, ... var AT = module.AT = diff --git a/format.js b/format.js index f6af09f..4ef894c 100644 --- a/format.js +++ b/format.js @@ -22,6 +22,16 @@ var { } = diff +/*********************************************************************/ +// helpers... + +// OPT(key, value) -> true if key matches value or does not exist... +var OPT = function(key, value){ + return OR( + NOT(AT(key)), + AT(key, value)) } + + /*********************************************************************/ // @@ -41,24 +51,14 @@ module.VALUE = OR( // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Change A/B side values... -var SIDE_VALUES = -module.SIDE_VALUES = OR( - // A and B... - AND( - AT('A', VALUE), - AT('B', VALUE)), - // only A... - AT('A', VALUE), - // only B... - AT('B', VALUE)) - // Basic change... var CHANGE = module.CHANGE = AND( AT('path', L), - AT('type', OR(S, undefined)), - SIDE_VALUES) + OPT('type', S), + // NOTE: this matches if one or both of A and B exist and if they + // do the match VALUE... + AT(OR('A', 'B'), VALUE)) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -77,7 +77,7 @@ module.DIFF_FLAT = OR( var BASIC_CHANGE = module.BASIC_CHANGE = AND( AT('type', 'Basic'), - SIDE_VALUES) + AT(OR('A', 'B'), VALUE)) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -144,7 +144,20 @@ module.DIFF_TREE = OR( //--------------------------------------------------------------------- // Diff -- the root data structure... +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// Options... +var OPTIONS = +module.OPTIONS = AND( + OPT('tree_diff', B), + OPT('keep_none', B), + OPT('min_text_length', N), + OPT('no_attributes', B), + OPT('NONE', ANY), + OPT('EMPTY', ANY), + OPT('no_length', B), + OPT('cmp', F) ) +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var DIFF_OBJECT = module.DIFF_OBJECT = AND( // format metadata... @@ -153,16 +166,7 @@ module.DIFF_OBJECT = AND( AT('version', diff.FORMAT_VERSION), // instance metadata... - AT('options', - AND( - AT('tree_diff', OR(B, NULL)), - AT('keep_none', OR(B, NULL)), - AT('min_text_length', OR(N, NULL)), - AT('no_attributes', OR(B, NULL)), - AT('NONE', OR(ANY, NULL)), - AT('EMPTY', OR(ANY, NULL)), - AT('no_length', OR(B, NULL)), - AT('cmp', OR(F, NULL)) )), + AT('options', OPTIONS), AT('placeholders', AND( AT('NONE',