fancy 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/README.md +14 -14
  2. data/Rakefile +16 -4
  3. data/bin/fancy +3 -0
  4. data/bin/fspec +20 -0
  5. data/bin/fyi +27 -11
  6. data/bin/ifancy +1 -1
  7. data/boot/fancy_ext.rb +1 -0
  8. data/boot/fancy_ext/block_env.rb +1 -9
  9. data/boot/fancy_ext/delegator.rb +64 -0
  10. data/boot/fancy_ext/object.rb +4 -0
  11. data/boot/fancy_ext/thread.rb +4 -0
  12. data/boot/load.rb +5 -1
  13. data/boot/rbx-compiler/compiler/ast.rb +0 -1
  14. data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
  15. data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
  16. data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
  17. data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
  18. data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
  19. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  20. data/boot/rbx-compiler/parser/lexer.lex +5 -11
  21. data/boot/rbx-compiler/parser/parser.rb +16 -5
  22. data/boot/rbx-compiler/parser/parser.y +39 -24
  23. data/doc/api/fancy.css +1 -1
  24. data/doc/api/fancy.jsonp +1 -1
  25. data/doc/api/fdoc.js +22 -4
  26. data/doc/api/index.html +5 -6
  27. data/doc/api/jquery-ui.min.js +401 -0
  28. data/doc/api/jquery.tools.min.js +192 -0
  29. data/doc/api/themeswitchertool.js +250 -0
  30. data/doc/features.md +17 -0
  31. data/examples/actor_bunnies.fy +32 -0
  32. data/examples/actors.fy +26 -0
  33. data/examples/actors_primitive.fy +27 -0
  34. data/examples/actors_ring.fy +37 -0
  35. data/examples/armstrong_numbers.fy +1 -1
  36. data/examples/array.fy +7 -9
  37. data/examples/async_send.fy +1 -2
  38. data/examples/blocks.fy +4 -4
  39. data/examples/call_with_receiver.fy +1 -1
  40. data/examples/class.fy +1 -1
  41. data/examples/default_args.fy +4 -1
  42. data/examples/define_methods.fy +2 -2
  43. data/examples/echo.fy +1 -1
  44. data/examples/factorial.fy +1 -1
  45. data/examples/future_composition.fy +2 -2
  46. data/examples/futures.fy +0 -5
  47. data/examples/game_of_life.fy +1 -1
  48. data/examples/person.fy +1 -1
  49. data/lib/argv.fy +7 -2
  50. data/lib/array.fy +109 -42
  51. data/lib/block.fy +39 -14
  52. data/lib/boot.fy +2 -0
  53. data/lib/class.fy +2 -0
  54. data/lib/compiler/ast.fy +2 -1
  55. data/lib/compiler/ast/assign.fy +2 -3
  56. data/lib/compiler/ast/async_send.fy +1 -15
  57. data/lib/compiler/ast/class_def.fy +2 -1
  58. data/lib/compiler/ast/expression_list.fy +4 -5
  59. data/lib/compiler/ast/future_send.fy +1 -10
  60. data/lib/compiler/ast/goto.fy +46 -0
  61. data/lib/compiler/ast/identifier.fy +9 -7
  62. data/lib/compiler/ast/literals.fy +8 -1
  63. data/lib/compiler/ast/match.fy +14 -4
  64. data/lib/compiler/ast/message_send.fy +34 -6
  65. data/lib/compiler/ast/method_def.fy +6 -6
  66. data/lib/compiler/ast/node.fy +3 -3
  67. data/lib/compiler/ast/range.fy +1 -0
  68. data/lib/compiler/ast/script.fy +0 -2
  69. data/lib/compiler/ast/singleton_method_def.fy +2 -4
  70. data/lib/compiler/ast/string_interpolation.fy +17 -0
  71. data/lib/compiler/ast/super.fy +5 -4
  72. data/lib/compiler/ast/try_catch.fy +8 -6
  73. data/lib/compiler/ast/tuple_literal.fy +3 -2
  74. data/lib/compiler/command.fy +0 -1
  75. data/lib/compiler/compiler.fy +1 -5
  76. data/lib/compiler/stages.fy +6 -14
  77. data/lib/documentation.fy +57 -46
  78. data/lib/enumerable.fy +257 -23
  79. data/lib/enumerator.fy +122 -15
  80. data/lib/false_class.fy +10 -1
  81. data/lib/fancy_spec.fy +263 -61
  82. data/lib/fdoc.fy +11 -25
  83. data/lib/fiber.fy +11 -0
  84. data/lib/file.fy +8 -11
  85. data/lib/future.fy +84 -5
  86. data/lib/hash.fy +65 -14
  87. data/lib/integer.fy +35 -0
  88. data/lib/iteration.fy +54 -29
  89. data/lib/message.fy +6 -0
  90. data/lib/method.fy +0 -16
  91. data/lib/nil_class.fy +58 -8
  92. data/lib/number.fy +49 -22
  93. data/lib/object.fy +371 -65
  94. data/lib/package.fy +24 -1
  95. data/lib/package/installer.fy +5 -9
  96. data/lib/package/specification.fy +2 -2
  97. data/lib/parser/ext/lexer.lex +15 -11
  98. data/lib/parser/ext/parser.y +70 -23
  99. data/lib/parser/methods.fy +33 -14
  100. data/lib/proxy.fy +33 -3
  101. data/lib/range.fy +28 -0
  102. data/lib/rbx.fy +3 -1
  103. data/lib/rbx/actor.fy +53 -0
  104. data/lib/rbx/alpha.fy +31 -0
  105. data/lib/rbx/array.fy +21 -12
  106. data/lib/rbx/bignum.fy +6 -2
  107. data/lib/rbx/block.fy +23 -26
  108. data/lib/rbx/class.fy +54 -2
  109. data/lib/rbx/code_loader.fy +8 -4
  110. data/lib/rbx/date.fy +9 -0
  111. data/lib/rbx/directory.fy +18 -0
  112. data/lib/rbx/environment_variables.fy +1 -0
  113. data/lib/rbx/exception.fy +9 -2
  114. data/lib/rbx/fiber.fy +22 -4
  115. data/lib/rbx/file.fy +5 -5
  116. data/lib/rbx/fixnum.fy +5 -0
  117. data/lib/rbx/float.fy +11 -3
  118. data/lib/rbx/hash.fy +31 -16
  119. data/lib/rbx/integer.fy +1 -0
  120. data/lib/rbx/io.fy +17 -7
  121. data/lib/rbx/match_data.fy +15 -4
  122. data/lib/rbx/method.fy +40 -7
  123. data/lib/rbx/name_error.fy +4 -0
  124. data/lib/rbx/object.fy +92 -24
  125. data/lib/rbx/range.fy +20 -6
  126. data/lib/rbx/regexp.fy +11 -3
  127. data/lib/rbx/string.fy +51 -1
  128. data/lib/rbx/stringio.fy +17 -0
  129. data/lib/rbx/symbol.fy +15 -1
  130. data/lib/rbx/system.fy +20 -2
  131. data/lib/rbx/tcp_server.fy +4 -1
  132. data/lib/rbx/tcp_socket.fy +11 -0
  133. data/lib/rbx/time.fy +6 -0
  134. data/lib/rbx/tuple.fy +14 -5
  135. data/lib/set.fy +144 -29
  136. data/lib/stack.fy +42 -11
  137. data/lib/string.fy +118 -8
  138. data/lib/struct.fy +13 -3
  139. data/lib/symbol.fy +21 -2
  140. data/lib/thread_pool.fy +2 -1
  141. data/lib/true_class.fy +45 -7
  142. data/lib/tuple.fy +27 -9
  143. data/lib/version.fy +2 -2
  144. data/ruby_lib/fancy +43 -0
  145. data/ruby_lib/fdoc +23 -0
  146. data/ruby_lib/fspec +3 -0
  147. data/ruby_lib/fyi +3 -0
  148. data/ruby_lib/ifancy +3 -0
  149. data/tests/argv.fy +5 -9
  150. data/tests/array.fy +323 -196
  151. data/tests/assignment.fy +29 -29
  152. data/tests/block.fy +72 -59
  153. data/tests/class.fy +227 -138
  154. data/tests/control_flow.fy +83 -51
  155. data/tests/documentation.fy +8 -8
  156. data/tests/enumerable.fy +8 -0
  157. data/tests/enumerator.fy +47 -29
  158. data/tests/exception.fy +49 -32
  159. data/tests/file.fy +28 -28
  160. data/tests/fixnum.fy +170 -0
  161. data/tests/future.fy +24 -7
  162. data/tests/hash.fy +55 -38
  163. data/tests/method.fy +50 -43
  164. data/tests/nil_class.fy +37 -37
  165. data/tests/object.fy +152 -70
  166. data/tests/pattern_matching.fy +67 -31
  167. data/tests/range.fy +6 -6
  168. data/tests/set.fy +101 -4
  169. data/tests/stack.fy +14 -5
  170. data/tests/string.fy +115 -61
  171. data/tests/stringio.fy +18 -0
  172. data/tests/struct.fy +27 -0
  173. data/tests/symbol.fy +19 -6
  174. data/tests/true_class.fy +34 -34
  175. data/tests/tuple.fy +30 -12
  176. metadata +103 -81
  177. data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
  178. data/examples/actor.fy +0 -37
  179. data/examples/curl_async.fy +0 -37
  180. data/lib/compiler/ast/require.fy +0 -15
  181. data/tests/number.fy +0 -135
  182. data/tests/parsing/sexp.fy +0 -50
