rex 0.0.4 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +7 -0
- data/DOCUMENTATION.en.rdoc +215 -0
- data/DOCUMENTATION.ja.rdoc +205 -0
- data/Manifest.txt +37 -0
- data/README.ja +73 -0
- data/README.rdoc +53 -0
- data/Rakefile +28 -0
- data/bin/rex +18 -0
- data/lib/rex.rb +3 -23
- data/lib/rex/generator.rb +523 -0
- data/lib/rex/info.rb +16 -0
- data/lib/rex/rexcmd.rb +136 -0
- data/sample/a.cmd +1 -0
- data/sample/b.cmd +1 -0
- data/sample/c.cmd +4 -0
- data/sample/calc3.racc +47 -0
- data/sample/calc3.rex +15 -0
- data/sample/calc3.rex.rb +94 -0
- data/sample/calc3.tab.rb +188 -0
- data/sample/error1.rex +15 -0
- data/sample/error2.rex +15 -0
- data/sample/sample.html +32 -0
- data/sample/sample.rex +15 -0
- data/sample/sample.rex.rb +100 -0
- data/sample/sample.xhtml +32 -0
- data/sample/sample1.c +9 -0
- data/sample/sample1.rex +43 -0
- data/sample/sample2.bas +4 -0
- data/sample/sample2.rex +33 -0
- data/sample/simple.html +7 -0
- data/sample/simple.xhtml +10 -0
- data/sample/xhtmlparser.racc +66 -0
- data/sample/xhtmlparser.rex +72 -0
- data/test/assets/test.rex +12 -0
- data/test/rex-20060125.rb +152 -0
- data/test/rex-20060511.rb +143 -0
- data/test/test_generator.rb +184 -0
- metadata +74 -57
- data/README +0 -50
- data/lib/rex/array.rb +0 -13
- data/lib/rex/kernel.rb +0 -11
- data/lib/rex/modules/boolean.rb +0 -14
- data/lib/rex/modules/caller_name.rb +0 -15
- data/lib/rex/modules/ordinal.rb +0 -35
- data/lib/rex/modules/propercase.rb +0 -15
- data/lib/rex/modules/roman.rb +0 -41
- data/lib/rex/modules/scrub.rb +0 -66
- data/lib/rex/modules/stacktrace.rb +0 -31
- data/lib/rex/modules/swap.rb +0 -13
- data/lib/rex/modules/to_proc.rb +0 -13
- data/lib/rex/modules/tuple.rb +0 -14
- data/lib/rex/modules/wrap.rb +0 -15
- data/lib/rex/numeric.rb +0 -19
- data/lib/rex/string.rb +0 -21
- data/lib/rex/symbol.rb +0 -13
- data/test/boolean.rb +0 -64
- data/test/caller_name.rb +0 -26
- data/test/ordinal.rb +0 -609
- data/test/propercase.rb +0 -40
- data/test/roman.rb +0 -335
- data/test/scrub.rb +0 -27
- data/test/stacktrace.rb +0 -24
- data/test/swap.rb +0 -44
- data/test/to_proc.rb +0 -24
- data/test/tuple.rb +0 -26
- data/test/wrap.rb +0 -44
metadata
CHANGED
@@ -1,62 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Aaron Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-06-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.12.2
|
24
|
+
version:
|
25
|
+
description: |-
|
26
|
+
Rex is a lexical scanner generator.
|
27
|
+
It is written in Ruby itself, and generates Ruby program.
|
28
|
+
It is designed for use with Racc.
|
29
|
+
email:
|
30
|
+
- aaronp@rubyforge.org
|
31
|
+
executables:
|
32
|
+
- rex
|
20
33
|
extensions: []
|
21
34
|
|
22
35
|
extra_rdoc_files:
|
23
|
-
-
|
36
|
+
- Manifest.txt
|
37
|
+
- CHANGELOG.rdoc
|
38
|
+
- DOCUMENTATION.en.rdoc
|
39
|
+
- DOCUMENTATION.ja.rdoc
|
40
|
+
- README.rdoc
|
24
41
|
files:
|
42
|
+
- CHANGELOG.rdoc
|
43
|
+
- DOCUMENTATION.en.rdoc
|
44
|
+
- DOCUMENTATION.ja.rdoc
|
45
|
+
- Manifest.txt
|
46
|
+
- README.ja
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- bin/rex
|
25
50
|
- lib/rex.rb
|
26
|
-
- lib/rex/
|
27
|
-
- lib/rex/
|
28
|
-
- lib/rex/
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
- test/
|
51
|
-
- test/
|
52
|
-
- test/
|
53
|
-
- test/
|
54
|
-
- README
|
51
|
+
- lib/rex/generator.rb
|
52
|
+
- lib/rex/info.rb
|
53
|
+
- lib/rex/rexcmd.rb
|
54
|
+
- sample/a.cmd
|
55
|
+
- sample/b.cmd
|
56
|
+
- sample/c.cmd
|
57
|
+
- sample/calc3.racc
|
58
|
+
- sample/calc3.rex
|
59
|
+
- sample/calc3.rex.rb
|
60
|
+
- sample/calc3.tab.rb
|
61
|
+
- sample/error1.rex
|
62
|
+
- sample/error2.rex
|
63
|
+
- sample/sample.html
|
64
|
+
- sample/sample.rex
|
65
|
+
- sample/sample.rex.rb
|
66
|
+
- sample/sample.xhtml
|
67
|
+
- sample/sample1.c
|
68
|
+
- sample/sample1.rex
|
69
|
+
- sample/sample2.bas
|
70
|
+
- sample/sample2.rex
|
71
|
+
- sample/simple.html
|
72
|
+
- sample/simple.xhtml
|
73
|
+
- sample/xhtmlparser.racc
|
74
|
+
- sample/xhtmlparser.rex
|
75
|
+
- test/assets/test.rex
|
76
|
+
- test/rex-20060125.rb
|
77
|
+
- test/rex-20060511.rb
|
78
|
+
- test/test_generator.rb
|
55
79
|
has_rdoc: true
|
56
|
-
homepage: http://
|
57
|
-
|
58
|
-
rdoc_options: []
|
80
|
+
homepage: http://rex.rubyforge.org
|
81
|
+
licenses: []
|
59
82
|
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- --main
|
86
|
+
- README.rdoc
|
60
87
|
require_paths:
|
61
88
|
- lib
|
62
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -73,20 +100,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
100
|
version:
|
74
101
|
requirements: []
|
75
102
|
|
76
|
-
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
103
|
+
rubyforge_project: ruby-rex
|
104
|
+
rubygems_version: 1.3.3
|
78
105
|
signing_key:
|
79
|
-
specification_version:
|
80
|
-
summary:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Rex is a lexical scanner generator
|
81
108
|
test_files:
|
82
|
-
- test/
|
83
|
-
- test/caller_name.rb
|
84
|
-
- test/ordinal.rb
|
85
|
-
- test/propercase.rb
|
86
|
-
- test/roman.rb
|
87
|
-
- test/scrub.rb
|
88
|
-
- test/stacktrace.rb
|
89
|
-
- test/swap.rb
|
90
|
-
- test/to_proc.rb
|
91
|
-
- test/tuple.rb
|
92
|
-
- test/wrap.rb
|
109
|
+
- test/test_generator.rb
|
data/README
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
== What
|
2
|
-
Ruby Extension Library version 0.0.4
|
3
|
-
|
4
|
-
This is a collection of Ruby class monkeypatches. Some of these are by me and
|
5
|
-
some have been swiped from other places. I have no shame.
|
6
|
-
|
7
|
-
== How
|
8
|
-
require 'rubygems'
|
9
|
-
require 'rex'
|
10
|
-
|
11
|
-
Stuff you get:
|
12
|
-
Array#swap!(a, b)
|
13
|
-
File#random_line(separator="#{$/}", seed=nil)
|
14
|
-
Integer#to_ordinal
|
15
|
-
Integer#from_ordinal(ordinal)
|
16
|
-
Integer#to_roman
|
17
|
-
Integer#from_roman(roman)
|
18
|
-
Kernel#boolean?
|
19
|
-
Kernel#caller_name
|
20
|
-
Kernel#stack_trace(msg=nil)
|
21
|
-
Kernel#Tuple(*ary)
|
22
|
-
String#propercase
|
23
|
-
String#scrub!(allowed=BASIC_MARKUP)
|
24
|
-
String#wrap(columns=78)
|
25
|
-
Symbol#to_proc
|
26
|
-
|
27
|
-
You can run the example programs in the examples directory to see what the
|
28
|
-
above methods do. You can run the example programs from anywhere, e.g.:
|
29
|
-
|
30
|
-
ruby ~/src/projects/rex/examples/stacktrace.rb
|
31
|
-
|
32
|
-
== Install
|
33
|
-
To construct a Ruby gem, just type:
|
34
|
-
|
35
|
-
rake gem
|
36
|
-
|
37
|
-
To install it, type:
|
38
|
-
|
39
|
-
sudo gem install pkg/rex-0.0.4.gem
|
40
|
-
|
41
|
-
== Notes
|
42
|
-
I haven't tested this code with YARV, so YMMV.
|
43
|
-
|
44
|
-
Symbol#to_proc comes from the blog post:
|
45
|
-
http://weblog.raganwald.com/2008/02/1100inject.html
|
46
|
-
|
47
|
-
== Contribute
|
48
|
-
The source is availble at github: git://github.com/yesmar/rex.git. Feel free
|
49
|
-
to clone it and implement your own awesome ideas. You can also send your
|
50
|
-
patches by email to yesmar[at]speakeasy[dot]net.
|
data/lib/rex/array.rb
DELETED
data/lib/rex/kernel.rb
DELETED
data/lib/rex/modules/boolean.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# boolean.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Kernel
|
7
|
-
def boolean?
|
8
|
-
raise ArgumentError, 'nil self' if self.nil?
|
9
|
-
|
10
|
-
self.class == TrueClass || self.class == FalseClass
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# caller_name.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Kernel
|
7
|
-
def caller_name
|
8
|
-
k = caller[0].split(%r{:[\d]*:in})
|
9
|
-
return k[0] if !k.nil? && !k.empty?
|
10
|
-
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
data/lib/rex/modules/ordinal.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# ordinal.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Ordinal
|
7
|
-
# convert number to ordinal
|
8
|
-
def to_ordinal
|
9
|
-
cardinal = self.to_i.abs
|
10
|
-
if (10...20).include?(cardinal) then
|
11
|
-
cardinal.to_s << 'th'
|
12
|
-
else
|
13
|
-
cardinal.to_s << %w{th st nd rd th th th th th th}[cardinal % 10]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# convert ordinal to number
|
18
|
-
def Integer.from_ordinal(ordinal)
|
19
|
-
raise ArgumentError, 'nil ordinal' if ordinal.nil?
|
20
|
-
raise ArgumentError, 'invalid ordinal class' if ordinal.class != String
|
21
|
-
raise ArgumentError, 'empty ordinal' if ordinal.empty?
|
22
|
-
raise ArgumentError, 'not an ordinal' if ordinal.length < 3
|
23
|
-
|
24
|
-
suffix = ordinal[-2,2]
|
25
|
-
if suffix == 'st' || suffix == 'nd' || suffix == 'rd' || suffix == 'th'
|
26
|
-
value = ordinal[0,ordinal.length-2]
|
27
|
-
else
|
28
|
-
raise 'not an ordinal'
|
29
|
-
end
|
30
|
-
|
31
|
-
value.to_i
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# propercase.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module ProperCase
|
7
|
-
# convert string to Proper Case
|
8
|
-
def propercase
|
9
|
-
ary = self.split(' ')
|
10
|
-
ary.each { |e| e.capitalize! }
|
11
|
-
ary.join(' ')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
data/lib/rex/modules/roman.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# roman.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Roman
|
7
|
-
ROMAN_NUMERALS = [ ['M', 1000], ['CM', 900], ['D', 500],
|
8
|
-
['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40],
|
9
|
-
['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1] ]
|
10
|
-
|
11
|
-
# convert Integer to Roman numeral
|
12
|
-
def to_roman
|
13
|
-
remainder = self
|
14
|
-
roman = ''
|
15
|
-
for sym,sum in ROMAN_NUMERALS
|
16
|
-
while remainder >= sum
|
17
|
-
remainder -= sum
|
18
|
-
roman << sym
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
roman
|
23
|
-
end
|
24
|
-
|
25
|
-
# convert Roman numeral to Integer
|
26
|
-
def Integer.from_roman(roman)
|
27
|
-
str = roman.upcase
|
28
|
-
sum = 0
|
29
|
-
for entry in ROMAN_NUMERALS
|
30
|
-
sym,num = entry[0], entry[1]
|
31
|
-
while sym == str[0, sym.length]
|
32
|
-
sum += num
|
33
|
-
str.slice!(0, sym.length)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
sum
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
data/lib/rex/modules/scrub.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# scrub.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Scrub
|
7
|
-
# dictionary of allowable HTML tags and attributes
|
8
|
-
BASIC_MARKUP = {
|
9
|
-
'a' => ['href', 'title'],
|
10
|
-
'img' => ['src', 'alt', 'title'],
|
11
|
-
'br' => [],
|
12
|
-
'i' => nil,
|
13
|
-
'u' => nil,
|
14
|
-
'b' => nil,
|
15
|
-
'pre' => nil,
|
16
|
-
'kbd' => nil,
|
17
|
-
'code' => ['lang'],
|
18
|
-
'cite' => nil,
|
19
|
-
'strong' => nil,
|
20
|
-
'em' => nil,
|
21
|
-
'ins' => nil,
|
22
|
-
'sup' => nil,
|
23
|
-
'del' => nil,
|
24
|
-
'table' => nil,
|
25
|
-
'tr' => nil,
|
26
|
-
'td' => nil,
|
27
|
-
'th' => nil,
|
28
|
-
'ol' => nil,
|
29
|
-
'ul' => nil,
|
30
|
-
'li' => nil,
|
31
|
-
'p' => nil,
|
32
|
-
'h1' => nil,
|
33
|
-
'h2' => nil,
|
34
|
-
'h3' => nil,
|
35
|
-
'h4' => nil,
|
36
|
-
'h5' => nil,
|
37
|
-
'h6' => nil,
|
38
|
-
'blockquote' => ['cite']
|
39
|
-
}
|
40
|
-
|
41
|
-
# TODO: add option to replace scrubbed text with a user-defined tag
|
42
|
-
def scrub!(allowed=BASIC_MARKUP)
|
43
|
-
gsub!(/<(\/*)(\w+)([^>]*)>/) do
|
44
|
-
raw = $~
|
45
|
-
tag = raw[2].downcase
|
46
|
-
if allowed.has_key? tag
|
47
|
-
pcs = [tag]
|
48
|
-
allowed[tag].each do |prop|
|
49
|
-
['"', "'", ''].each do |q|
|
50
|
-
q2 = (q != '' ? q : '\s')
|
51
|
-
if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
|
52
|
-
pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
|
53
|
-
break
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end if allowed[tag]
|
57
|
-
"<#{raw[1]}#{pcs.join ' '}>"
|
58
|
-
else
|
59
|
-
''
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# stacktrace.rb
|
4
|
-
# yesmar@speakeasy.net
|
5
|
-
|
6
|
-
module Kernel
|
7
|
-
SPONSOR = 'yesmar'
|
8
|
-
|
9
|
-
def stacktrace(msg=nil)
|
10
|
-
raise ArgumentError, 'invalid msg class' if msg.class != String if !msg.nil?
|
11
|
-
|
12
|
-
program = File.basename(caller_name) || 'unknown'
|
13
|
-
st = []
|
14
|
-
|
15
|
-
st << "#{msg} " if !msg.nil? && !msg.empty?
|
16
|
-
st << 'Stack Trace:'
|
17
|
-
|
18
|
-
i = 1
|
19
|
-
caller.each do |c|
|
20
|
-
st << " #{c}"
|
21
|
-
i += 1
|
22
|
-
if i == caller.size-1
|
23
|
-
st << " #{program}:this stack trace is brought to you by #{SPONSOR}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
st
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|