omghax-einstein 0.1.0 → 0.1.1
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/History.txt +5 -0
- data/Manifest.txt +1 -1
- data/lib/einstein/version.rb +1 -1
- data/lib/einstein/visitors.rb +12 -0
- data/test/{test_helper.rb → helper.rb} +0 -0
- data/test/test_evaluate.rb +9 -1
- data/test/test_parser.rb +1 -1
- data/test/test_pretty_print.rb +9 -1
- data/test/test_tokenizer.rb +68 -0
- data/website/index.html +2 -2
- metadata +5 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/lib/einstein/version.rb
CHANGED
data/lib/einstein/visitors.rb
CHANGED
|
@@ -96,6 +96,18 @@ module Einstein
|
|
|
96
96
|
o.left.accept(self) - o.value.accept(self)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
# Performs a bitwise left shift of the left value of +o+ by the number
|
|
100
|
+
# of bits specified in the right value of +o+.
|
|
101
|
+
def visit_LeftShiftNode(o)
|
|
102
|
+
o.left.accept(self) << o.value.accept(self)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Performs a bitwise right shift of the left value of +o+ by the number
|
|
106
|
+
# of bits specified in the right value of +o+.
|
|
107
|
+
def visit_RightShiftNode(o)
|
|
108
|
+
o.left.accept(self) >> o.value.accept(self)
|
|
109
|
+
end
|
|
110
|
+
|
|
99
111
|
# Performs a bitwise AND with the left and right values of +o+.
|
|
100
112
|
def visit_BitwiseAndNode(o)
|
|
101
113
|
o.left.accept(self) & o.value.accept(self)
|
|
File without changes
|
data/test/test_evaluate.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
|
2
2
|
require "logger"
|
|
3
3
|
|
|
4
4
|
class TestEvaluate < Test::Unit::TestCase
|
|
@@ -38,6 +38,14 @@ class TestEvaluate < Test::Unit::TestCase
|
|
|
38
38
|
assert_equal(0b1100 & 0b1111, parse("0b1100 & 0b1111").evaluate)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
def test_rshift
|
|
42
|
+
assert_equal(10 >> 2, parse("10 >> 2").evaluate)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_lshift
|
|
46
|
+
assert_equal(10 << 2, parse("10 << 2").evaluate)
|
|
47
|
+
end
|
|
48
|
+
|
|
41
49
|
def test_subtraction
|
|
42
50
|
assert_equal(10 - 5, parse("10 - 5").evaluate)
|
|
43
51
|
assert_equal(5 - 10, parse("5 - 10").evaluate)
|
data/test/test_parser.rb
CHANGED
data/test/test_pretty_print.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
|
2
2
|
require "logger"
|
|
3
3
|
|
|
4
4
|
class TestPrettyPrint < Test::Unit::TestCase
|
|
@@ -34,6 +34,14 @@ class TestPrettyPrint < Test::Unit::TestCase
|
|
|
34
34
|
assert_equal "(12 & 15)", parse("0b1100 & 0b1111").inspect
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def test_rshift
|
|
38
|
+
assert_equal("(10 >> 2)", parse("10 >> 2").inspect)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_lshift
|
|
42
|
+
assert_equal("(10 << 2)", parse("10 << 2").inspect)
|
|
43
|
+
end
|
|
44
|
+
|
|
37
45
|
def test_subtraction
|
|
38
46
|
assert_equal "(10 - 5)", parse("10 - 5").inspect
|
|
39
47
|
assert_equal "(5 - 10)", parse("5 - 10").inspect
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/helper"
|
|
2
|
+
|
|
3
|
+
class TestTokenizer < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@tokenizer = Einstein::Tokenizer.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_rshift
|
|
9
|
+
assert_equal [[:RSHIFT, ">>"]], tokenize(">>")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_lshift
|
|
13
|
+
assert_equal [[:LSHIFT, "<<"]], tokenize("<<")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_raise
|
|
17
|
+
assert_equal [[:RAISE, "**"]], tokenize("**")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_single_char
|
|
21
|
+
assert_equal [["(", "("]], tokenize("(")
|
|
22
|
+
assert_equal [["{", "{"]], tokenize("{")
|
|
23
|
+
assert_equal [["!", "!"]], tokenize("!")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_comment
|
|
27
|
+
assert_equal [[:COMMENT, "/* hope this works... */"]], tokenize("/* hope this works... */")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_whitespace
|
|
31
|
+
assert_equal [[:WS, " \t\r\n"]], tokenize(" \t\r\n")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_ident
|
|
35
|
+
assert_equal [[:IDENT, "x"]], tokenize("x")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_float_scientific
|
|
39
|
+
assert_equal [[:NUMBER, 10.10e-3]], tokenize("10.10e-3")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_float
|
|
43
|
+
assert_equal [[:NUMBER, 10.10]], tokenize("10.10")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_number_base2
|
|
47
|
+
assert_equal [[:NUMBER, 0b1010]], tokenize("0b1010")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_number_base8
|
|
51
|
+
assert_equal [[:NUMBER, 011]], tokenize("011")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_number_base16
|
|
55
|
+
assert_equal [[:NUMBER, 0xdeadbeef]], tokenize("0xdeadbeef")
|
|
56
|
+
assert_equal [[:NUMBER, 0xCAFEBABE]], tokenize("0xCAFEBABE")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_number_base10
|
|
60
|
+
assert_equal [[:NUMBER, 15]], tokenize("15")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def tokenize(stmt)
|
|
66
|
+
@tokenizer.tokenize(stmt)
|
|
67
|
+
end
|
|
68
|
+
end
|
data/website/index.html
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
<h1>einstein</h1>
|
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/einstein"; return false'>
|
|
35
35
|
<p>Get Version</p>
|
|
36
|
-
<a href="http://rubyforge.org/projects/einstein" class="numbers">0.1.
|
|
36
|
+
<a href="http://rubyforge.org/projects/einstein" class="numbers">0.1.1</a>
|
|
37
37
|
</div>
|
|
38
38
|
<h2>What</h2>
|
|
39
39
|
|
|
@@ -109,7 +109,7 @@ offers a .tgz file download for those of you who don’t have git installed
|
|
|
109
109
|
Einstein and take it to crazy new places. If I like your changes, I’ll merge
|
|
110
110
|
them into the master branch.</p>
|
|
111
111
|
<p class="coda">
|
|
112
|
-
<a href="http://github.com/omghax">Dray Lacy</a>,
|
|
112
|
+
<a href="http://github.com/omghax">Dray Lacy</a>, 8th May 2008<br>
|
|
113
113
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
|
114
114
|
</p>
|
|
115
115
|
</div>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omghax-einstein
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dray Lacy
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-
|
|
12
|
+
date: 2008-05-08 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -50,7 +50,7 @@ files:
|
|
|
50
50
|
- tasks/environment.rake
|
|
51
51
|
- tasks/website.rake
|
|
52
52
|
- test/test_evaluate.rb
|
|
53
|
-
- test/
|
|
53
|
+
- test/helper.rb
|
|
54
54
|
- test/test_parser.rb
|
|
55
55
|
- test/test_pretty_print.rb
|
|
56
56
|
- website/index.html
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- website/javascripts/rounded_corners_lite.inc.js
|
|
59
59
|
- website/stylesheets/screen.css
|
|
60
60
|
- website/template.rhtml
|
|
61
|
+
- test/test_tokenizer.rb
|
|
61
62
|
has_rdoc: true
|
|
62
63
|
homepage: http://einstein.rubyforge.org
|
|
63
64
|
post_install_message:
|
|
@@ -87,6 +88,6 @@ specification_version: 2
|
|
|
87
88
|
summary: Safe arithmetic parser for Ruby apps
|
|
88
89
|
test_files:
|
|
89
90
|
- test/test_evaluate.rb
|
|
90
|
-
- test/test_helper.rb
|
|
91
91
|
- test/test_parser.rb
|
|
92
92
|
- test/test_pretty_print.rb
|
|
93
|
+
- test/test_tokenizer.rb
|