@@ -4,48 +4,79 @@ class Stack {
4
4
  """
5
5
 
6
6
  def initialize {
7
+ """
8
+ Initializes a new Stack.
9
+ """
10
+
7
11
  @arr = []
8
12
  }
9
13
 
10
14
  def initialize: size {
11
- "Initializes a new Stack with a given size."
15
+ """
16
+ @size Initial size of the new Stack.
17
+
18
+ Initializes a new Stack with a given size.
19
+ """
12
20
 
13
21
  @arr = Array new: size
14
22
  }
15
23
 
16
24
  def push: obj {
17
- "Pushes a value onto the Stack."
18
-
19
- @arr << obj
20
- }
25
+ """
26
+ @obj Object to be pushed onto @self.
21
27
 
22
- def << obj {
23
- "Same as Stack#push:."
28
+ Pushes a value onto the Stack.
29
+ """
24
30
 
25
31
  @arr << obj
26
32
  }
27
33
 
34
+ alias_method: '<< for: 'push:
35
+
28
36
  def pop {
29
- "Pops the top-of-stack element from the Stack and returns it."
37
+ """
38
+ @return Top-of-stack element.
39
+
40
+ Pops the top-of-stack element from the Stack and returns it.
41
+ """
30
42
 
31
43
  @arr remove_at: (size - 1)
32
44
  }
33
45
 
34
46
  def top {
35
- "Returns the top-of-stack element."
47
+ """
48
+ @return The top-of-stack element.
49
+ """
36
50
 
37
51
  @arr last
38
52
  }
39
53
 
40
54
  def size {
41
- "Returns the size of the Stack."
55
+ """
56
+ @return Size of the Stack.
57
+ """
42
58
 
43
59
  @arr size
44
60
  }
45
61
 
46
62
  def empty? {
47
- "Indicates, if the Stack is empty."
63
+ """
64
+ @return @true if empty, otherwise @false.
65
+
66
+ Indicates, if the Stack is empty.
67
+ """
48
68
 
49
69
  @arr empty?
50
70
  }
71
+
72
+ def each: block {
73
+ """
74
+ @block @Block@ to be called with each element in @self.
75
+ @return @self.
76
+
77
+ Calls a given @Block@ with each element in @self, starting with the top of stack element.
78
+ """
79
+
80
+ @arr reverse each: block
81
+ }
51
82
  }
@@ -11,19 +11,33 @@ class String {
11
11
  include: FancyEnumerable
12
12
 
13
13
  def ++ other {
14
- "Concatenate the String with another String"
14
+ """
15
+ @other Object to concatenate @self with as a @String@.
16
+ @return Concatenation of @self with @other.
17
+
18
+ Concatenate @self with another Object's @String@ representation.
19
+ \"foo\” ++ 42 # => \”foo42\”
20
+ """
15
21
 
16
22
  self + (other to_s)
17
23
  }
18
24
 
19
25
  def whitespace? {
20
- "Indicates, if a String is empty or a single whitespace character."
26
+ """
27
+ @return @true, if @self consists only of a single whitespace character or is empty, @false otherwise.
28
+
29
+ Indicates, if a @String@ is empty or a single whitespace character.
30
+ """
21
31
 
22
32
  empty? or: (self == " ")
23
33
  }
24
34
 
25
35
  def blank? {
26
- "Indicates, if a String consists only of whitespace."
36
+ """
37
+ @return @true if @self consists only of whitespace, @false otherwise.
38
+
39
+ Indicates, if a @String@ consists only of whitespace.
40
+ """
27
41
 
28
42
  self =~ /^\s*$/ if_true: {
29
43
  true
@@ -33,26 +47,122 @@ class String {
33
47
  }
34
48
 
35
49
  def * num {
36
- "Returns a string that is the num-fold concatenation of itself."
50
+ """
51
+ @num Amount of concatenations to do with @self.
52
+ @return @String@ that is the num-fold concatenation of @self.
53
+
54
+ Returns a @String@ that is the num-fold concatenation of itself.
55
+ \"foo\" * 3 # => \”foofoofoo\"
56
+ """
37
57
 
38
58
  str = ""
39
59
  num to_i times: {
40
- str = str ++ self
60
+ str << self
41
61
  }
42
62
  str
43
63
  }
44
64
 
45
65
  def words {
66
+ """
67
+ @return @Array@ of all the whitespace seperated words in @self.
68
+
69
+ \"hello world\" words # => [\"hello\", \"world\"]
70
+ """
71
+
46
72
  split
47
73
  }
48
74
 
49
75
  def raise! {
50
- "Raises a new StdError with self as the message."
51
- StdError new: self . raise!
76
+ """
77
+ Raises a new @StandardError@ with self as the message.
78
+ """
79
+
80
+ StandardError new: self . raise!
52
81
  }
53
82
 
54
83
  def rest {
55
- "Returns a @String@ containing all but the first character."
84
+ """
85
+ @return @String@ containing all but the first character.
86
+
87
+ Returns a @String@ containing all but the first character.
88
+ \"hello\" rest # => \"ello\"
89
+ """
90
+
56
91
  from: 1 to: -1
57
92
  }
93
+
94
+ def lines {
95
+ """
96
+ @return @Array@ of all the lines in @self.
97
+
98
+ Returns the lines of a @String@ as an @Array@.
99
+ """
100
+
101
+ split: "\n"
102
+ }
103
+
104
+ def << object {
105
+ """
106
+ @object An @Object@ who's @String@ representation will be appended to @self.
107
+ @return @self, but modified.
108
+
109
+ Appends @object's @String@ representation to @self.
110
+
111
+ Example usage:
112
+ str = \"hello\"
113
+ str << \" \"
114
+ str << 42
115
+ str # => \"hello 42\"
116
+ """
117
+
118
+ append: $ object to_s
119
+ }
120
+
121
+ def skip_leading_indentation {
122
+ """
123
+ Remove leading white space for multi-line strings.
124
+ This method expects the first character to be an line return.
125
+ """
126
+
127
+ str = self
128
+ m = /^(\r?\n)*(\s+)/ match(str)
129
+ str = str strip()
130
+ if: m then: {
131
+ pattern = "^ {" ++ (m[2] size()) ++ "}"
132
+ rex = Regexp.new(pattern)
133
+ str = str gsub(rex, "");
134
+ }
135
+ str
136
+ }
137
+
138
+ def characters {
139
+ """
140
+ @return @Array@ of all characters (as @String@) in @self.
141
+ """
142
+
143
+ scan: /./
144
+ }
145
+
146
+ def character {
147
+ """
148
+ @return @Fixnum@ (byte / ASCII) value of first character in @self.
149
+ """
150
+
151
+ self bytes each: |c| {
152
+ return c
153
+ }
154
+ return nil
155
+ }
156
+
157
+ def bytes {
158
+ """
159
+ @return @FancyEnumerator@ of all bytes (@Fixnum@ values) in @self.
160
+ """
161
+
162
+ enum = bytes()
163
+ def enum each: block {
164
+ each(&block)
165
+ }
166
+ FancyEnumerator new: enum
167
+ }
58
168
  }
@@ -1,7 +1,17 @@
1
1
  class Struct {
2
- def Struct new: fields {
3
- struct = new(*fields)
4
- struct read_write_slots: fields
2
+ """
3
+ Structs are light-weight classes with predefined read-writable slots.
4
+ """
5
+
6
+ def Struct new: slots {
7
+ """
8
+ @slots @Array@ of slotnames the new Struct should contain.
9
+
10
+ Creates a new Struct class with the given slots.
11
+ """
12
+
13
+ struct = new(*slots)
14
+ struct read_write_slots: slots
5
15
 
6
16
  def struct new: values {
7
17
  new(*values)
@@ -14,10 +14,29 @@ class Symbol {
14
14
  """
15
15
 
16
16
  if: (arg is_a?: Array) then: {
17
- arg first send_message: self with_params: $ arg rest
17
+ arg first receive_message: self with_params: $ arg rest
18
18
  } else: {
19
- arg send_message: self
19
+ arg receive_message: self
20
20
  }
21
21
  }
22
22
 
23
+ def call {
24
+ """
25
+ Sends @self as message to the sender in its context.
26
+ Example:
27
+ 'foo call
28
+ # => same as
29
+ self foo
30
+
31
+ if: x then: 'foo else: 'bar
32
+ # same as:
33
+ if: x then: { self foo } else: { self bar }
34
+ """
35
+
36
+ binding = Binding setup(Rubinius VariableScope of_sender(),
37
+ Rubinius CompiledMethod of_sender(),
38
+ Rubinius StaticScope of_sender())
39
+ recv = binding self()
40
+ recv receive_message: self
41
+ }
23
42
  }
