ppr 0.0.2
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 +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +333 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ppr.rb +12 -0
- data/lib/ppr/bar.inc +1 -0
- data/lib/ppr/foo.inc +1 -0
- data/lib/ppr/keyword_searcher.rb +105 -0
- data/lib/ppr/ppr_core.rb +849 -0
- data/lib/ppr/safer_generator.rb +130 -0
- data/lib/ppr/test_keyword_searcher.rb +57 -0
- data/lib/ppr/test_ppr.inc +7 -0
- data/lib/ppr/test_ppr.rb +291 -0
- data/lib/ppr/test_ppr.txt +62 -0
- data/lib/ppr/test_ppr2.txt +61 -0
- data/lib/ppr/test_ppr_exp.txt +31 -0
- data/lib/ppr/test_safer_generator.rb +140 -0
- data/lib/ppr/version.rb +3 -0
- data/ppr.gemspec +39 -0
- metadata +114 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
.assign F :< "File"
|
2
|
+
.do
|
3
|
+
:< "# #{@F} for testing Ppr"
|
4
|
+
.end
|
5
|
+
|
6
|
+
|
7
|
+
.if :< true
|
8
|
+
.def HW
|
9
|
+
:<"#{@hello} world!"
|
10
|
+
.end
|
11
|
+
.endif
|
12
|
+
|
13
|
+
.if :<false
|
14
|
+
:< "Should not happen!"
|
15
|
+
.else
|
16
|
+
.def He
|
17
|
+
:<"Hello "
|
18
|
+
.end
|
19
|
+
.endif
|
20
|
+
|
21
|
+
.def Wo
|
22
|
+
:<"world!"
|
23
|
+
.end
|
24
|
+
|
25
|
+
.def Surprise
|
26
|
+
:<"!"
|
27
|
+
.end
|
28
|
+
|
29
|
+
.doR
|
30
|
+
:< "HW in different programming languages\n"
|
31
|
+
.end
|
32
|
+
.require :< "bar.inc"
|
33
|
+
.require :< "bar.inc"
|
34
|
+
|
35
|
+
* In BASIC:
|
36
|
+
PRINT "HW":
|
37
|
+
|
38
|
+
* In Scheme:
|
39
|
+
(write 'He##world!)
|
40
|
+
|
41
|
+
* In OCaml:
|
42
|
+
print_string "Hello world##Surprise";;
|
43
|
+
|
44
|
+
|
45
|
+
.def rep(word,num)
|
46
|
+
:< word \
|
47
|
+
* num.to_i
|
48
|
+
.end
|
49
|
+
.def repp(word,num) :< word + word + word
|
50
|
+
.load :< "test_ppr.inc"
|
51
|
+
|
52
|
+
Multiple times He##Wo in different programming languages
|
53
|
+
###############################################################
|
54
|
+
|
55
|
+
* In BASIC:
|
56
|
+
rep(PRINT "Hello world!": ,3)
|
57
|
+
|
58
|
+
* In Scheme:
|
59
|
+
repp((write 'HW\) ,3)
|
60
|
+
|
61
|
+
* In OCaml:
|
62
|
+
repr(print_string "HW";; ,3)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
ASSIGN F ~> "File"
|
2
|
+
RUBY
|
3
|
+
~>"# #{@F} for testing Ppr"
|
4
|
+
ENDM
|
5
|
+
|
6
|
+
|
7
|
+
MACRO HW
|
8
|
+
~>"#{@hello} world!"
|
9
|
+
ENDM
|
10
|
+
|
11
|
+
MACRO He
|
12
|
+
~>"Hello "
|
13
|
+
ENDM
|
14
|
+
|
15
|
+
MACRO Wo
|
16
|
+
~>"world!"
|
17
|
+
ENDM
|
18
|
+
|
19
|
+
MACRO Surprise
|
20
|
+
~>"!"
|
21
|
+
ENDM
|
22
|
+
|
23
|
+
RUBYR
|
24
|
+
~>"HW in different programming languages\n"
|
25
|
+
ENDM
|
26
|
+
###############################################################
|
27
|
+
|
28
|
+
* In BASIC:
|
29
|
+
PRINT "HW":
|
30
|
+
|
31
|
+
* In Scheme:
|
32
|
+
(write 'He@@world!)
|
33
|
+
|
34
|
+
* In OCaml:
|
35
|
+
print_string "Hello world@@Surprise";;
|
36
|
+
|
37
|
+
|
38
|
+
MACRO rep(word,num)
|
39
|
+
~> word \
|
40
|
+
* num.to_i
|
41
|
+
ENDM
|
42
|
+
MACRO repp(word,num) ~> word + word + word
|
43
|
+
MACRO_R repr(word,num)
|
44
|
+
~> word
|
45
|
+
num = num.to_i - 1
|
46
|
+
if num > 0 then
|
47
|
+
~> "repr(#{word},#{num})"
|
48
|
+
end
|
49
|
+
ENDM
|
50
|
+
|
51
|
+
Multiple times He@@Wo in different programming languages
|
52
|
+
###############################################################
|
53
|
+
|
54
|
+
* In BASIC:
|
55
|
+
rep(PRINT "Hello world!": ,3)
|
56
|
+
|
57
|
+
* In Scheme:
|
58
|
+
repp((write 'HW\) ,3)
|
59
|
+
|
60
|
+
* In OCaml:
|
61
|
+
repr(print_string "HW";; ,3)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# File for testing Ppr
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
Hello world! in different programming languages
|
8
|
+
###############################################################
|
9
|
+
|
10
|
+
* In BASIC:
|
11
|
+
PRINT "Hello world!":
|
12
|
+
|
13
|
+
* In Scheme:
|
14
|
+
(write 'Hello world!)
|
15
|
+
|
16
|
+
* In OCaml:
|
17
|
+
print_string "Hello world!";;
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
Multiple times Hello world! in different programming languages
|
22
|
+
###############################################################
|
23
|
+
|
24
|
+
* In BASIC:
|
25
|
+
PRINT "Hello world!": PRINT "Hello world!": PRINT "Hello world!":
|
26
|
+
|
27
|
+
* In Scheme:
|
28
|
+
(write 'Hello world!) (write 'Hello world!) (write 'Hello world!)
|
29
|
+
|
30
|
+
* In OCaml:
|
31
|
+
print_string "Hello world!";; print_string "Hello world!";; print_string "Hello world!";;
|
@@ -0,0 +1,140 @@
|
|
1
|
+
######################################################################
|
2
|
+
## Program testing SaferGenerator ##
|
3
|
+
######################################################################
|
4
|
+
|
5
|
+
require "ppr.rb"
|
6
|
+
|
7
|
+
# Create the generator
|
8
|
+
puts "Creating the generator..."
|
9
|
+
$generator = SaferGenerator.new
|
10
|
+
|
11
|
+
puts "Creating the procs to test..."
|
12
|
+
# Create the safe proc to test.
|
13
|
+
$safe = proc { |stream| stream << 10.times.to_a.join(", ") }
|
14
|
+
# Create the unsafes proc to test.
|
15
|
+
$unsafes = []
|
16
|
+
$unsafes << proc { |stream| File.open("bad.bad","w") {|file| file << "Bad\n" } }
|
17
|
+
$unsafes << proc { |stream| stream << "Going to dir..." << Dir["./*"] }
|
18
|
+
$unsafes << proc { |stream| stream << IO.binread(__FILE__) }
|
19
|
+
$unsafes << proc { |stream| stream << system("ls") }
|
20
|
+
$unsafes << proc { |stream| stream << `ls` }
|
21
|
+
$unsafes << proc { |stream| open("bad.bad","w") { |file| file << "Bad\n" } }
|
22
|
+
# Create the expected raised exceptions with the unsafe procs.
|
23
|
+
$exceptions = [ NameError, NameError, NameError, NoMethodError, NoMethodError,
|
24
|
+
NoMethodError ]
|
25
|
+
|
26
|
+
ok = true # Test result, true if not any trouble.
|
27
|
+
|
28
|
+
# Test the execution of safe code for generating text.
|
29
|
+
$expected = StringIO.new("")
|
30
|
+
$safe.call($expected)
|
31
|
+
$expected = $expected.string
|
32
|
+
$result = ""
|
33
|
+
print "Executing safe code..."
|
34
|
+
begin
|
35
|
+
$result = $generator.run(&$safe)
|
36
|
+
rescue Exception => e
|
37
|
+
puts "\nError: got exception #{e}"
|
38
|
+
ok = false
|
39
|
+
end
|
40
|
+
if ok then
|
41
|
+
if $expected == $result then
|
42
|
+
ok = true
|
43
|
+
else
|
44
|
+
ok = false
|
45
|
+
puts "\nError: unexpected execution result."
|
46
|
+
puts "Got #{$result} but expecting #{expected}."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
puts " ok.\n" if ok
|
50
|
+
|
51
|
+
# Test the execution of the unsafe code.
|
52
|
+
$unsafes.each.with_index do |unsafe,i|
|
53
|
+
print "Executing unsafe proc #{i}..."
|
54
|
+
begin
|
55
|
+
$result = $generator.run(&unsafe)
|
56
|
+
# Should not execute the following.
|
57
|
+
puts " Danger: the unsafe code should not have been executed."
|
58
|
+
ok = false
|
59
|
+
rescue Exception => e
|
60
|
+
if e.cause.class != $exceptions[i] then
|
61
|
+
puts " Danger: unexpected exception: #{e.cause.inspect}"
|
62
|
+
ok = false
|
63
|
+
end
|
64
|
+
puts " Safe: got exception #{e.cause.inspect} as expected."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# Now check the black list.
|
70
|
+
|
71
|
+
# Create a new safer generator with a blacked list methods or constants.
|
72
|
+
$blacks = [ :print, :Float ]
|
73
|
+
# Create the procs using black lists methods or constants.
|
74
|
+
$unsafes = []
|
75
|
+
$unsafes << proc { |stream| print "Should not work..." }
|
76
|
+
$unsafes << proc { |stream| Float.name }
|
77
|
+
# Create the expected exceptions.
|
78
|
+
$exceptions = [ NoMethodError, NameError ]
|
79
|
+
|
80
|
+
# Check each black listed element.
|
81
|
+
$blacks.each.with_index do |black,i|
|
82
|
+
puts "Creating a safer generator where '#{black}' is blacked list..."
|
83
|
+
$generator = SaferGenerator.new(black)
|
84
|
+
puts "Executing safe code..."
|
85
|
+
begin
|
86
|
+
$result = $generator.run(&$safe)
|
87
|
+
rescue Exception => e
|
88
|
+
puts "\nError: got exception #{e}"
|
89
|
+
ok = false
|
90
|
+
end
|
91
|
+
puts "Executing code with #{black}..."
|
92
|
+
begin
|
93
|
+
$result = $generator.run(&$unsafes[i])
|
94
|
+
# The following should not be executed.
|
95
|
+
puts " Danger: '#{black}' should not have been executed."
|
96
|
+
ok = false
|
97
|
+
rescue Exception => e
|
98
|
+
if e.cause.class == $exceptions[i] then
|
99
|
+
puts " Safe: got exception #{e.cause.inspect} as expected."
|
100
|
+
else
|
101
|
+
puts " Danger: unexpected exception #{e.cause.inspect}."
|
102
|
+
ok = false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Check with all the black list elements.
|
108
|
+
puts "Creating a safer generator where '#{$blacks}' are blacked list..."
|
109
|
+
$generator = SaferGenerator.new(*$blacks)
|
110
|
+
puts "Executing safe code..."
|
111
|
+
begin
|
112
|
+
$result = $generator.run(&$safe)
|
113
|
+
rescue Exception => e
|
114
|
+
puts "\nError: got exception #{e}"
|
115
|
+
ok = false
|
116
|
+
end
|
117
|
+
# Check each unsafe proc.
|
118
|
+
$unsafes.each.with_index do |unsafe,i|
|
119
|
+
puts "Executing code #{i}..."
|
120
|
+
begin
|
121
|
+
$result = $generator.run(&unsafe)
|
122
|
+
# The following should not be executed.
|
123
|
+
puts " Danger: the proc should not have been executed."
|
124
|
+
ok = false
|
125
|
+
rescue Exception => e
|
126
|
+
if e.cause.class == $exceptions[i] then
|
127
|
+
puts " Safe: got exception #{e.cause.inspect} as expected."
|
128
|
+
else
|
129
|
+
puts " Danger: unexpected exception #{e.cause.inspect}."
|
130
|
+
ok = false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
if ok then
|
137
|
+
puts "Success."
|
138
|
+
else
|
139
|
+
puts "Failure."
|
140
|
+
end
|
data/lib/ppr/version.rb
ADDED
data/ppr.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ppr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ppr"
|
8
|
+
spec.version = Ppr::VERSION
|
9
|
+
spec.authors = ["Lovic Gauthier"]
|
10
|
+
spec.email = ["lovic@ariake-nct.ac.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{Preprocessor in Ruby: text preprocessor where macros are specified in Ruby language.}
|
13
|
+
spec.description = %q{Preprocessor in Ruby: provides a Ruby class named Rpp which implements a text preprocessor where macros are specified in Ruby language.
|
14
|
+
Usage:
|
15
|
+
ppr = Ppr::Preprocessor.new(<configuration options if any>) ;
|
16
|
+
ppr.preprocess(<input stream to preprocess>, <output stream where to write the preprocessing result>)}
|
17
|
+
spec.homepage = "https://github.com/civol"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
21
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
22
|
+
# if spec.respond_to?(:metadata)
|
23
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
24
|
+
# else
|
25
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
# "public gem pushes."
|
27
|
+
# end
|
28
|
+
|
29
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
30
|
+
f.match(%r{^(test|spec|features)/})
|
31
|
+
end
|
32
|
+
spec.bindir = "exe"
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.require_paths = ["lib"]
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ppr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lovic Gauthier
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-30 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: |-
|
56
|
+
Preprocessor in Ruby: provides a Ruby class named Rpp which implements a text preprocessor where macros are specified in Ruby language.
|
57
|
+
Usage:
|
58
|
+
ppr = Ppr::Preprocessor.new(<configuration options if any>) ;
|
59
|
+
ppr.preprocess(<input stream to preprocess>, <output stream where to write the preprocessing result>)
|
60
|
+
email:
|
61
|
+
- lovic@ariake-nct.ac.jp
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".gitignore"
|
67
|
+
- ".travis.yml"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/ppr.rb
|
75
|
+
- lib/ppr/bar.inc
|
76
|
+
- lib/ppr/foo.inc
|
77
|
+
- lib/ppr/keyword_searcher.rb
|
78
|
+
- lib/ppr/ppr_core.rb
|
79
|
+
- lib/ppr/safer_generator.rb
|
80
|
+
- lib/ppr/test_keyword_searcher.rb
|
81
|
+
- lib/ppr/test_ppr.inc
|
82
|
+
- lib/ppr/test_ppr.rb
|
83
|
+
- lib/ppr/test_ppr.txt
|
84
|
+
- lib/ppr/test_ppr2.txt
|
85
|
+
- lib/ppr/test_ppr_exp.txt
|
86
|
+
- lib/ppr/test_safer_generator.rb
|
87
|
+
- lib/ppr/version.rb
|
88
|
+
- ppr.gemspec
|
89
|
+
homepage: https://github.com/civol
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.8
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: 'Preprocessor in Ruby: text preprocessor where macros are specified in Ruby
|
113
|
+
language.'
|
114
|
+
test_files: []
|