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(
[
"unterminated \\w+ meets end of file",
"unexpected (#{BINARY_OP.join('|')}), expecting \\$end",
"syntax error, unexpected \\$end" ,
"syntax error, unexpected end-of-input",
"syntax error, unexpected (#{RUBY20_IO.join('|')}),"
].join('|'))
when 'rbx' ; Regexp.new(
[
"unterminated \\w+ meets end of file",
"syntax error, unexpected \\$end" ,
"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(
[
"unterminated \\w+ meets end of file",
"syntax error, unexpected" \
" t(UPLUS|UMINUS|STAR|REGEXP_BEG|AMPER)",
"syntax error, unexpected end-of-file",
"formal argument must be local variable" ].join('|'))
end
Instance Attribute Summary
Attributes included from Plugin
#disabled
Instance Method Summary
collapse
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
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
119
120
121
|
# File 'lib/rib/core/multiline.rb', line 119
def multiline? err
err.is_a?(SyntaxError) && err.message =~ ERROR_REGEXP
end
|
#multiline_prompt ⇒ Object
123
124
125
|
# File 'lib/rib/core/multiline.rb', line 123
def multiline_prompt
config[:multiline_prompt] ||= '| '
end
|
#print_eval_error(err) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/rib/core/multiline.rb', line 87
def print_eval_error err
return super if Multiline.disabled?
if multiline?(err)
throw :rib_multiline
else
super
end
end
|
#prompt ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/rib/core/multiline.rb', line 96
def prompt
return super if Multiline.disabled?
if multiline_buffer.empty?
super
else
mprompt = multiline_prompt[0, config[:prompt].size]
"#{' '*(config[:prompt].size-mprompt.size)}#{mprompt}"
end
end
|