tenderlove-frex 1.0.1.20090313144615
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.
- data/CHANGELOG.rdoc +7 -0
- data/DOCUMENTATION.en.rdoc +215 -0
- data/DOCUMENTATION.ja.rdoc +205 -0
- data/Manifest.txt +38 -0
- data/README.ja +73 -0
- data/README.rdoc +39 -0
- data/Rakefile +27 -0
- data/bin/frex +18 -0
- data/frex.gemspec +37 -0
- data/lib/frex.rb +3 -0
- data/lib/frex/generator.rb +526 -0
- data/lib/frex/info.rb +16 -0
- data/lib/frex/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 +27 -0
- metadata +105 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
#!C:/Program Files/ruby-1.8/bin/ruby
|
2
|
+
#
|
3
|
+
# rex
|
4
|
+
#
|
5
|
+
# Copyright (c) 2005 ARIMA Yasuhiro <arima.yasuhiro@nifty.com>
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute/modify this program under the terms of
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
10
|
+
# For details of LGPL, see the file "COPYING".
|
11
|
+
#
|
12
|
+
|
13
|
+
## ---------------------------------------------------------------------
|
14
|
+
|
15
|
+
REX_OPTIONS = <<-EOT
|
16
|
+
|
17
|
+
o -o --output-file <outfile> file name of output [<filename>.rb]
|
18
|
+
o -s --stub - append stub code for debug
|
19
|
+
o -i --ignorecase - ignore char case
|
20
|
+
o -C --check-only - syntax check only
|
21
|
+
o - --independent - independent mode
|
22
|
+
o -d --debug - print debug information
|
23
|
+
o -h --help - print this message and quit
|
24
|
+
o - --version - print version and quit
|
25
|
+
o - --copyright - print copyright and quit
|
26
|
+
|
27
|
+
EOT
|
28
|
+
|
29
|
+
## ---------------------------------------------------------------------
|
30
|
+
|
31
|
+
require 'getoptlong'
|
32
|
+
require 'rex/generator'
|
33
|
+
require 'rex/info'
|
34
|
+
|
35
|
+
## ---------------------------------------------------------------------
|
36
|
+
|
37
|
+
=begin
|
38
|
+
class Rex
|
39
|
+
def initialize
|
40
|
+
end
|
41
|
+
end
|
42
|
+
=end
|
43
|
+
|
44
|
+
def main
|
45
|
+
$cmd = File.basename($0, ".rb")
|
46
|
+
opt = get_options
|
47
|
+
filename = ARGV[0]
|
48
|
+
|
49
|
+
rex = Rex::Generator.new(opt)
|
50
|
+
begin
|
51
|
+
rex.grammar_file = filename
|
52
|
+
rex.read_grammar
|
53
|
+
rex.parse
|
54
|
+
if opt['--check-only']
|
55
|
+
$stderr.puts "syntax ok"
|
56
|
+
return 0
|
57
|
+
end
|
58
|
+
rex.write_scanner
|
59
|
+
|
60
|
+
rescue Rex::ParseError, Errno::ENOENT
|
61
|
+
msg = $!.to_s
|
62
|
+
unless /\A\d/ === msg
|
63
|
+
msg[0,0] = ' '
|
64
|
+
end
|
65
|
+
$stderr.puts "#{$cmd}:#{rex.grammar_file}:#{rex.lineno}:#{msg}"
|
66
|
+
return 1
|
67
|
+
|
68
|
+
end
|
69
|
+
return 0
|
70
|
+
end
|
71
|
+
|
72
|
+
## ---------------------------------------------------------------------
|
73
|
+
def get_options
|
74
|
+
tmp = REX_OPTIONS.collect do |line|
|
75
|
+
next if /\A\s*\z/ === line
|
76
|
+
disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5)
|
77
|
+
a = []
|
78
|
+
a.push lopt unless lopt == '-'
|
79
|
+
a.push sopt unless sopt == '-'
|
80
|
+
a.push takearg == '-' ?
|
81
|
+
GetoptLong::NO_ARGUMENT : GetoptLong::REQUIRED_ARGUMENT
|
82
|
+
a
|
83
|
+
end
|
84
|
+
getopt = GetoptLong.new(*tmp.compact)
|
85
|
+
getopt.quiet = true
|
86
|
+
|
87
|
+
opt = {}
|
88
|
+
begin
|
89
|
+
getopt.each do |name, arg|
|
90
|
+
raise GetoptLong::InvalidOption,
|
91
|
+
"#{$cmd}: #{name} given twice" if opt.key? name
|
92
|
+
opt[name] = arg.empty? ? true : arg
|
93
|
+
end
|
94
|
+
rescue GetoptLong::AmbigousOption, GetoptLong::InvalidOption,
|
95
|
+
GetoptLong::MissingArgument, GetoptLong::NeedlessArgument
|
96
|
+
usage 1, $!.message
|
97
|
+
end
|
98
|
+
|
99
|
+
usage if opt['--help']
|
100
|
+
|
101
|
+
if opt['--version']
|
102
|
+
puts "#{$cmd} version #{Rex::Version}"
|
103
|
+
exit 0
|
104
|
+
end
|
105
|
+
if opt['--copyright']
|
106
|
+
puts "#{$cmd} version #{Rex::Version}"
|
107
|
+
puts "#{Rex::Copyright} <#{Rex::Mailto}>"
|
108
|
+
exit 0
|
109
|
+
end
|
110
|
+
|
111
|
+
usage(1, 'no grammar file given') if ARGV.empty?
|
112
|
+
usage(1, 'too many grammar files given') if ARGV.size > 1
|
113
|
+
|
114
|
+
opt
|
115
|
+
end
|
116
|
+
|
117
|
+
## ---------------------------------------------------------------------
|
118
|
+
|
119
|
+
def usage(status=0, msg=nil )
|
120
|
+
f = (status == 0 ? $stdout : $stderr)
|
121
|
+
f.puts "#{$cmd}: #{msg}" if msg
|
122
|
+
f.print <<-EOT
|
123
|
+
Usage: #{$cmd} [options] <grammar file>
|
124
|
+
Options:
|
125
|
+
EOT
|
126
|
+
|
127
|
+
REX_OPTIONS.each do |line|
|
128
|
+
next if line.strip.empty?
|
129
|
+
if /\A\s*\z/ === line
|
130
|
+
f.puts
|
131
|
+
next
|
132
|
+
end
|
133
|
+
|
134
|
+
disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5)
|
135
|
+
if disp == 'o'
|
136
|
+
sopt = nil if sopt == '-'
|
137
|
+
lopt = nil if lopt == '-'
|
138
|
+
opt = [sopt, lopt].compact.join(',')
|
139
|
+
|
140
|
+
takearg = nil if takearg == '-'
|
141
|
+
opt = [opt, takearg].compact.join(' ')
|
142
|
+
|
143
|
+
f.printf "%-27s %s\n", opt, doc
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
exit status
|
148
|
+
end
|
149
|
+
|
150
|
+
## ---------------------------------------------------------------------
|
151
|
+
|
152
|
+
main
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
#
|
3
|
+
# rex
|
4
|
+
#
|
5
|
+
# Copyright (c) 2005-2006 ARIMA Yasuhiro <arima.yasuhiro@nifty.com>
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute/modify this program under the terms of
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
10
|
+
# For details of LGPL, see the file "COPYING".
|
11
|
+
#
|
12
|
+
|
13
|
+
## ---------------------------------------------------------------------
|
14
|
+
|
15
|
+
REX_OPTIONS = <<-EOT
|
16
|
+
|
17
|
+
o -o --output-file <outfile> file name of output [<filename>.rb]
|
18
|
+
o -s --stub - append stub code for debug
|
19
|
+
o -i --ignorecase - ignore char case
|
20
|
+
o -C --check-only - syntax check only
|
21
|
+
o - --independent - independent mode
|
22
|
+
o -d --debug - print debug information
|
23
|
+
o -h --help - print this message and quit
|
24
|
+
o - --version - print version and quit
|
25
|
+
o - --copyright - print copyright and quit
|
26
|
+
|
27
|
+
EOT
|
28
|
+
|
29
|
+
## ---------------------------------------------------------------------
|
30
|
+
|
31
|
+
require 'getoptlong'
|
32
|
+
require 'rex/generator'
|
33
|
+
require 'rex/info'
|
34
|
+
|
35
|
+
## ---------------------------------------------------------------------
|
36
|
+
|
37
|
+
class RexRunner
|
38
|
+
def run
|
39
|
+
@status = 1
|
40
|
+
usage 'no grammar file given' if ARGV.empty?
|
41
|
+
usage 'too many grammar files given' if ARGV.size > 1
|
42
|
+
filename = ARGV[0]
|
43
|
+
|
44
|
+
rex = Rex::Generator.new(@opt)
|
45
|
+
begin
|
46
|
+
rex.grammar_file = filename
|
47
|
+
rex.read_grammar
|
48
|
+
rex.parse
|
49
|
+
if @opt['--check-only']
|
50
|
+
$stderr.puts "syntax ok"
|
51
|
+
return 0
|
52
|
+
end
|
53
|
+
rex.write_scanner
|
54
|
+
@status = 0
|
55
|
+
|
56
|
+
rescue Rex::ParseError, Errno::ENOENT
|
57
|
+
msg = $!.to_s
|
58
|
+
unless /\A\d/ === msg
|
59
|
+
msg[0,0] = ' '
|
60
|
+
end
|
61
|
+
$stderr.puts "#{@cmd}:#{rex.grammar_file}:#{rex.lineno}:#{msg}"
|
62
|
+
|
63
|
+
ensure
|
64
|
+
exit @status
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def initialize
|
70
|
+
@status = 2
|
71
|
+
@cmd = File.basename($0, ".rb")
|
72
|
+
tmp = REX_OPTIONS.collect do |line|
|
73
|
+
next if /\A\s*\z/ === line
|
74
|
+
disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5)
|
75
|
+
a = []
|
76
|
+
a.push lopt unless lopt == '-'
|
77
|
+
a.push sopt unless sopt == '-'
|
78
|
+
a.push takearg == '-' ?
|
79
|
+
GetoptLong::NO_ARGUMENT : GetoptLong::REQUIRED_ARGUMENT
|
80
|
+
a
|
81
|
+
end
|
82
|
+
getopt = GetoptLong.new(*tmp.compact)
|
83
|
+
getopt.quiet = true
|
84
|
+
|
85
|
+
@opt = {}
|
86
|
+
begin
|
87
|
+
getopt.each do |name, arg|
|
88
|
+
raise GetoptLong::InvalidOption,
|
89
|
+
"#{@cmd}: #{name} given twice" if @opt.key? name
|
90
|
+
@opt[name] = arg.empty? ? true : arg
|
91
|
+
end
|
92
|
+
rescue GetoptLong::AmbigousOption, GetoptLong::InvalidOption,
|
93
|
+
GetoptLong::MissingArgument, GetoptLong::NeedlessArgument
|
94
|
+
usage $!.message
|
95
|
+
end
|
96
|
+
|
97
|
+
usage if @opt['--help']
|
98
|
+
|
99
|
+
if @opt['--version']
|
100
|
+
puts "#{@cmd} version #{Rex::Version}"
|
101
|
+
exit 0
|
102
|
+
end
|
103
|
+
if @opt['--copyright']
|
104
|
+
puts "#{@cmd} version #{Rex::Version}"
|
105
|
+
puts "#{Rex::Copyright} <#{Rex::Mailto}>"
|
106
|
+
exit 0
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def usage( msg=nil )
|
111
|
+
f = $stderr
|
112
|
+
f.puts "#{@cmd}: #{msg}" if msg
|
113
|
+
f.print <<-EOT
|
114
|
+
Usage: #{@cmd} [options] <grammar file>
|
115
|
+
Options:
|
116
|
+
EOT
|
117
|
+
|
118
|
+
REX_OPTIONS.each do |line|
|
119
|
+
next if line.strip.empty?
|
120
|
+
if /\A\s*\z/ === line
|
121
|
+
f.puts
|
122
|
+
next
|
123
|
+
end
|
124
|
+
|
125
|
+
disp, sopt, lopt, takearg, doc = line.strip.split(/\s+/, 5)
|
126
|
+
if disp == 'o'
|
127
|
+
sopt = nil if sopt == '-'
|
128
|
+
lopt = nil if lopt == '-'
|
129
|
+
opt = [sopt, lopt].compact.join(',')
|
130
|
+
|
131
|
+
takearg = nil if takearg == '-'
|
132
|
+
opt = [opt, takearg].compact.join(' ')
|
133
|
+
|
134
|
+
f.printf "%-27s %s\n", opt, doc
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
exit @status
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
RexRunner.new.run
|
143
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'frex'
|
4
|
+
|
5
|
+
class TestGenerator < Test::Unit::TestCase
|
6
|
+
def test_header_is_written_after_module
|
7
|
+
file = File.join(Dir::tmpdir, 'out.rb')
|
8
|
+
rex = Frex::Generator.new(
|
9
|
+
"--independent" => true,
|
10
|
+
"--output-file" => file
|
11
|
+
)
|
12
|
+
rex.grammar_file = (File.join(File.dirname(__FILE__), 'assets', 'test.rex'))
|
13
|
+
rex.read_grammar
|
14
|
+
rex.parse
|
15
|
+
rex.write_scanner
|
16
|
+
|
17
|
+
comments = []
|
18
|
+
File.open(file, 'rb') { |f|
|
19
|
+
f.each_line do |line|
|
20
|
+
comments << line.chomp if line =~ /^#/
|
21
|
+
end
|
22
|
+
}
|
23
|
+
assert_match 'DO NOT MODIFY', comments.join
|
24
|
+
assert_equal '#--', comments.first
|
25
|
+
assert_equal '#++', comments.last
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tenderlove-frex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1.20090313144615
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Patterson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-13 00:00:00 -07:00
|
13
|
+
default_executable: frex
|
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.9.0
|
24
|
+
version:
|
25
|
+
description: Frex is a fork of Rex. Rex is a lexical scanner generator. It is written in Ruby itself, and generates Ruby program. It is designed for use with Racc.
|
26
|
+
email:
|
27
|
+
- aaronp@rubyforge.org
|
28
|
+
executables:
|
29
|
+
- frex
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- Manifest.txt
|
34
|
+
- CHANGELOG.rdoc
|
35
|
+
- DOCUMENTATION.en.rdoc
|
36
|
+
- DOCUMENTATION.ja.rdoc
|
37
|
+
- README.rdoc
|
38
|
+
files:
|
39
|
+
- CHANGELOG.rdoc
|
40
|
+
- DOCUMENTATION.en.rdoc
|
41
|
+
- DOCUMENTATION.ja.rdoc
|
42
|
+
- Manifest.txt
|
43
|
+
- README.ja
|
44
|
+
- README.rdoc
|
45
|
+
- Rakefile
|
46
|
+
- bin/frex
|
47
|
+
- frex.gemspec
|
48
|
+
- lib/frex.rb
|
49
|
+
- lib/frex/generator.rb
|
50
|
+
- lib/frex/info.rb
|
51
|
+
- lib/frex/rexcmd.rb
|
52
|
+
- sample/a.cmd
|
53
|
+
- sample/b.cmd
|
54
|
+
- sample/c.cmd
|
55
|
+
- sample/calc3.racc
|
56
|
+
- sample/calc3.rex
|
57
|
+
- sample/calc3.rex.rb
|
58
|
+
- sample/calc3.tab.rb
|
59
|
+
- sample/error1.rex
|
60
|
+
- sample/error2.rex
|
61
|
+
- sample/sample.html
|
62
|
+
- sample/sample.rex
|
63
|
+
- sample/sample.rex.rb
|
64
|
+
- sample/sample.xhtml
|
65
|
+
- sample/sample1.c
|
66
|
+
- sample/sample1.rex
|
67
|
+
- sample/sample2.bas
|
68
|
+
- sample/sample2.rex
|
69
|
+
- sample/simple.html
|
70
|
+
- sample/simple.xhtml
|
71
|
+
- sample/xhtmlparser.racc
|
72
|
+
- sample/xhtmlparser.rex
|
73
|
+
- test/assets/test.rex
|
74
|
+
- test/rex-20060125.rb
|
75
|
+
- test/rex-20060511.rb
|
76
|
+
- test/test_generator.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/aaronp/frex/tree/master
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --main
|
82
|
+
- README.rdoc
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
version:
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: frex
|
100
|
+
rubygems_version: 1.2.0
|
101
|
+
signing_key:
|
102
|
+
specification_version: 2
|
103
|
+
summary: Frex is a fork of Rex
|
104
|
+
test_files:
|
105
|
+
- test/test_generator.rb
|