fancy 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -2,26 +2,40 @@ class Range {
2
2
  ruby_alias: 'to_a
3
3
  ruby_alias: '==
4
4
  ruby_alias: '===
5
+ ruby_alias: 'first
6
+ ruby_alias: 'last
5
7
 
6
- include: FancyEnumerable
8
+ def initialize: @start to: @end {
9
+ """
10
+ @start Start element of Range.
11
+ @end End element of Range.
7
12
 
8
- def initialize: start to: end {
9
- initialize(start, end)
13
+ Initializes a new Range starting at @start and ending at @end.
14
+ """
15
+
16
+ initialize(@start, @end)
10
17
  }
11
18
 
12
19
  def each: block {
20
+ """
21
+ @block @Block@ to be called with every value in @self.
22
+ @return @self.
23
+
24
+ Calls @block on each value in @self. Used for iterating over a @Range@.
25
+ """
26
+
13
27
  try {
14
28
  val = nil
15
29
  each() |x| {
16
30
  try {
17
31
  val = block call: [x]
18
32
  } catch (Fancy NextIteration) => ex {
19
- val = ex return_value
33
+ val = ex result
20
34
  }
21
35
  }
22
- val
36
+ return self
23
37
  } catch (Fancy BreakIteration) => ex {
24
- ex return_value
38
+ ex result
25
39
  }
26
40
  }
27
41
  }
