Permalink
Browse files

HUUGE CHANGE: Semicolons are history - or at least completely optiona…

…l now! A newline will do it, except for literal strings, hashes, arrays & blocks, which _can_ have linebreaks in them. Much nicer syntax for Fancy. Yay!
  • Loading branch information...
1 parent f708b6c commit 0e8107391a1a57c9d958e141e8f16b6ce1602057 @bakkdoor committed Sep 9, 2010
Showing with 1,309 additions and 1,292 deletions.
  1. +1 −1 bin/ifancy
  2. +1 −1 examples/argv.fnc
  3. +3 −3 examples/arithmetic.fnc
  4. +10 −10 examples/armstrong_numbers.fnc
  5. +21 −21 examples/array.fnc
  6. +6 −6 examples/blocks.fnc
  7. +8 −8 examples/boolean.fnc
  8. +24 −24 examples/class.fnc
  9. +5 −5 examples/closures.fnc
  10. +1 −1 examples/factorial.fnc
  11. +1 −1 examples/fibonacci.fnc
  12. +6 −6 examples/files.fnc
  13. +31 −31 examples/game_of_life.fnc
  14. +1 −1 examples/hello_world.fnc
  15. +7 −7 examples/html_generator.fnc
  16. +6 −6 examples/metadata.fnc
  17. +6 −6 examples/methods.fnc
  18. +4 −4 examples/nested_classes.fnc
  19. +6 −6 examples/numbers.fnc
  20. +15 −15 examples/person.fnc
  21. +5 −5 examples/project-euler/02.fnc
  22. +2 −2 examples/require.fnc
  23. +7 −6 examples/scope.fnc
  24. +9 −9 lib/argv.fnc
  25. +55 −55 lib/array.fnc
  26. +6 −6 lib/block.fnc
  27. +39 −39 lib/boot.fnc
  28. +7 −7 lib/class.fnc
  29. +5 −5 lib/console.fnc
  30. +2 −2 lib/directory.fnc
  31. +52 −52 lib/enumerable.fnc
  32. +45 −45 lib/fancy_spec.fnc
  33. +9 −9 lib/file.fnc
  34. +6 −6 lib/hash.fnc
  35. +3 −3 lib/method.fnc
  36. +8 −8 lib/nil_class.fnc
  37. +10 −10 lib/number.fnc
  38. +16 −16 lib/object.fnc
  39. +27 −27 lib/rubinius/array.fnc
  40. +8 −8 lib/rubinius/console.fnc
  41. +5 −5 lib/rubinius/file.fnc
  42. +1 −1 lib/rubinius/object.fnc
  43. +3 −3 lib/rubinius/system.fnc
  44. +12 −12 lib/set.fnc
  45. +9 −9 lib/string.fnc
  46. +2 −2 lib/symbol.fnc
  47. +5 −5 lib/true_class.fnc
  48. +5 −6 lib/version.fnc
  49. +1 −1 src/parser/fancy.lex
  50. +100 −82 src/parser/fancy.y
  51. +2 −2 tests/argv.fnc
  52. +161 −161 tests/array.fnc
  53. +29 −29 tests/block.fnc
  54. +142 −143 tests/class.fnc
  55. +9 −9 tests/documentation.fnc
  56. +16 −16 tests/exception.fnc
  57. +46 −46 tests/file.fnc
  58. +44 −44 tests/hash.fnc
  59. +8 −8 tests/method.fnc
  60. +17 −17 tests/nil_class.fnc
  61. +40 −40 tests/number.fnc
  62. +73 −73 tests/object.fnc
  63. +16 −16 tests/parsing/sexp.fnc
  64. +7 −7 tests/scope.fnc
  65. +5 −5 tests/set.fnc
  66. +40 −40 tests/string.fnc
  67. +8 −8 tests/symbol.fnc
  68. +19 −19 tests/true_class.fnc
