Module: Rib::Multiline
- Extended by:
- Plugin
- Defined in:
- lib/rib/core/multiline.rb
Overview
Constant Summary collapse
- BINARY_OP =
test those: ruby -e ‘“’ ruby -e ‘{’ ruby -e ‘[’ ruby -e ‘(’ ruby -e ‘/’ ruby -e ‘class C’ ruby -e ‘def f’ ruby -e ‘begin’ ruby -e ‘eval ”1+1.to_i “’ ruby -e ‘eval ”11.to_i -“’ ruby -e ‘eval ”1+1.to_i *“’ ruby -e ‘eval ”1+1.to_i /“’ ruby -e ‘eval ”1+1.to_i &“’ ruby -e ‘eval ”1+1.to_i |“’ ruby -e ‘eval ”1+1.to_i ^“’
%w[tUPLUS tUMINUS tSTAR tREGEXP_BEG tAMPER]
- RUBY20_IO =
%w[unary+ unary- * tREGEXP_BEG &]. map(&Regexp.method(:escape))
- ERROR_REGEXP =
case engine when 'ruby' ; Regexp.new( [ # string or regexp "unterminated \\w+ meets end of file", # mri and rubinius "unexpected (#{BINARY_OP.join('|')}), expecting \\$end", "syntax error, unexpected \\$end" , # ruby 2.0 "syntax error, unexpected end-of-input", "syntax error, unexpected (#{RUBY20_IO.join('|')})," ].join('|')) when 'rbx' ; Regexp.new( [ # string or regexp "unterminated \\w+ meets end of file", # mri and rubinius "syntax error, unexpected \\$end" , # rubinius "expecting keyword_end" , "expecting keyword_then" , "expecting keyword_when" , "expecting keyword_do_cond" , "expecting \\$end" , "expecting '.+'( or '.+')*" , "missing '.+' for '.+' started on line \\d+"].join('|')) when 'jruby'; Regexp.new( [ # string or regexp "unterminated \\w+ meets end of file", # jruby "syntax error, unexpected" \ " t(UPLUS|UMINUS|STAR|REGEXP_BEG|AMPER)", "syntax error, unexpected end-of-file", # jruby 9.0.4.0 "formal argument must be local variable" ].join('|')) end
Instance Attribute Summary
Attributes included from Plugin
Instance Method Summary collapse
- #handle_interrupt ⇒ Object
- #loop_eval(input) ⇒ Object
-
#loop_once ⇒ Object
————— Rib API —————.
-
#multiline?(err) ⇒ Boolean
————— Plugin API —————.
- #multiline_prompt ⇒ Object
- #print_eval_error(err) ⇒ Object
- #prompt ⇒ Object
Methods included from Plugin
disable, disabled?, enable, enabled?, extended
Instance Method Details
#handle_interrupt ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rib/core/multiline.rb', line 106 def handle_interrupt return super if Multiline.disabled? if multiline_buffer.empty? super else print "[removed this line: #{multiline_buffer.pop}]" super throw :rib_multiline end end |
#loop_eval(input) ⇒ Object
81 82 83 84 85 |
# File 'lib/rib/core/multiline.rb', line 81 def loop_eval input return super if Multiline.disabled? multiline_buffer << input super(multiline_buffer.join("\n")) end |
#loop_once ⇒ Object
————— Rib API —————
71 72 73 74 75 76 77 78 79 |
# File 'lib/rib/core/multiline.rb', line 71 def loop_once return super if Multiline.disabled? result = nil catch(:rib_multiline) do result = super multiline_buffer.clear end result end |
#multiline?(err) ⇒ Boolean
————— Plugin API —————
119 120 121 |
# File 'lib/rib/core/multiline.rb', line 119 def multiline? err err.is_a?(SyntaxError) && err. =~ ERROR_REGEXP end |
#multiline_prompt ⇒ Object
123 124 125 |
# File 'lib/rib/core/multiline.rb', line 123 def multiline_prompt config[:multiline_prompt] ||= '| ' end |