lucio 0.0.7 → 0.0.8

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 (47) hide show
  1. data/Gemfile +4 -9
  2. data/Gemfile.lock +3 -11
  3. data/README.md +9 -9
  4. data/Rakefile +0 -3
  5. data/VERSION +1 -1
  6. data/bin/lucio +1 -1
  7. data/bin/repl.rb +19 -21
  8. data/lib/lucio.rb +2 -0
  9. data/lib/lucio/lexicon.rb +12 -20
  10. data/lib/lucio/lucio.rb +48 -18
  11. data/lucio.gemspec +17 -42
  12. data/spec/add_spec.rb +34 -0
  13. data/spec/behead_spec.rb +12 -0
  14. data/spec/divide_spec.rb +26 -0
  15. data/spec/empty_list_spec.rb +23 -0
  16. data/spec/internal_spec.rb +13 -0
  17. data/spec/let_spec.rb +29 -0
  18. data/spec/minus_spec.rb +27 -0
  19. data/spec/readme_examples_spec.rb +32 -0
  20. data/spec/spec_helper.rb +3 -1
  21. data/spec/times_spec.rb +34 -0
  22. metadata +31 -80
  23. data/.autotest +0 -3
  24. data/TODO.md +0 -32
  25. data/lib/lucio/grammar.rb +0 -37
  26. data/lib/lucio/list.rb +0 -22
  27. data/lib/lucio/operators.rb +0 -9
  28. data/lib/lucio/operators/attribution.rb +0 -10
  29. data/lib/lucio/operators/conditional.rb +0 -20
  30. data/lib/lucio/operators/division.rb +0 -16
  31. data/lib/lucio/operators/equality.rb +0 -11
  32. data/lib/lucio/operators/macro.rb +0 -15
  33. data/lib/lucio/operators/multiplication.rb +0 -16
  34. data/lib/lucio/operators/operator.rb +0 -29
  35. data/lib/lucio/operators/subtraction.rb +0 -18
  36. data/lib/lucio/operators/sum.rb +0 -13
  37. data/lib/lucio/runner.rb +0 -60
  38. data/lib/lucio_syntax.treetop +0 -92
  39. data/spec/all_the_fun_spec.rb +0 -21
  40. data/spec/division_spec.rb +0 -19
  41. data/spec/eval_spec.rb +0 -116
  42. data/spec/lucio_spec.rb +0 -25
  43. data/spec/multiplication_spec.rb +0 -19
  44. data/spec/parser_spec.rb +0 -105
  45. data/spec/subtraction_spec.rb +0 -19
  46. data/spec/sum_spec.rb +0 -19
  47. data/spec/variable_spec.rb +0 -13
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'behead' do
5
+
6
+ it 'should return the first item and the rest' do
7
+ h, t = Lucio.behead [1, 2, 3, 4]
8
+ h.should == 1
9
+ t.should == [2, 3, 4]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'divide' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'without parameters should return zero' do
10
+ lambda {@lucio.eval('(/)')}.should raise_error
11
+ end
12
+
13
+ it 'with one value should return that value' do
14
+ @lucio.eval('(/ 2)').should == 0.5
15
+ end
16
+
17
+ it 'with two values should return the sum' do
18
+ @lucio.eval('(/ 8 4)').should == 2
19
+ end
20
+
21
+ it 'with nested lists should eval the list before return the sum' do
22
+ @lucio.eval('(/ 4 (/ 8 2))').should == 1
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'empty lists' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'given an empty list should return nil' do
10
+ @lucio.eval('()').should be_nil
11
+ end
12
+
13
+ it 'given two empty lists should return nil' do
14
+ @lucio.eval('()()').should be_nil
15
+ end
16
+
17
+ it 'given nested lists should be empty' do
18
+ lambda {@lucio.eval('(())')}.should raise_error
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'internal' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it "should sample some internal usage" do
10
+ @lucio.eval('()')
11
+ end
12
+ end
13
+ end
data/spec/let_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'let' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'should define x' do
10
+ code = '
11
+ (let x 10)
12
+ (eql? x 10)'
13
+ @lucio.eval(code).should be_true
14
+ end
15
+
16
+ it 'should define x as a arithmetic operation' do
17
+ code = '
18
+ (let x (* 10 2))
19
+ (eql? x (* 10 2))'
20
+ @lucio.eval(code).should be_true
21
+ end
22
+
23
+ it 'should define x as a comparison result' do
24
+ code = '(eql? (* 10 2) 20)'
25
+ @lucio.eval(code).should be_true
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'minus' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'without parameters should return zero' do
10
+ @lucio.eval('(- )').should == 0
11
+ end
12
+
13
+ it 'with one value should return that value' do
14
+ @lucio.eval('(- 3)').should == -3
15
+ end
16
+
17
+ it 'with two values should return the subtraction' do
18
+ @lucio.eval('(- 3 5)').should == -2
19
+ @lucio.eval('(- 5 3)').should == 2
20
+ end
21
+
22
+ it 'with nested lists should eval the list before return the sum' do
23
+ @lucio.eval('(- 5 (- 3 2))').should == 4
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'Examples found in README file' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'first example: math' do
10
+ @lucio.eval('(/ (* (+ 1 2) (+ 3 4)) 2)').should == 10.5
11
+ end
12
+
13
+ it 'second example: eql?' do
14
+ @lucio.eval('(eql? (* (+ 1 2) 3) 9)').should be_true
15
+ end
16
+
17
+ it 'third example: if' do
18
+ @lucio.eval('
19
+ (if (eql? 10.5 (/ (* (+ 1 2) (+ 3 4)) 2))
20
+ ("great"))').should == 'great'
21
+ end
22
+
23
+ it 'fourth example: if else' do
24
+ code = '
25
+ (if (eql? 0 (/ (* (+ 1 2) (+ 3 4)) 2))
26
+ ("great")
27
+ ("ouch"))'
28
+
29
+ @lucio.eval(code).should == 'ouch'
30
+ end
31
+ end
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'simplecov'
2
+ SimpleCov.start
2
3
 
3
- SimpleCov.start # if ENV['COVERAGE']
4
+ require 'rspec'
5
+ require 'lucio'
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lucio do
4
+ context 'times' do
5
+ before :each do
6
+ @lucio = Lucio.new
7
+ end
8
+
9
+ it 'without parameters should return zero' do
10
+ @lucio.eval('(*)').should == 1
11
+ end
12
+
13
+ it 'with one value should return that value' do
14
+ @lucio.eval('(* 3)').should == 3
15
+ end
16
+
17
+ it 'with two values should return the multiplication' do
18
+ @lucio.eval('(* 3 5)').should == 15
19
+ end
20
+
21
+ it 'with nested lists should eval the list before return the multiplication' do
22
+ @lucio.eval('(* 3 (* 3 2))').should == 18
23
+ end
24
+
25
+ it 'with neeeeeeesteeeeeeeed freeeeezy!' do
26
+ @lucio.eval('(* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 (* 3 2))))))))))))))').should == (3 ** 14) * 2
27
+ end
28
+
29
+ it 'with invalid operator should raise error' do
30
+ lambda {@lucio.eval('((* 3 4))')}.should raise_error UnboundSymbolException
31
+ end
32
+
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,34 +9,23 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-15 00:00:00.000000000 -03:00
12
+ date: 2011-07-19 00:00:00.000000000 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: polyglot
17
- requirement: &11461008 !ruby/object:Gem::Requirement
16
+ name: sparse
17
+ requirement: &11020860 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *11461008
26
- - !ruby/object:Gem::Dependency
27
- name: treetop
28
- requirement: &11460720 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ! '>='
20
+ - - ~>
32
21
  - !ruby/object:Gem::Version
33
- version: '0'
22
+ version: 0.0.3
34
23
  type: :runtime
35
24
  prerelease: false
36
- version_requirements: *11460720
25
+ version_requirements: *11020860
37
26
  - !ruby/object:Gem::Dependency
38
27
  name: rspec
39
- requirement: &11460396 !ruby/object:Gem::Requirement
28
+ requirement: &11020560 !ruby/object:Gem::Requirement
40
29
  none: false
41
30
  requirements:
42
31
  - - ! '>='
@@ -44,62 +33,40 @@ dependencies:
44
33
  version: '0'
45
34
  type: :development
46
35
  prerelease: false
47
- version_requirements: *11460396
36
+ version_requirements: *11020560
48
37
  - !ruby/object:Gem::Dependency
49
- name: ZenTest
50
- requirement: &11460108 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: *11460108
59
- - !ruby/object:Gem::Dependency
60
- name: diff-lcs
61
- requirement: &11459820 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: *11459820
70
- - !ruby/object:Gem::Dependency
71
- name: yard
72
- requirement: &11459508 !ruby/object:Gem::Requirement
38
+ name: bundler
39
+ requirement: &11020236 !ruby/object:Gem::Requirement
73
40
  none: false
74
41
  requirements:
75
42
  - - ~>
76
43
  - !ruby/object:Gem::Version
77
- version: 0.6.0
44
+ version: 1.0.0
78
45
  type: :development
79
46
  prerelease: false
80
- version_requirements: *11459508
47
+ version_requirements: *11020236
81
48
  - !ruby/object:Gem::Dependency
82
- name: bundler
83
- requirement: &11459184 !ruby/object:Gem::Requirement
49
+ name: jeweler
50
+ requirement: &11019924 !ruby/object:Gem::Requirement
84
51
  none: false
85
52
  requirements:
86
53
  - - ~>
87
54
  - !ruby/object:Gem::Version
88
- version: 1.0.0
55
+ version: 1.6.4
89
56
  type: :development
90
57
  prerelease: false
91
- version_requirements: *11459184
58
+ version_requirements: *11019924
92
59
  - !ruby/object:Gem::Dependency
93
- name: jeweler
94
- requirement: &11458896 !ruby/object:Gem::Requirement
60
+ name: simplecov
61
+ requirement: &11019612 !ruby/object:Gem::Requirement
95
62
  none: false
96
63
  requirements:
97
64
  - - ~>
98
65
  - !ruby/object:Gem::Version
99
- version: 1.6.4
66
+ version: 0.4.0
100
67
  type: :development
101
68
  prerelease: false
102
- version_requirements: *11458896
69
+ version_requirements: *11019612
103
70
  description: Lucio is intended to be a Lisp-like language developed in Ruby only for
104
71
  knowledge and fun.
105
72
  email: pbalduino+github@gmail.com
@@ -112,7 +79,6 @@ extra_rdoc_files:
112
79
  - LICENSE.txt
113
80
  - README.md
114
81
  files:
115
- - .autotest
116
82
  - .document
117
83
  - .rspec
118
84
  - .rvmrc
@@ -122,38 +88,23 @@ files:
122
88
  - LICENSE.txt
123
89
  - README.md
124
90
  - Rakefile
125
- - TODO.md
126
91
  - VERSION
127
92
  - bin/lucio
128
93
  - bin/repl.rb
129
94
  - lib/lucio.rb
130
- - lib/lucio/grammar.rb
131
95
  - lib/lucio/lexicon.rb
132
- - lib/lucio/list.rb
133
96
  - lib/lucio/lucio.rb
134
- - lib/lucio/operators.rb
135
- - lib/lucio/operators/attribution.rb
136
- - lib/lucio/operators/conditional.rb
137
- - lib/lucio/operators/division.rb
138
- - lib/lucio/operators/equality.rb
139
- - lib/lucio/operators/macro.rb
140
- - lib/lucio/operators/multiplication.rb
141
- - lib/lucio/operators/operator.rb
142
- - lib/lucio/operators/subtraction.rb
143
- - lib/lucio/operators/sum.rb
144
- - lib/lucio/runner.rb
145
- - lib/lucio_syntax.treetop
146
97
  - lucio.gemspec
147
- - spec/all_the_fun_spec.rb
148
- - spec/division_spec.rb
149
- - spec/eval_spec.rb
150
- - spec/lucio_spec.rb
151
- - spec/multiplication_spec.rb
152
- - spec/parser_spec.rb
98
+ - spec/add_spec.rb
99
+ - spec/behead_spec.rb
100
+ - spec/divide_spec.rb
101
+ - spec/empty_list_spec.rb
102
+ - spec/internal_spec.rb
103
+ - spec/let_spec.rb
104
+ - spec/minus_spec.rb
105
+ - spec/readme_examples_spec.rb
153
106
  - spec/spec_helper.rb
154
- - spec/subtraction_spec.rb
155
- - spec/sum_spec.rb
156
- - spec/variable_spec.rb
107
+ - spec/times_spec.rb
157
108
  has_rdoc: true
158
109
  homepage: https://github.com/pbalduino/lucio
159
110
  licenses:
@@ -170,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
121
  version: '0'
171
122
  segments:
172
123
  - 0
173
- hash: 177896529
124
+ hash: -427292301
174
125
  required_rubygems_version: !ruby/object:Gem::Requirement
175
126
  none: false
176
127
  requirements:
data/.autotest DELETED
@@ -1,3 +0,0 @@
1
- Autotest.add_hook(:initialize) do |at|
2
- at.add_exception %r{coverage}
3
- end
data/TODO.md DELETED
@@ -1,32 +0,0 @@
1
- # TODO
2
-
3
- ## Introdução
4
-
5
- 1. Toda a comunicação será feita através desse arquivo, das mensagens de commit e do código.
6
-
7
- 1. Dúvidas, intenções e próximos passos serão incluidos aqui.
8
-
9
- 1. Commits mal explicados ou sem uma mensagem clara e objetiva serão revertidos.
10
-
11
- 1. ???
12
-
13
- 1. Profit
14
-
15
- ## Tarefas
16
-
17
- * Podemos fazer de duas formas: apagar as linhas de mensagens que foram resolvidas ou podemos simplesmente <strike>riscá-las</strike> e mantê-las por aqui, como uma forma rudimentar de histórico para quem não quiser/puder ver o versionamento do arquivo. O quê você prefere?
18
-
19
- * Escrever testes para casos especiais ou que ainda levantem dúvidas sobre o funcionamento do parser.
20
-
21
- * Finalizada uma versão funcional do parser, criar testes para resolver pequenas expressões matemáticas e fazer com que o Runner as execute.
22
-
23
- * Minha primeira idéia foi de usar a classe Lexicon como uma espécie de dicionário de funções e operadores, onde ficariam as funções existentes e as novas. O Runner vai executar a expressão correspondente ao operador utilizando valores simples da lista. Caso seja encontrada uma lista dentro da lista atual, ela será passada recursivamente ao Runner até que retorne um valor simples.
24
-
25
- * Exemplo:
26
- <pre>
27
- (eql? (+ 1 2) 3)
28
- |
29
- +--> runner: eql? (lista) 3 +-> eql? 3 3 -> true
30
- | |
31
- +-----> runner + 1 2 --> returns 3 --+
32
- </pre>