View
@@ -1,7 +1,7 @@
#!/usr/bin/env fancy
["Welcome to the (still very simple) Fancy REPL",
- "Fancy " ++ FANCY_VERSION] println;
+ "Fancy " ++ FANCY_VERSION] println
ARGV rest each: |file| {
"LOADING: " ++ file println;
View
@@ -1,4 +1,4 @@
-"This will always get printed, even when required from another file" println;
+"This will always get printed, even when required from another file" println
ARGV[0] == __FILE__ if_true: {
"This will get printed, if this file is directly run with fancy" println
View
@@ -1,4 +1,4 @@
-23 + 32432.32 println;
-324432.432 - 32432.4324 println;
-32432 * 432.32 println;
+23 + 32432.32 println
+324432.432 - 32432.4324 println
+32432 * 432.32 println
432 / 12319 println
@@ -5,26 +5,26 @@
def class Number {
def decimals {
"""Returns all decimals of a Number as an Array.
- E.g. 123 decimals # => [1,2,3]""";
+ E.g. 123 decimals # => [1,2,3]"""
- decimals = [];
- tmp = self;
+ decimals = []
+ tmp = self
{ tmp >= 10 } while_true: {
- decimals << (tmp modulo: 10);
+ decimals << (tmp modulo: 10)
tmp = (tmp div: 10)
- };
- decimals << tmp;
+ }
+ decimals << tmp
decimals
}
def armstrong? {
- "Indicates, if a Number is a Armstrong Number.";
+ "Indicates, if a Number is a Armstrong Number."
- decimals = self decimals;
- n_decimals = decimals size;
+ decimals = self decimals
+ n_decimals = decimals size
decimals map: |x| { x ** n_decimals } . sum == self
}
-};
+}
# output alls Armstrong Numbers between 0 and 10000
0 upto: 10000 do_each: |i| {
View
@@ -1,51 +1,51 @@
# some array example code
# create an array
-arr = [1,2,3,4,5,6];
+arr = [1,2,3,4,5,6]
# print each element squared
arr each: |x| {
x squared println
-};
+}
# display each element with its index in the array
arr each_with_index: |x i| {
"Index " ++ i ++ " -> " ++ x println
-};
+}
# print the array of squared elements
-arr map: 'squared . inspect println;
+arr map: 'squared . inspect println
# print the array of doubled elements
-arr map: 'doubled . inspect println;
+arr map: 'doubled . inspect println
# print array of all elements smaller than 4
-arr select: |x| { x < 4 } . inspect println;
+arr select: |x| { x < 4 } . inspect println
# print array of all elements that are not smaller than 4
-arr reject: |x| { x < 4 } . inspect println;
+arr reject: |x| { x < 4 } . inspect println
# prints: [5, 6]
-arr take_while: |x| { x < 5 } . inspect println;
+arr take_while: |x| { x < 5 } . inspect println
-"testing reduce:with: " print;
-arr reduce: |acc x| { acc * x } with: 1 . println; # same as: 1*1*2*3*4*5*6
+"testing reduce:with: " print
+arr reduce: |acc x| { acc * x } with: 1 . println # same as: 1*1*2*3*4*5*6
-"testing any?: " print;
-arr any?: |x| { x > 3 } . println; # prints: true
+"testing any?: " print
+arr any?: |x| { x > 3 } . println # prints: true
-"testing all?: " print;
-arr all?: |x| { x < 7 } . println; # prints: true
+"testing all?: " print
+arr all?: |x| { x < 7 } . println # prints: true
-"testing from:to: " print;
-arr [[3,5]] . inspect println; # prints: [4, 5, 6]
+"testing from:to: " print
+arr [[3,5]] . inspect println # prints: [4, 5, 6]
# some other handy methods
-"testing size: " print;
-arr size println; # prints: 6
+"testing size: " print
+arr size println # prints: 6
-"testing to_s: " print;
-arr to_s println; # prints: 123456
+"testing to_s: " print
+arr to_s println # prints: 123456
-"testing inspect: " print;
+"testing inspect: " print
arr inspect println # prints: [1, 2, 3, 4, 5, 6] : Array
View
@@ -1,12 +1,12 @@
-x = { Console println: "Println from within block!" };
-x call; # calls x and prints: "Println from within block!"
+x = { Console println: "Println from within block!" }
+x call # calls x and prints: "Println from within block!"
-y = |x y| { Console println: $ x + y };
-y call: [2, 3]; # calls y and prints: 5
+y = |x y| { Console println: $ x + y }
+y call: [2, 3] # calls y and prints: 5
# prints numbers 0 to 20
-zahl = 0;
+zahl = 0
{ zahl <= 20 } while_true: {
- Console println: zahl;
+ Console println: zahl
zahl = zahl + 1
}
View
@@ -1,20 +1,20 @@
# some boolean expressions & logicial operations
-true and: true . println; # true
-true and: nil . println; # nil
-nil and: nil . println; # nil
+true and: true . println # true
+true and: nil . println # nil
+nil and: nil . println # nil
-true or: true . println; # true
-true or: nil . println; # true
-nil or: nil . println; # nil
+true or: true . println # true
+true or: nil . println # true
+nil or: nil . println # nil
-"--------------" println;
+"--------------" println
# won't print string
nil if_true: {
"this should _not_ be displayed" println
-};
+}
# will print string
nil if_false: {
View
@@ -1,64 +1,64 @@
def class Bar {
def initialize {
Console println: "In Bar constructor!"
- };
+ }
def say_hello: name {
- Console print: "Hello, ";
+ Console print: "Hello, "
Console println: name
}
-};
+}
def class Foo : Bar {
def initialize: name {
- Console println: "gonna set @name";
+ Console println: "gonna set @name"
@name = name
- };
+ }
def say_hello {
- Console print: "Hello, ";
- Console println: @name;
+ Console print: "Hello, "
+ Console println: @name
{@block call} if: @block
- };
+ }
def on_hello_do: block {
@block = block
}
-};
+}
-bar = Bar new;
-bar say_hello: "Chris";
+bar = Bar new
+bar say_hello: "Chris"
-foo = Foo new: "Chris from Constructor";
-foo say_hello;
+foo = Foo new: "Chris from Constructor"
+foo say_hello
foo on_hello_do: {
Console println: "Call me when calling on_hello! :)"
-};
-foo say_hello;
+}
+foo say_hello
-foo class println; # print the class of foo
+foo class println # print the class of foo
# define a singleton method on foo object
foo define_singleton_method: "foo!" with: {
"In foo method :D" println
-};
+}
-foo foo!;
+foo foo!
# define a 'normal' method on Foo class
# (instance method for all instances of Foo)
foo class define_method: "foo_for_all:" with: |x| {
- "In foo_for_all method (defined for all instances of Foo class)" println;
+ "In foo_for_all method (defined for all instances of Foo class)" println
"Got argument: " ++ x println
-};
+}
-foo2 = Foo new;
-foo2 foo_for_all: "hello, test! :)";
-foo foo_for_all: "hello, test (again)! :)";
+foo2 = Foo new
+foo2 foo_for_all: "hello, test! :)"
+foo foo_for_all: "hello, test (again)! :)"
# define a class method on Foo class
# it's the same as calling 'define_singleton_method:with:' on class
foo class define_class_method: "cool_class_method:" with: |arg| {
"In class method for Foo! Argument given: " ++ arg println
-};
+}
# the following is the same as:
# foo class cool_class_method: "Some argument string"
View
@@ -2,19 +2,19 @@
def create_counter: number {
closure = {
number = number + 1
- };
+ }
closure
-};
+}
# create a counter from 100 upwards
-closure = self create_counter: 100;
+closure = self create_counter: 100
# this will print numbers 100 - 120
20 times: {
Console println: $ closure call
-};
+}
# create a counter from 500 upwards
-closure = self create_counter: 500;
+closure = self create_counter: 500
# this will print numbers 500 - 510
10 times: {
Console println: $ closure call
View
@@ -2,7 +2,7 @@ def class Number {
def factorial {
1 upto: self . product
}
-};
+}
1 upto: 10 do_each: |i| {
i to_s ++ "! = " ++ (i factorial) println
View
@@ -10,7 +10,7 @@ def class Number {
}
}
}
-};
+}
15 times: |x| {
x fib println
View
@@ -1,20 +1,20 @@
{
Directory create: "tmp/"
-} unless: $ Directory exists?: "tmp/";
+} unless: $ Directory exists?: "tmp/"
File open: "tmp/Hello-World.txt" modes: ['write] with: |f| {
f write: "Hello, world" . newline
-};
+}
-File delete: "tmp/Hello-World.txt";
+File delete: "tmp/Hello-World.txt"
-arr = [1,2,3,4];
+arr = [1,2,3,4]
File open: "tmp/Array-Test.txt" modes: ['write] with: |f| {
arr each: |x| {
f writeln: x
}
-};
+}
-File delete: "tmp/Array-Test.txt";
+File delete: "tmp/Array-Test.txt"
Directory delete: "tmp/"
Oops, something went wrong.

0 comments on commit 0e81073

Please sign in to comment.