bakkdoor-blocktalk 0.1.2 → 0.1.3
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.
- data/README.markdown +3 -3
- data/bin/blocktalk +28 -5
- data/evaluator.rb +2 -2
- data/examples/classes_modules.bt +1 -1
- data/examples/linecounter.bt +2 -2
- data/examples/portscan.bt +1 -1
- data/examples/ruby_methods.bt +4 -2
- data/examples/test.bt +17 -15
- data/examples/test2.bt +13 -17
- data/examples/test3.bt +2 -2
- data/lib/blocktalk/string.bt +12 -0
- data/lib/kernel/object.rb +8 -0
- metadata +1 -1
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ***Blocktalk*** #
|
2
|
-
### **v0.1.
|
2
|
+
### **v0.1.3** ###
|
3
3
|
|
4
4
|
## **Blocktalk** is a dynamic, object-oriented programming language somewhat in the tradition of Smalltalk and Ruby. ##
|
5
5
|
|
@@ -51,10 +51,10 @@ The example above shows, how a typicall if-then conditional could be written.
|
|
51
51
|
|
52
52
|
Another example would be a while loop:
|
53
53
|
|
54
|
-
i =
|
54
|
+
i = Console gets: "Please enter a number!" to_i
|
55
55
|
{i < 10} while_true {
|
56
56
|
Console print: "a smaller than b!"
|
57
|
-
i =
|
57
|
+
i = Console gets: "Enter again!" to_i
|
58
58
|
}
|
59
59
|
|
60
60
|
In this case, while_true takes a ruby-like implicit block, noticeable by the absence of the colon after the methodname,
|
data/bin/blocktalk
CHANGED
@@ -9,20 +9,35 @@ if ARGV.size < 1
|
|
9
9
|
exit
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
load_path = ""
|
14
13
|
|
15
|
-
if ARGV.join(" ")
|
14
|
+
if ARGV.join(" ") =~ /\-I\s*(\S+)/
|
16
15
|
$: << File.expand_path($1)
|
17
16
|
load_path = $1 + "/"
|
18
17
|
end
|
19
18
|
|
19
|
+
# ruby 1.8 is default
|
20
|
+
ruby_implementation = "ruby"
|
21
|
+
|
22
|
+
if ARGV.join(" ") =~ /\--rubyimp (\S+)/
|
23
|
+
ruby_implementation = $1
|
24
|
+
puts "Using #{ruby_implementation} for Blocktalk"
|
25
|
+
|
26
|
+
# remove option from argv, since it's not used anymore:
|
27
|
+
idx = ARGV.index("--rubyimp")
|
28
|
+
ARGV.delete_at(idx)
|
29
|
+
ARGV.delete_at(idx) # rubyimp argument now is at this index
|
30
|
+
end
|
31
|
+
|
20
32
|
require load_path + "lib/core"
|
21
33
|
require load_path + "evaluator"
|
22
34
|
require load_path + "parser/nodes"
|
35
|
+
require load_path + "version"
|
23
36
|
|
24
|
-
|
25
|
-
|
37
|
+
if ARGV.include?("--version") || ARGV.include?("-v")
|
38
|
+
puts "blocktalk v#{blocktalk_version}"
|
39
|
+
exit
|
40
|
+
end
|
26
41
|
|
27
42
|
parser_dynamic = ARGV.include?("--dynparser")
|
28
43
|
|
@@ -36,8 +51,16 @@ end
|
|
36
51
|
|
37
52
|
parse_file = ARGV[0]
|
38
53
|
parser = BlocktalkParser.new
|
54
|
+
|
39
55
|
ast = parser.parse IO.read(parse_file)
|
40
56
|
|
57
|
+
# if parsig failed -> output error message with reason
|
58
|
+
unless ast
|
59
|
+
puts "ParseError in #{parse_file} (line #{parser.failure_line} / #{parser.failure_column}):"
|
60
|
+
puts "#{parser.failure_reason}"
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
|
41
64
|
# start evaluation process
|
42
65
|
ast.evaluate
|
43
66
|
|
@@ -60,7 +83,7 @@ if ruby_output
|
|
60
83
|
else
|
61
84
|
# also pass any additional args in ARGV to Evaluator
|
62
85
|
# (ARGV[0] is the name of the file to execute).
|
63
|
-
Evaluator.eval(ARGV[1..-1])
|
86
|
+
Evaluator.eval(ruby_implementation, ARGV[1..-1])
|
64
87
|
|
65
88
|
if debug_on
|
66
89
|
puts
|
data/evaluator.rb
CHANGED
@@ -8,9 +8,9 @@ class Evaluator
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.eval(argv = [])
|
11
|
+
def self.eval(ruby_implementation = "ruby", argv = [])
|
12
12
|
# Kernel::eval @expressions.join(";")
|
13
|
-
system("/usr/bin/env
|
13
|
+
system("/usr/bin/env #{ruby_implementation} -e '#{@expressions.join(';')}' #{argv.join(' ')}")
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.inspect
|
data/examples/classes_modules.bt
CHANGED
data/examples/linecounter.bt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
(
|
1
|
+
(ARGV size) > 0 if_true: {
|
2
2
|
filename = ARGV at: 0
|
3
3
|
File open: filename do |f|
|
4
|
-
Console puts: "#{filename} has #{f
|
4
|
+
Console puts: "#{filename} has #{f readlines size} lines!"
|
5
5
|
end
|
6
6
|
} if_false: {
|
7
7
|
Console puts: "Please specify a file to count lines on!"
|
data/examples/portscan.bt
CHANGED
data/examples/ruby_methods.bt
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# calling some ruby methods...
|
2
|
+
require: "lib/blocktalk/string"
|
2
3
|
|
3
4
|
File open: "examples/test3.bt" mode: "r" do |f|
|
4
5
|
(f readlines) each do |l|
|
@@ -8,7 +9,7 @@ end
|
|
8
9
|
|
9
10
|
# and again, this time cached!
|
10
11
|
File open: "examples/test3.bt" mode: "r" do |f|
|
11
|
-
|
12
|
+
f readlines each do |l|
|
12
13
|
Console puts: l
|
13
14
|
end
|
14
15
|
end
|
@@ -17,4 +18,5 @@ end
|
|
17
18
|
str = "hello, world, how are you?"
|
18
19
|
str2 = str gsub: "," with: "!"
|
19
20
|
Console puts: str;
|
20
|
-
puts: str2
|
21
|
+
puts: str2;
|
22
|
+
puts: (str at: (2 .. 5))
|
data/examples/test.bt
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# this is just for demonstration
|
2
2
|
# there probably won't be the need to require the console module from the
|
3
3
|
# standard library every time you want to print something to the screen ;)
|
4
|
-
System require: "console"
|
4
|
+
#System require: "console"
|
5
5
|
|
6
6
|
# we support ruby-style blocks with do ... end and curly braces { ... }
|
7
|
-
File open: "test.txt" mode: "w" do |f|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
# File open: "test.txt" mode: "w" do |f|
|
8
|
+
# f puts: "whats up, dog?!"
|
9
|
+
# f puts: "crazy shit, yo!"
|
10
|
+
# f puts: "hahaha!!"
|
11
|
+
# end
|
12
12
|
|
13
|
-
10
|
13
|
+
10 upto: 0 do |i|
|
14
14
|
Console puts: i
|
15
15
|
end
|
16
16
|
|
17
17
|
i = 0
|
18
|
-
|
18
|
+
{i < 10} while_true do
|
19
19
|
Console puts: i
|
20
|
-
i
|
20
|
+
i = i + 1
|
21
21
|
end
|
22
22
|
|
23
|
-
numbers = [1,2,3,4,5] select
|
24
|
-
numbers each
|
25
|
-
puts i
|
23
|
+
numbers = [1,2,3,4,5] select {|i| i < 3}
|
24
|
+
numbers each do |i|
|
25
|
+
Console puts: i
|
26
26
|
end
|
27
27
|
|
28
|
-
(1 .. 100) each
|
28
|
+
#(1 .. 100) each {|i| Console puts: i}
|
29
29
|
|
30
|
-
squares = (1 .. 100) collect
|
30
|
+
#squares = (1 .. 100) collect {|i| i * i}
|
31
31
|
|
32
32
|
|
33
33
|
# define a square method
|
@@ -37,9 +37,11 @@ square = { |x|
|
|
37
37
|
|
38
38
|
# or like this:
|
39
39
|
abs = { |num|
|
40
|
-
|
40
|
+
num > 0 if_true {
|
41
41
|
return num
|
42
42
|
}
|
43
43
|
|
44
44
|
num * -1
|
45
45
|
}
|
46
|
+
|
47
|
+
Console puts: ([1,2,3,4,5] collect {|i| square call: i})
|
data/examples/test2.bt
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
foo = do |x|
|
2
|
-
Console puts
|
2
|
+
Console puts: "bkzubb: #{x}"
|
3
3
|
end
|
4
4
|
|
5
5
|
bar = do
|
6
6
|
100
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
foo call: 10
|
10
10
|
|
11
11
|
|
12
12
|
[1,2,3] each { |x|
|
@@ -16,7 +16,7 @@ Console puts: (foo call: 10)
|
|
16
16
|
# anonymous class
|
17
17
|
c = Class new {
|
18
18
|
def foo = do |x|
|
19
|
-
Console puts:
|
19
|
+
Console puts: "in foo: #{x}"
|
20
20
|
end
|
21
21
|
}
|
22
22
|
|
@@ -27,7 +27,7 @@ obj foo: (10 to_s)
|
|
27
27
|
# new class Foo
|
28
28
|
Class >> :Foo do
|
29
29
|
def bar = do |x|
|
30
|
-
Console puts:
|
30
|
+
Console puts: "in Foo#bar: #{x}"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -54,7 +54,7 @@ foo bazz
|
|
54
54
|
Class >> {:MyArray => Array} do
|
55
55
|
def crazy_ouput = do
|
56
56
|
self each { |x|
|
57
|
-
Console puts:
|
57
|
+
Console puts: "craaaaaazy: #{x}"
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
@@ -62,8 +62,8 @@ Class >> {:MyArray => Array} do
|
|
62
62
|
i = 0
|
63
63
|
arr = []
|
64
64
|
{i < amount} while_true {
|
65
|
-
arr <<
|
66
|
-
i =
|
65
|
+
arr << self at: i
|
66
|
+
i = i + 1
|
67
67
|
}
|
68
68
|
|
69
69
|
return: arr
|
@@ -73,9 +73,9 @@ Class >> {:MyArray => Array} do
|
|
73
73
|
def my_each = do |block|
|
74
74
|
i = 0
|
75
75
|
{i < (self size)} while_true {
|
76
|
-
curr_item =
|
76
|
+
curr_item = self at: i
|
77
77
|
block call: curr_item
|
78
|
-
i =
|
78
|
+
i = i + 1
|
79
79
|
}
|
80
80
|
end
|
81
81
|
end
|
@@ -91,20 +91,16 @@ myarr crazy_ouput
|
|
91
91
|
|
92
92
|
Console puts: (myarr class)
|
93
93
|
|
94
|
-
Console puts: (
|
94
|
+
Console puts: (myarr take_n: 3 inspect)
|
95
95
|
|
96
96
|
|
97
97
|
myarr my_each: { |elem|
|
98
|
-
Console puts:
|
98
|
+
Console puts: "my_each: #{elem}"
|
99
99
|
}
|
100
100
|
|
101
|
-
# File open: "grammar/test2.blk" mode: "r" do |f|
|
102
|
-
# Console puts: (f readlines)
|
103
|
-
# end
|
104
|
-
|
105
101
|
Class >> :MyClass do
|
106
102
|
def funky = do |name|
|
107
|
-
Console puts:
|
103
|
+
Console puts: "in MyClass#funky with name = #{name}"
|
108
104
|
end
|
109
105
|
end
|
110
106
|
|
@@ -113,7 +109,7 @@ end
|
|
113
109
|
|
114
110
|
Module >> :MyModule {
|
115
111
|
def test = do |bar|
|
116
|
-
Console puts:
|
112
|
+
Console puts: "in MyModule#test with bar = #{bar}"
|
117
113
|
end
|
118
114
|
}
|
119
115
|
|
data/examples/test3.bt
CHANGED
data/lib/blocktalk/string.bt
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
Class >> :String do
|
2
|
+
def at = do |index|
|
3
|
+
%ruby{
|
4
|
+
self[index]
|
5
|
+
}%
|
6
|
+
end
|
7
|
+
|
8
|
+
def at = do |index puts: value|
|
9
|
+
%ruby{
|
10
|
+
self[index] = value
|
11
|
+
}%
|
12
|
+
end
|
13
|
+
|
2
14
|
def substitute = do |string with: subst_string|
|
3
15
|
self gsub: string with: subst_string
|
4
16
|
end
|
data/lib/kernel/object.rb
CHANGED
@@ -42,6 +42,14 @@ class Object
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def and(other)
|
46
|
+
self and other
|
47
|
+
end
|
48
|
+
|
49
|
+
def or(other)
|
50
|
+
self or other
|
51
|
+
end
|
52
|
+
|
45
53
|
# this should get called, if we try to call a method on objects of
|
46
54
|
# ruby classes.
|
47
55
|
# it will try to find the correct ruby method-name & clall it.
|