mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Command interpreter takes x,x as an address
This commit is contained in:
@@ -27,3 +27,11 @@ describe "CommandInterpreter", ->
|
||||
interpreter.eval(editor, 's/current/foo/g')
|
||||
expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);'
|
||||
|
||||
describe "when prefixed with an address", ->
|
||||
it "only makes substitutions within given lines", ->
|
||||
interpreter.eval(editor, '4,7s/ /!/g')
|
||||
expect(buffer.lineForRow(2)).toBe ' if (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(3)).toBe '!!!!var!pivot!=!items.shift(),!current,!left!=![],!right!=![];'
|
||||
expect(buffer.lineForRow(4)).toBe '!!!!while(items.length!>!0)!{'
|
||||
expect(buffer.lineForRow(5)).toBe '!!!!!!current!=!items.shift();'
|
||||
expect(buffer.lineForRow(6)).toBe ' current < pivot ? left.push(current) : right.push(current);'
|
||||
|
||||
@@ -7,6 +7,6 @@ class CommandInterpreter
|
||||
@parser = PEG.buildParser(fs.read(require.resolve 'commands.pegjs'))
|
||||
|
||||
eval: (editor, command) ->
|
||||
operation = @parser.parse(command)
|
||||
operation.execute(editor)
|
||||
operations = @parser.parse(command)
|
||||
operation.execute(editor) for operation in operations
|
||||
|
||||
|
||||
14
src/atom/command-interpreter/address.coffee
Normal file
14
src/atom/command-interpreter/address.coffee
Normal file
@@ -0,0 +1,14 @@
|
||||
Range = require 'range'
|
||||
|
||||
module.exports =
|
||||
class Address
|
||||
startRow: null
|
||||
endRow: null
|
||||
|
||||
constructor: (start, end) ->
|
||||
@startRow = start - 1
|
||||
@endRow = end - 1
|
||||
|
||||
execute: (editor) ->
|
||||
range = new Range([@startRow, 0], [@endRow, 0])
|
||||
editor.getSelection().setBufferRange(range)
|
||||
@@ -1,10 +1,27 @@
|
||||
{
|
||||
var Substitution = require('command-interpreter/substitution');
|
||||
var Address = require('command-interpreter/address');
|
||||
}
|
||||
|
||||
start
|
||||
= address:address? _ command:substitution {
|
||||
var operations = [];
|
||||
if (address) operations.push(address);
|
||||
operations.push(command);
|
||||
return operations;
|
||||
}
|
||||
|
||||
address
|
||||
= start:integer _ ',' _ end:integer {
|
||||
return new Address(start, end)
|
||||
}
|
||||
|
||||
substitution
|
||||
= "s" _ "/" find:([^/]*) "/" replace:([^/]*) "/" _ options:[g]* {
|
||||
return new Substitution(find.join(''), replace.join(''), options)
|
||||
return new Substitution(find.join(''), replace.join(''), options);
|
||||
}
|
||||
|
||||
integer
|
||||
= digits:[0-9]+ { return parseInt(digits.join('')); }
|
||||
|
||||
_ = " "*
|
||||
|
||||
Reference in New Issue
Block a user