python 0.0.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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +60 -0
  6. data/Rakefile +2 -0
  7. data/bin/python.rb +16 -0
  8. data/examples/demo.py +10 -0
  9. data/examples/fibonacci.py +5 -0
  10. data/examples/twoclass.py +9 -0
  11. data/features/programmer_caclulate_numerical_expression.feature +50 -0
  12. data/features/programmer_execute_from_source_file.feature +10 -0
  13. data/features/programmer_starts_repl_console.feature +10 -0
  14. data/features/programmer_use_advanced_calculator.feature +35 -0
  15. data/features/programmer_use_class.feature +42 -0
  16. data/features/programmer_use_closure.feature +66 -0
  17. data/features/programmer_use_variables.feature +12 -0
  18. data/features/step_definitions/calculate_numerical_steps.rb +67 -0
  19. data/features/support/env.rb +2 -0
  20. data/lib/python.rb +10 -0
  21. data/lib/python/builtins.rb +72 -0
  22. data/lib/python/environment.rb +42 -0
  23. data/lib/python/file_interpreter.rb +29 -0
  24. data/lib/python/parser/combinator.rb +206 -0
  25. data/lib/python/parser/expression.rb +125 -0
  26. data/lib/python/parser/identifier.rb +22 -0
  27. data/lib/python/parser/indent_converter.rb +52 -0
  28. data/lib/python/parser/integer.rb +28 -0
  29. data/lib/python/parser/statement.rb +86 -0
  30. data/lib/python/pyobject.rb +129 -0
  31. data/lib/python/repl.rb +47 -0
  32. data/lib/python/syntax.rb +201 -0
  33. data/lib/python/version.rb +3 -0
  34. data/python.gemspec +24 -0
  35. data/spec/python/parser/expression_spec.rb +28 -0
  36. data/spec/python/parser/indent_converter_spec.rb +36 -0
  37. data/spec/python/pyobject_spec.rb +20 -0
  38. data/spec/python/repl_spec.rb +14 -0
  39. data/spec/spec_helper.rb +1 -0
  40. metadata +125 -0
@@ -0,0 +1,3 @@
1
+ module Python
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- mode: ruby -*-
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'python/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "python"
9
+ spec.version = Python::VERSION
10
+ spec.authors = ["Kensuke Sawada"]
11
+ spec.email = ["sasasawada@gmail.com"]
12
+ spec.summary = %q{Python in Ruby}
13
+ spec.description = %q{Python implemented purely in Ruby without any library}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Python
4
+ module Parser
5
+ describe ExpressionParser do
6
+ describe "#parse" do
7
+ def BOP(name, l, r)
8
+ Syntax::BinaryOp.new(name, l, r)
9
+ end
10
+
11
+ def UOP(name, e)
12
+ Syntax::UnaryOp.new(name, e)
13
+ end
14
+
15
+ def LO(n)
16
+ Syntax::LiteralObject.new(Builtins::Int.make_instance(n))
17
+ end
18
+
19
+ it "parse numerical expression" do
20
+ ast = ExpressionParser.expression.parse("-(1+10)*+(100//1000)").parsed
21
+ expect(ast) == BOP("__mul__",
22
+ UOP("__neg__", BOP("__add__", LO(1), LO(10))),
23
+ UOP("__pos__", BOP("__floordiv__", LO(100), LO(1000))))
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module Python
4
+ module Parser
5
+ describe IndentConverter do
6
+ describe "#convert" do
7
+ it "convert indent" do
8
+
9
+ input_code = <<CODE
10
+ def aaa():
11
+ def bbb():
12
+ def ccc():
13
+ x = 1 + 1
14
+ return 123
15
+ return ccc
16
+
17
+ aaa()
18
+ CODE
19
+
20
+ expected_code = <<CODE
21
+ def aaa():
22
+ $Idef bbb():
23
+ $Idef ccc():
24
+ $Ix = 1 + 1
25
+ return 123
26
+ $D$Dreturn ccc
27
+ $D
28
+ aaa()
29
+
30
+ CODE
31
+ expect(IndentConverter.new.convert(input_code)).to eq(expected_code)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Python
4
+ describe PyObject do
5
+ describe "#get_special_attr" do
6
+ it "gets special attr of direct-class" do
7
+ cls = PyObject.new("__xxx__" => PyObject.new(:entity => 1))
8
+ obj = PyObject.new(:class => cls)
9
+ expect(obj.get_special_attr("__xxx__")).to eq(PyObject.new(:entity => 1))
10
+ end
11
+
12
+ it "gets special attr of base-class" do
13
+ base = PyObject.new("__xxx__" => PyObject.new(:entity => 1))
14
+ dire = PyObject.new(:bases => [base])
15
+ obj = PyObject.new(:class => dire)
16
+ expect(obj.get_special_attr("__xxx__")).to eq(PyObject.new(:entity => 1))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ module Python
4
+ describe REPL do
5
+ describe "#start" do
6
+ it "prompts for the input" do
7
+ output = double('output')
8
+ repl = REPL.new(output)
9
+ expect(output).to receive(:print).with("python.rb> ")
10
+ repl.start
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ require 'python'
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: python
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kensuke Sawada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Python implemented purely in Ruby without any library
42
+ email:
43
+ - sasasawada@gmail.com
44
+ executables:
45
+ - python.rb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/python.rb
55
+ - examples/demo.py
56
+ - examples/fibonacci.py
57
+ - examples/twoclass.py
58
+ - features/programmer_caclulate_numerical_expression.feature
59
+ - features/programmer_execute_from_source_file.feature
60
+ - features/programmer_starts_repl_console.feature
61
+ - features/programmer_use_advanced_calculator.feature
62
+ - features/programmer_use_class.feature
63
+ - features/programmer_use_closure.feature
64
+ - features/programmer_use_variables.feature
65
+ - features/step_definitions/calculate_numerical_steps.rb
66
+ - features/support/env.rb
67
+ - lib/python.rb
68
+ - lib/python/builtins.rb
69
+ - lib/python/environment.rb
70
+ - lib/python/file_interpreter.rb
71
+ - lib/python/parser/combinator.rb
72
+ - lib/python/parser/expression.rb
73
+ - lib/python/parser/identifier.rb
74
+ - lib/python/parser/indent_converter.rb
75
+ - lib/python/parser/integer.rb
76
+ - lib/python/parser/statement.rb
77
+ - lib/python/pyobject.rb
78
+ - lib/python/repl.rb
79
+ - lib/python/syntax.rb
80
+ - lib/python/version.rb
81
+ - python.gemspec
82
+ - spec/python/parser/expression_spec.rb
83
+ - spec/python/parser/indent_converter_spec.rb
84
+ - spec/python/pyobject_spec.rb
85
+ - spec/python/repl_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Python in Ruby
111
+ test_files:
112
+ - features/programmer_caclulate_numerical_expression.feature
113
+ - features/programmer_execute_from_source_file.feature
114
+ - features/programmer_starts_repl_console.feature
115
+ - features/programmer_use_advanced_calculator.feature
116
+ - features/programmer_use_class.feature
117
+ - features/programmer_use_closure.feature
118
+ - features/programmer_use_variables.feature
119
+ - features/step_definitions/calculate_numerical_steps.rb
120
+ - features/support/env.rb
121
+ - spec/python/parser/expression_spec.rb
122
+ - spec/python/parser/indent_converter_spec.rb
123
+ - spec/python/pyobject_spec.rb
124
+ - spec/python/repl_spec.rb
125
+ - spec/spec_helper.rb