mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-28 18:40:09 +00:00
94 lines
2.2 KiB
JavaScript
94 lines
2.2 KiB
JavaScript
/**********************************************************************
|
|
*
|
|
*
|
|
*
|
|
**********************************************************************/
|
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
|
(function(require){ var module={} // make module AMD/node compatible...
|
|
/*********************************************************************/
|
|
|
|
var diff = require('./diff')
|
|
var {
|
|
ANY,
|
|
BOOL, NUMBER, STRING, ARRAY, FUNCTION,
|
|
OR, AND, NOT,
|
|
AT, OF, IN,
|
|
|
|
EMPTY, NONE,
|
|
} = diff
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
// XXX need better mismatch checking -- ideally stating the exact spot
|
|
// where we did not match...
|
|
//
|
|
|
|
var VALUE =
|
|
module.VALUE = OR(
|
|
EMPTY,
|
|
NONE,
|
|
ANY)
|
|
|
|
|
|
var CHANGE =
|
|
module.CHANGE = AND(
|
|
AT('path', ARRAY),
|
|
// XXX optional...
|
|
// ...see DIFF_OBJECT's options for description...
|
|
AT('type', OR(STRING, undefined)),
|
|
OR(
|
|
// A ans B...
|
|
AND(
|
|
AT('A', VALUE),
|
|
AT('B', VALUE)),
|
|
// only A...
|
|
AT('A', VALUE),
|
|
// only B...
|
|
AT('B', VALUE)))
|
|
|
|
|
|
var DIFF_FORMAT_FLAT =
|
|
module.DIFF_FORMAT_FLAT = ARRAY(CHANGE)
|
|
|
|
|
|
// XXX it makes sense to make this a recursive pattern...
|
|
// ...need to check if we stop on a recursive pattern...
|
|
var DIFF_FORMAT_TREE =
|
|
module.DIFF_FORMAT_TREE = ANY
|
|
|
|
|
|
var DIFF_OBJECT =
|
|
module.DIFF_OBJECT = AND(
|
|
AT('format', diff.FORMAT_NAME),
|
|
//AT('version', STRING(/\d+\.\d+\.\d+/)),
|
|
AT('version', diff.FORMAT_VERSION),
|
|
|
|
AT('options', AND(
|
|
AT('tree_diff', OR(BOOL, null)),
|
|
AT('keep_none', OR(BOOL, null)),
|
|
AT('min_text_length', OR(NUMBER, null)),
|
|
AT('no_attributes', OR(BOOL, null)),
|
|
AT('NONE', OR(ANY, null)),
|
|
AT('EMPTY', OR(ANY, null)),
|
|
AT('no_length', OR(BOOL, null)),
|
|
AT('cmp', OR(FUNCTION, null)) )),
|
|
AT('placeholders', AND(
|
|
// XXX would be nice to store these and to use them to test later...
|
|
AT('NONE', ANY),
|
|
AT('EMPTY', ANY))),
|
|
|
|
AT('timestamp', NUMBER),
|
|
OR(
|
|
AND(
|
|
AT('structure', 'flat'),
|
|
AT('diff', DIFF_FORMAT_FLAT)),
|
|
AND(
|
|
AT('structure', 'tree'),
|
|
AT('diff', DIFF_FORMAT_TREE))) )
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
* vim:set ts=4 sw=4 : */ return module })
|