@@ -94,8 +94,9 @@ class ThreadPool {
94
94
  }
95
95
  }
96
96
 
97
- def protected init_completable: block {
97
+ def init_completable: block {
98
98
  block extend(Completable)
99
99
  block complete: false
100
100
  }
101
+ protected: 'init_completable:
101
102
  }
@@ -1,39 +1,77 @@
1
1
  class TrueClass {
2
- "TrueClass. The class of the singleton @true value."
2
+ """
3
+ TrueClass. The class of the singleton @true value.
4
+ """
3
5
 
4
6
  def TrueClass new {
7
+ """
8
+ @return @true.
9
+ """
10
+
5
11
  # always return true singleton object when trying to create a new
6
12
  # TrueClass instance
7
13
  true
8
14
  }
9
15
 
10
16
  def if_true: block {
11
- "Calls @block."
17
+ """
18
+ @block @Block@ to be called with @self.
19
+ @return Value of calling @block with @self.
20
+
21
+ Calls @block with @self.
22
+ """
23
+
12
24
  block call: [self]
13
25
  }
14
26
 
15
27
  def if_true: then_block else: else_block {
16
- "Calls @then_block."
28
+ """
29
+ @then_block @Block@ to be called with @self.
30
+ @else_block Gets ignored.
31
+ @return Value of calling @then_block with @self.
32
+
33
+ Calls @then_block with @self.
34
+ """
35
+
17
36
  then_block call: [self]
18
37
  }
19
38
 
20
39
  def true? {
21
- "Returns @true."
40
+ """
41
+ @return @true.
42
+ """
43
+
22
44
  true
23
45
  }
24
46
 
25
47
  def to_s {
26
- "Returns @true as a @String@."
48
+ """
49
+ @return @true as a @String@.
50
+ """
51
+
27
52
  "true"
28
53
  }
29
54
 
55
+ alias_method: 'inspect for: 'to_s
56
+
30
57
  def to_a {
31
- "Returns an empty @Array@."
58
+ """
59
+ @return An empty @Array@.
60
+ """
61
+
32
62
  []
33
63
  }
34
64
 
35
65
  def not {
36
- "Returns @false."
66
+ """
67
+ @return @false.
68
+ """
69
+
37
70
  false
38
71
  }
39
72
  }
73
+
74
+ true documentation: """
75
+ @true is the singleton boolean true value (only instance of @TrueClass@).
76
+ TrueClass##new yields @true.
77
+ """
@@ -6,7 +6,7 @@ class Tuple {
6
6
 
7
7
  include: FancyEnumerable
8
8
 
9
- def [] idx {
9
+ def [idx] {
10
10
  """
11
11
  Forwards to @Tuple@#at:.
12
12
  """
@@ -15,22 +15,34 @@ class Tuple {
15
15
  }
16
16
 
17
17
  def first {
18
- "Returns the first element in the @Tuple@."
18
+ """
19
+ @return The first element in @self.
20
+ """
21
+
19
22
  at: 0
20
23
  }
21
24
 
22
25
  def second {
23
- "Returns the second element in the @Tuple@."
26
+ """
27
+ @return The second element in @self.
28
+ """
29
+
24
30
  at: 1
25
31
  }
26
32
 
27
33
  def third {
28
- "Returns the third element in the @Tuple@."
34
+ """
35
+ @return The third element in @self.
36
+ """
37
+
29
38
  at: 2
30
39
  }
31
40
 
32
41
  def fourth {
33
- "Returns the fourth element in the @Tuple@"
42
+ """
43
+ @return The fourth element in @self.
44
+ """
45
+
34
46
  at: 3
35
47
  }
36
48
 
@@ -71,15 +83,17 @@ class Tuple {
71
83
  }
72
84
 
73
85
  def inspect {
74
- "Returns a @String@ representation of a @Tuple@"
86
+ """
87
+ @return A @String@ representation of @self.
88
+ """
75
89
 
76
90
  str = "("
77
91
  each: |v| {
78
- str = str ++ v
92
+ str << (v inspect)
79
93
  } in_between: {
80
- str = str ++ ", "
94
+ str << ", "
81
95
  }
82
- str = str ++ ")"
96
+ str << ")"
83
97
  str
84
98
  }
85
99
 
@@ -96,4 +110,8 @@ class Tuple {
96
110
  [obj] + (obj map: 'identity)
97
111
  }
98
112
  }
113
+
114
+ def Tuple name {
115
+ "Tuple"
116
+ }
99
117
  }