@@ -1,4 +1,8 @@
1
1
  class Regexp {
2
+ """
3
+ Regular Expression class. Used by Regexp literals in Fancy.
4
+ """
5
+
2
6
  ruby_alias: 'inspect
3
7
  ruby_alias: 'to_s
4
8
 
@@ -9,8 +13,12 @@ class Regexp {
9
13
  def i {
10
14
  Regexp new(source(), true)
11
15
  }
12
- }
13
16
 
14
- class MatchData {
15
- ruby_alias: '[]
17
+ def Regexp new: string {
18
+ new(string)
19
+ }
20
+
21
+ def Regexp [string] {
22
+ new(string)
23
+ }
16
24
  }
@@ -10,8 +10,15 @@ class String {
10
10
  ruby_alias: 'chomp
11
11
  ruby_alias: 'inspect
12
12
  ruby_alias: 'to_sym
13
+ ruby_alias: '<
14
+ ruby_alias: '>
13
15
 
14
- def [] index {
16
+ alias_method: '[]: for_ruby: '[]=
17
+ alias_method: 'scan: for_ruby: 'scan
18
+
19
+ forwards_unary_ruby_methods
20
+
21
+ def [index] {
15
22
  """Given an Array of 2 Numbers, it returns the substring between the given indices.
16
23
  If given a Number, returns the character at that index."""
17
24
 
@@ -103,4 +110,47 @@ class String {
103
110
  def unpack: format {
104
111
  unpack(format)
105
112
  }
113
+
114
+ def replace: pattern with: replacement {
115
+ if: (replacement is_a?: Block) then: {
116
+ gsub(pattern, &replacement)
117
+ } else: {
118
+ gsub(pattern, replacement)
119
+ }
120
+ }
121
+
122
+ def replace!: pattern with: replacement {
123
+ if: (replacement is_a?: Block) then: {
124
+ gsub!(pattern, &replacement)
125
+ } else: {
126
+ gsub!(pattern, replacement)
127
+ }
128
+ }
129
+
130
+ def append: string {
131
+ """
132
+ @string Other @String@ to append on @self.
133
+ @return @self, but modified.
134
+
135
+ Appends another @String@ onto this @String@.
136
+
137
+ Example usage:
138
+ str = \"hello\"
139
+ str append: \" world!\"
140
+ str # => \"hello world!\"
141
+ """
142
+
143
+ append(string)
144
+ }
145
+
146
+ def includes?: substring {
147
+ """
148
+ @substring @String@ to be checked if it's in @self.
149
+ @return @true if @substring is in @self, @false otherwise.
150
+
151
+ Indicates if a given substring is in @self.
152
+ """
153
+
154
+ include?(substring)
155
+ }
106
156
  }
@@ -0,0 +1,17 @@
1
+ require("stringio")
2
+
3
+ class StringIO {
4
+ include: IOMixin
5
+ forwards_unary_ruby_methods
6
+ StringIO forwards_unary_ruby_methods
7
+
8
+ ruby_alias: '<<
9
+
10
+ def each: block {
11
+ each(&block)
12
+ }
13
+
14
+ def each_line: block {
15
+ each_line(&block)
16
+ }
17
+ }
@@ -7,6 +7,20 @@ class Symbol {
7
7
  }
8
8
 
9
9
  def inspect {
10
- "'" ++ (inspect() from: 1 to: -1)
10
+ "'" ++ to_s
11
+ }
12
+
13
+ def defined? {
14
+ """
15
+ @return @true, if @self is defined as a constant in senders scope, @false otherwise.
16
+
17
+ Indicates if a Symbol is defined as a constant in the senders scope.
18
+ """
19
+
20
+ binding = Binding setup(Rubinius VariableScope of_sender(),
21
+ Rubinius CompiledMethod of_sender(),
22
+ Rubinius StaticScope of_sender())
23
+
24
+ binding send('self) class const_defined?(self)
11
25
  }
12
26
  }
@@ -1,14 +1,32 @@
1
1
  require("open3")
2
2
 
3
3
  class System {
4
+ """
5
+ System class. Holds system-wide relevant methods.
6
+ """
7
+
4
8
  def System exit {
5
- "Exit the running Fancy process."
9
+ """
10
+ Exit the running Fancy process.
11
+ """
6
12
 
7
13
  Kernel exit()
8
14
  }
9
15
 
16
+ def System exit: exitcode {
17
+ """
18
+ @exitcode Exit code (Fixnum) to be returned to the parent process.
19
+
20
+ Exit the running Fancy process with a given exit code.
21
+ """
22
+
23
+ Kernel exit(exitcode)
24
+ }
25
+
10
26
  def System do: command_str {
11
- "Runs the given string as a system() command."
27
+ """
28
+ Runs the given string as a system() command.
29
+ """
12
30
 
13
31
  Kernel system(command_str)
14
32
  }
@@ -1,6 +1,9 @@
1
1
  require("socket")
2
2
 
3
3
  class TCPServer {
4
- " TCP Server "
4
+ """
5
+ TCP Server
6
+ """
7
+
5
8
  ruby_alias: 'accept
6
9
  }
@@ -1,7 +1,18 @@
1
1
  require("socket")
2
2
 
3
3
  class TCPSocket {
4
+ """
5
+ TCP Socket class.
6
+ """
7
+
4
8
  def TCPSocket open: server port: port {
9
+ """
10
+ @server Server hostname to open Socket on.
11
+ @port Server port to open Socket on.
12
+
13
+ Creates and opens a new @TCPSocket@ on @server and @port.
14
+ """
15
+
5
16
  open(server, port)
6
17
  }
7
18
  }
@@ -1,4 +1,10 @@
1
1
  class Time {
2
+ """
3
+ Time class. Used for even more timely stuff.
4
+ """
5
+
6
+ forwards_unary_ruby_methods
7
+
2
8
  metaclass ruby_alias: 'now
3
9
  ruby_alias: '==
4
10
  ruby_alias: '-
@@ -1,9 +1,8 @@
1
1
  Tuple = Rubinius Tuple
2
2
  class Tuple {
3
- ruby_alias: 'size
4
- ruby_alias: 'to_a
3
+ forwards_unary_ruby_methods
5
4
 
6
- def initialize: size {
5
+ def Tuple new: size {
7
6
  """
8
7
  @size Size of the @Tuple@ (amount of values to hold).
9
8
 
@@ -11,7 +10,15 @@ class Tuple {
11
10
  E.g. if @size is @2, creates a 2-Tuple.
12
11
  """
13
12
 
14
- initialize(size)
13
+ if: (size < 2) then: {
14
+ ArgumentError new: "Tuple size has to be a minimum of 2!" . raise!
15
+ }
16
+
17
+ new(size)
18
+ }
19
+
20
+ def Tuple new {
21
+ ArgumentError new: "Cannot initialize empty Tuple!" . raise!
15
22
  }
16
23
 
17
24
  def at: idx {
@@ -26,7 +33,7 @@ class Tuple {
26
33
  at(idx)
27
34
  }
28
35
 
29
- def at: idx put: val {
36
+ def [idx]: val {
30
37
  """
31
38
  @idx Index of element to set.
32
39
  @val Value to set at given index.
@@ -35,4 +42,6 @@ class Tuple {
35
42
  """
36
43
  put(idx, val)
37
44
  }
45
+
46
+ alias_method: 'at:put: for: '[]:
38
47
  }
data/lib/set.fy CHANGED
@@ -1,61 +1,176 @@
1
1
  class Set {
2
- "A simple Set data structure class."
2
+ """
3
+ A simple Set data structure class.
4
+ """
3
5
 
4
6
  include: FancyEnumerable
5
- read_slots: ['values]
6
7
 
7
- def initialize: arr {
8
- "Initialize a new Set with a given Array of values."
9
- @values = arr uniq
8
+ def initialize: values {
9
+ """
10
+ @values @FancyEnumerable@ of values to be used as values for @self.
11
+
12
+ Initialize a new Set with a given collection of values.
13
+ """
14
+
15
+ @hash = <[]>
16
+ values each: |v| {
17
+ @hash[v]: true
18
+ }
10
19
  }
11
20
 
12
21
  def initialize {
13
- "Initialize a new empty Set."
14
- @values = []
22
+ """
23
+ Initialize a new empty Set.
24
+ """
25
+
26
+ @hash = <[]>
27
+ }
28
+
29
+ def values {
30
+ """
31
+ @return Values in self as an @Array@.
32
+ """
33
+
34
+ @hash keys
35
+ }
36
+
37
+ def size {
38
+ """
39
+ @return Amount of values in @self as a @Fixnum@.
40
+ """
41
+
42
+ @hash size
43
+ }
44
+
45
+ def empty? {
46
+ """
47
+ @return @true, if Set is emty, @false otherwise.
48
+
49
+ Indicates, if a Set is empty.
50
+ """
51
+
52
+ @hash empty?
15
53
  }
16
54
 
17
55
  def == other {
18
- "Indicates, if two Sets are equal."
56
+ """
57
+ @other @Set@ to compare @self against.
58
+ @return @true, if self is equal to @other, @false otherwise.
59
+
60
+ Indicates, if two Sets are equal.
61
+ """
62
+
19
63
  if: (other is_a?: Set) then: {
20
- @values == (other values)
64
+ if: (size == (other size)) then: {
65
+ return other all?: |x| { includes?: x }
66
+ }
21
67
  }
68
+ return false
22
69
  }
23
70
 
24
- def Set [] arr {
25
- "Initialize a new Array with a given Array of values."
26
- Set new: arr
71
+ def Set [values] {
72
+ """
73
+ @values @FancyEnumerable@ of values used for new Set.
74
+
75
+ Initialize a new Set with a given collection of values.
76
+ """
77
+
78
+ Set new: values
27
79
  }
28
80
 
29
81
  def << value {
30
- "Insert a value into the Set."
31
- { @values << value } unless: (includes?: value)
82
+ """
83
+ @value Value to be inserted into @self.
84
+ @return @self.
85
+
86
+ Insert a value into the Set.
87
+ """
88
+
89
+ @hash[value]: true
90
+ self
32
91
  }
33
92
 
34
93
  def includes?: value {
35
- "Indicates, if the Set includes a given value."
36
- @values includes?: value
94
+ """
95
+ @value Value to be checked for if included in @self.
96
+ @return @true if @value in @self, @false otherwise.
97
+
98
+ Indicates, if the Set includes a given value.
99
+ """
100
+
101
+ @hash includes?: value
37
102
  }
38
103
 
39
104
  def each: block {
40
- "Calls a given Block for each element of the Set."
41
- @values each: block
42
- }
105
+ """
106
+ @block @Block@ to be called with each value in @self.
107
+ @return @self.
43
108
 
44
- def unknown_message: msg with_params: params {
45
- if: (params empty?) then: {
46
- @values send_message: msg
47
- } else: {
48
- @values send_message: msg with_params: params
49
- }
109
+ Calls a given Block for each element of the Set.
110
+ """
111
+
112
+ @hash each_key: block
113
+ self
50
114
  }
51
115
 
52
116
  def to_s {
53
- "Returns a String representation of a Set."
54
- "Set" ++ @values to_s
117
+ """
118
+ Returns a @String@ representation of a Set.
119
+ """
120
+
121
+ "Set[" ++ (values join: ", ") ++ "]"
55
122
  }
56
123
 
57
124
  def inspect {
58
- "Returns a detailed String representation of a Set."
59
- to_s ++ " : Set"
125
+ """
126
+ Returns a detailed @String@ representation of a Set.
127
+ """
128
+
129
+ "Set[" ++ (values map: 'inspect . join: ", " . to_s) ++ "]"
130
+ }
131
+
132
+ def remove: obj {
133
+ """
134
+ @obj Object to be removed from @self.
135
+
136
+ Removes a given object from a Set, if available.
137
+ """
138
+
139
+ @hash delete: obj
140
+ }
141
+
142
+ def + other {
143
+ """
144
+ @other Other Set to use for creating union Set.
145
+ @return Union Set containing all values in both @self and @other.
146
+ """
147
+
148
+ Set[values + (other values)]
149
+ }
150
+
151
+ def - other {
152
+ """
153
+ @other Other Set to use for creating difference Set.
154
+ @return Difference Set by removing all values from @self that are in @other.
155
+ """
156
+
157
+ s = Set[values]
158
+ other values each: |v| {
159
+ s remove: v
160
+ }
161
+ s
162
+ }
163
+
164
+ def & other {
165
+ """
166
+ @other Other Set to use for creating Set.
167
+ @return Intersection Set containing only values that are in both @self and @other.
168
+ """
169
+
170
+ s = Set[values]
171
+ s values each: |v| {
172
+ { s remove: v } unless: (other includes?: v)
173
+ }
174
+ s
60
175
  }
61
176
  }