Top Level Namespace
Defined Under Namespace
Modules: Builtins, Chitin, Kernel
Classes: Array, Class, Coolline, Fixnum, IO, Object, Replay, String, Symbol
Instance Method Summary
collapse
Instance Method Details
#incomplete_string(string) ⇒ Object
Is this an incomplete string? If so, return the string character that it uses. Else return false.
23
24
25
26
27
|
# File 'lib/chitin/support.rb', line 23
def incomplete_string(string)
return '"' unless syntax_error_for(string + '"')
return "'" unless syntax_error_for(string + '\'')
return false
end
|
#need(file) ⇒ Object
1
2
3
|
# File 'lib/chitin.rb', line 1
def need(file)
require(File.dirname(File.expand_path(__FILE__)) + '/' + file)
end
|
#proper_string(val) ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/chitin/support.rb', line 1
def proper_string(val)
if (e = syntax_error_for(val)) &&
e.message =~ /unterminated string meets end of file/
if syntax_error_for(val + '\'')
unless syntax_error_for(val + '"')
val << '"'
end
else
val << '\''
end
end
val
end
|
#shellsplit_keep_quotes(line) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/chitin/support.rb', line 37
def shellsplit_keep_quotes(line)
words = []
field = ''
line.scan(/\G\s*(?>([^\s\\\'\"]+)|('[^\']*')|("(?:[^\"\\]|\\.)*")|(\\.?)|(\S))(\s|\z)?/m) do
|word, sq, dq, esc, garbage, sep|
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1'))
if sep
words << field
field = ''
end
end
words
end
|
#syntax_error_for(code) ⇒ Object
If the code is syntactically correct, return nil. Else, return the error.
31
32
33
34
35
|
# File 'lib/chitin/support.rb', line 31
def syntax_error_for(code)
eval "return nil\n#{code}"
rescue SyntaxError => e
e
end
|