Last active
December 17, 2015 19:49
-
-
Save nelstrom/5663083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%{ | |
machine vim_print; | |
action H { @head = p } | |
action T { @tail = p } | |
action return { fret; } | |
action push_insert_mode { fcall insert_mode; } | |
action EmitMotion { @events << {motion: strokes} } | |
action EmitSwitch { @events << {switch: strokes} } | |
action EmitInput { @events << {input: strokes} } | |
action EmitEscape { @events << {escape: '<Esc>' } } | |
escape = 27 >H@T @EmitEscape; | |
input = (any - escape) >H@T @EmitInput; | |
motion = [hjklbwe0] >H@T @EmitMotion; | |
switch = [iIaAsSoO] >H@T @EmitSwitch; | |
insert_mode := ( | |
input* | |
escape @return | |
); | |
normal_mode := ( | |
motion | | |
switch @push_insert_mode | |
)*; | |
}%% | |
class VimParser | |
attr_accessor :head, :tail, :data | |
def initialize(listener) | |
@events = listener | |
%% write data; | |
end | |
def process(input) | |
@data = input.unpack("c*") | |
eof = @data.length | |
stack = [] | |
%% write init; | |
%% write exec; | |
end | |
def strokes | |
@data[@head..@tail].pack('c*') | |
end | |
end | |
VimParser.new(recorder = []).process("helihello\e") | |
puts recorder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment