Index: trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js |
— | — | @@ -0,0 +1,52 @@ |
| 2 | +var dumpReader = require('./dumpReader.js'), |
| 3 | + events = require('events'), |
| 4 | + optimist = require('optimist'); |
| 5 | + |
| 6 | +function DumpGrepper ( regexp ) { |
| 7 | + // inherit from EventEmitter |
| 8 | + //events.EventEmitter.call(this); |
| 9 | + this.re = regexp; |
| 10 | +} |
| 11 | + |
| 12 | +DumpGrepper.prototype = new events.EventEmitter(); |
| 13 | +DumpGrepper.prototype.constructor = DumpGrepper; |
| 14 | + |
| 15 | +DumpGrepper.prototype.grepRev = function ( revision ) { |
| 16 | + var bits = revision.text.split( this.re ); |
| 17 | + if ( bits.length > 1 ) { |
| 18 | + this.emit( 'match', revision, bits ); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +module.exports.DumpGrepper = DumpGrepper; |
| 23 | + |
| 24 | +if (module === require.main) { |
| 25 | + var argv = optimist.usage( 'Usage: $0 <regexp>', { |
| 26 | + 'i': { |
| 27 | + description: 'Case-insensitive matching', |
| 28 | + 'boolean': true, |
| 29 | + 'default': false |
| 30 | + } |
| 31 | + } ).argv; |
| 32 | + |
| 33 | + console.log( argv ); |
| 34 | + |
| 35 | + var flags = ''; |
| 36 | + if(argv.i) { |
| 37 | + flags += 'i'; |
| 38 | + } |
| 39 | + |
| 40 | + var reader = new dumpReader.DumpReader(), |
| 41 | + grepper = new DumpGrepper( new RegExp( '(' + argv._[0] + ')', flags ) ); |
| 42 | + |
| 43 | + reader.on( 'revision', grepper.grepRev.bind( grepper ) ); |
| 44 | + grepper.on( 'match', function ( revision, bits ) { |
| 45 | + console |
| 46 | + console.log( 'Match:' + revision.page.title ) |
| 47 | + console.log( bits.map( function ( s ) { return s.substr(0, 40) } ) ); |
| 48 | + } ); |
| 49 | + process.stdin.setEncoding('utf8'); |
| 50 | + process.stdin.on('data', reader.push.bind(reader) ); |
| 51 | + process.stdin.resume(); |
| 52 | +} |
| 53 | + |
Property changes on: trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 54 | + native |