cirru-sepal 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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +2 -0
- data/bin/sepal.rb +16 -0
- data/cirru-sepal.gemspec +26 -0
- data/lib/cirru/sepal.rb +53 -0
- data/lib/cirru/sepal/version.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6b79a7a004f8b71a8a6e94679f217e6f50ff18bf
|
4
|
+
data.tar.gz: 0ce3748f93025f6a4d6d77ce2aaff2bf588a8366
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b0c3a1cf44899f7419617c0f81e04347ac03d5d4296914b76922481a2690bd4984f97cc0386b301675e71825d96a3205539b7060c12a6cea4cf29a474924df3
|
7
|
+
data.tar.gz: d62aa7d1ca8a4ccfa18ea1dfbd9c47400d436e67b4d9ab90f32fa54077a56eaf62ca50683f4a7ac6f8c321ecf87a82959ff8c736520af74ad09b1c9e70b47815
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 jiyinyiyong
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Cirru::Sepal
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
https://www.igvita.com/2008/12/11/ruby-ast-for-fun-and-profit/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cirru-sepal'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install cirru-sepal
|
25
|
+
```
|
26
|
+
|
27
|
+
You may also get command `sepal.rb` for running Cirru files for Ruby AST.
|
28
|
+
|
29
|
+
```
|
30
|
+
sepal.rb demo.cirru
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Compiling Cirru code in to Ruby.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'cirru/sepal'
|
39
|
+
rubyCode = Cirru::Sepal.compile code, file
|
40
|
+
```
|
41
|
+
|
42
|
+
Here is a glance of Cirru code for Ruby AST:
|
43
|
+
|
44
|
+
```cirru
|
45
|
+
lasgn a :1
|
46
|
+
lasgn b 1
|
47
|
+
|
48
|
+
call nil p (lvar a)
|
49
|
+
|
50
|
+
defn p2 (args x)
|
51
|
+
call nil p (lvar x)
|
52
|
+
|
53
|
+
call nil p2 :demo
|
54
|
+
|
55
|
+
call nil p
|
56
|
+
call (call 1 + 2) + 3
|
57
|
+
```
|
58
|
+
|
59
|
+
It compiles to(and then eval):
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
a = "1"
|
63
|
+
b = 1
|
64
|
+
|
65
|
+
p(a)
|
66
|
+
|
67
|
+
def p2(x)
|
68
|
+
p(x)
|
69
|
+
end
|
70
|
+
|
71
|
+
p2("demo")
|
72
|
+
|
73
|
+
p(((1 + 2) + 3))
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it ( https://github.com/[my-github-username]/cirru-sepal/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/sepal.rb
ADDED
data/cirru-sepal.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cirru/sepal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cirru-sepal"
|
8
|
+
spec.version = Cirru::Sepal::VERSION
|
9
|
+
spec.authors = ["jiyinyiyong"]
|
10
|
+
spec.email = ["jiyinyiyong@gmail.com"]
|
11
|
+
spec.summary = %q{Cirru Sepal: play with Cirru AST}
|
12
|
+
spec.description = %q{Generate Ruby AST in Cirru grammar}
|
13
|
+
spec.homepage = "https://github.com/Cirru/sepal.rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'cirru-parser', '~> 0.0.2'
|
25
|
+
spec.add_runtime_dependency 'ruby2ruby', '~> 2.1.4'
|
26
|
+
end
|
data/lib/cirru/sepal.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require "cirru/sepal/version"
|
3
|
+
require 'cirru/parser'
|
4
|
+
require 'ruby2ruby'
|
5
|
+
|
6
|
+
module Cirru
|
7
|
+
module Sepal
|
8
|
+
def self.compile(code, file)
|
9
|
+
tree = Cirru::Parser.pare code, file
|
10
|
+
ast = program tree
|
11
|
+
generateCode ast
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def generateCode(ast)
|
17
|
+
# p 'Ast:', ast
|
18
|
+
ruby2ruby = Ruby2Ruby.new
|
19
|
+
ruby2ruby.process ast
|
20
|
+
end
|
21
|
+
|
22
|
+
def program(tree)
|
23
|
+
statements = tree.map do |line|
|
24
|
+
transform line
|
25
|
+
end
|
26
|
+
s :block, *statements
|
27
|
+
end
|
28
|
+
|
29
|
+
def transform(tree)
|
30
|
+
if tree.is_a? Array
|
31
|
+
head = tree[0]
|
32
|
+
body = tree[1..-1]
|
33
|
+
list = body.map do |item|
|
34
|
+
transform item
|
35
|
+
end
|
36
|
+
s parseToken(head), *list
|
37
|
+
else # string then
|
38
|
+
parseToken tree
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def parseToken(text)
|
43
|
+
if text == 'nil'
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
if text[0] == ':'
|
47
|
+
return s(:str, text[1..-1])
|
48
|
+
end
|
49
|
+
if text =~ /^[+-.]?[\d\.]+/
|
50
|
+
return s(:lit, text.to_i)
|
51
|
+
end
|
52
|
+
return text.to_sym
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cirru-sepal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiyinyiyong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-24 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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cirru-parser
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby2ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.4
|
69
|
+
description: Generate Ruby AST in Cirru grammar
|
70
|
+
email:
|
71
|
+
- jiyinyiyong@gmail.com
|
72
|
+
executables:
|
73
|
+
- sepal.rb
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/sepal.rb
|
83
|
+
- cirru-sepal.gemspec
|
84
|
+
- lib/cirru/sepal.rb
|
85
|
+
- lib/cirru/sepal/version.rb
|
86
|
+
homepage: https://github.com/Cirru/sepal.rb
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.14
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: 'Cirru Sepal: play with Cirru AST'
|
110
|
+
test_files: []
|