genmachine 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/genmachine +13 -25
- data/genmachine.gemspec +3 -2
- data/lib/VERSION +1 -0
- data/lib/genmachine.rb +3 -0
- data/lib/genmachine/generator.rb +7 -4
- data/lib/genmachine/generators/ruby.rb +3 -2
- data/lib/genmachine/spec_parser.rb +6 -3
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bin/genmachine
CHANGED
@@ -9,31 +9,18 @@ languages = generators.keys
|
|
9
9
|
|
10
10
|
options = {}
|
11
11
|
opts = OptionParser.new do |opts|
|
12
|
-
opts.version =
|
12
|
+
opts.version = GenMachine.version
|
13
13
|
opts.banner = BANNER
|
14
|
-
opts.on('-
|
15
|
-
|
16
|
-
"(default STATE_TABLE_FILE)")
|
17
|
-
options[:classname] = v
|
18
|
-
end
|
14
|
+
opts.on('-d', '--[no-]debug', "Verbose debug mode.") {|v| options[:debug] = v}
|
15
|
+
opts.on('-c', '--classname NAME', "Class/module/function name for generated library code "+
|
16
|
+
"(default STATE_TABLE_FILE)") {|v| options[:classname] = v}
|
19
17
|
opts.on('-l', '--language LANGUAGE',
|
20
18
|
"Language to generate code for- currently one of [#{languages.join(',')}] " +
|
21
|
-
"(default #{languages.first})")
|
22
|
-
|
23
|
-
|
24
|
-
opts.on('-
|
25
|
-
|
26
|
-
"(default STATE_TABLE_FILE.gmtest if it exists)") do |v|
|
27
|
-
options[:test_file] = v
|
28
|
-
end
|
29
|
-
opts.on('-e', '--[no-]executable',
|
30
|
-
"Generate an executable parser (default true)") do |v|
|
31
|
-
options[:executable] = v
|
32
|
-
end
|
33
|
-
opts.on('-o', '--output-dir DIR',
|
34
|
-
"Output directory for generated file(s) (default ./)") do |v|
|
35
|
-
options[:output_dir] = v
|
36
|
-
end
|
19
|
+
"(default #{languages.first})"){|v|options[:language]=v.to_underscored}
|
20
|
+
opts.on('-t', '--test-with FILE', "Try parsing the specified file after generating the parser "+
|
21
|
+
"(default STATE_TABLE_FILE.gmtest if it exists)"){|v|options[:test_file]=v}
|
22
|
+
opts.on('-e','--[no-]executable',"Generate an executable parser (default true)"){|v|options[:executable]=v}
|
23
|
+
opts.on('-o','--output-dir DIR',"Output directory for generated file(s) (default ./)"){|v|options[:output_dir]=v}
|
37
24
|
end
|
38
25
|
|
39
26
|
files = opts.parse(ARGV)
|
@@ -44,11 +31,12 @@ end
|
|
44
31
|
|
45
32
|
file_base = files[0].chomp(File.extname(files[0]))
|
46
33
|
name_base = File.basename(file_base)
|
47
|
-
options[:
|
34
|
+
options[:debug] = false if options[:debug].nil?
|
35
|
+
options[:executable] = true if options[:executable].nil?
|
48
36
|
options[:language] ||= languages.first
|
49
37
|
options[:classname] ||= name_base.capitalize + 'Parser'
|
50
38
|
options[:test_file] ||= files[0] + '.gmtest'
|
51
|
-
options[:
|
39
|
+
options[:output_dir] ||= './'
|
52
40
|
options[:class_fname] = options[:classname].to_underscored + '.rb'
|
53
41
|
options[:exe_fname] = name_base.to_underscored
|
54
42
|
|
@@ -57,7 +45,7 @@ unless languages.include? options[:language]
|
|
57
45
|
exit 2
|
58
46
|
end
|
59
47
|
|
60
|
-
spec_parser = GenMachine::SpecParser.new(files)
|
48
|
+
spec_parser = GenMachine::SpecParser.new(files,options)
|
61
49
|
options[:spec_ast] = spec_parser.build
|
62
50
|
gen = generators[options[:language]].new(options)
|
63
51
|
gen.generate_class
|
data/genmachine.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{genmachine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joseph Wecker"]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-16}
|
13
13
|
s.default_executable = %q{genmachine}
|
14
14
|
s.description = %q{Takes a state table where the following are defined: state, input+conditions, accumulate-action, pre-transition-actions, and transition-to. It takes that state table and generates very fast parsers. Similar to Ragel. Currently only outputs pure Ruby.}
|
15
15
|
s.email = %q{joseph.wecker@gmail.com}
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"VERSION",
|
30
30
|
"bin/genmachine",
|
31
31
|
"genmachine.gemspec",
|
32
|
+
"lib/VERSION",
|
32
33
|
"lib/genmachine.rb",
|
33
34
|
"lib/genmachine/char_set.rb",
|
34
35
|
"lib/genmachine/generator.rb",
|
data/lib/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/lib/genmachine.rb
CHANGED
@@ -9,6 +9,7 @@ Dir[File.join(File.dirname(__FILE__),'genmachine','generators','*.rb')].each do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module GenMachine
|
12
|
+
VERSION = File.exist?(File.join(File.dirname(__FILE__),'VERSION')) ? File.read(File.join(File.dirname(__FILE__),'VERSION')) : ""
|
12
13
|
class << self
|
13
14
|
def generators
|
14
15
|
Generators.constants.reduce({}) do |langs,const|
|
@@ -19,5 +20,7 @@ module GenMachine
|
|
19
20
|
langs
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
24
|
+
def version() VERSION end
|
22
25
|
end
|
23
26
|
end
|
data/lib/genmachine/generator.rb
CHANGED
@@ -4,27 +4,30 @@ module GenMachine
|
|
4
4
|
def initialize(opts={})
|
5
5
|
opts ||= {}
|
6
6
|
@spec_ast = opts.delete(:spec_ast)
|
7
|
-
@gen_executable = opts.delete(:executable)
|
7
|
+
@gen_executable = opts.delete(:executable)
|
8
8
|
@classname = opts.delete(:classname) || 'MiscParser'
|
9
9
|
@test_file = opts.delete(:test_file)
|
10
10
|
@output_dir = opts.delete(:output_dir) || './'
|
11
11
|
@class_fname = opts.delete(:class_fname)|| @classname.to_underscored
|
12
12
|
@exe_fname = opts.delete(:exe_fname) || @classname.sub(/parser$/i,'').to_underscored
|
13
|
+
@debug = opts.delete(:debug)
|
14
|
+
@gen_executable = false if @gen_executable.nil?
|
15
|
+
@debug = false if @debug.nil?
|
13
16
|
raise ArgumentError, "Must include the table specification data (:spec_ast)" if @spec_ast.nil?
|
14
17
|
end
|
15
18
|
|
16
19
|
def generate_class
|
17
|
-
puts "TODO: Generate class (#{@classname}): #{@class_fname}"
|
20
|
+
puts "TODO: Generate class (#{@classname}): #{@class_fname}" if @debug
|
18
21
|
end
|
19
22
|
|
20
23
|
def generate_executable
|
21
24
|
return unless @gen_executable
|
22
|
-
puts "TODO: Generate executable: #{@exe_fname}"
|
25
|
+
puts "TODO: Generate executable: #{@exe_fname}" if @debug
|
23
26
|
end
|
24
27
|
|
25
28
|
def run_test
|
26
29
|
return if @test_file.nil?
|
27
|
-
puts "TODO: Run test"
|
30
|
+
puts "TODO: Run test" if @debug
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
@@ -15,14 +15,15 @@ module GenMachine
|
|
15
15
|
|
16
16
|
def generate_class
|
17
17
|
library = ERB.new(IO.read(@template_base+'lib.erb.rb'),nil,'-')
|
18
|
-
f = File.new(@class_fname, 'w+')
|
18
|
+
f = File.new(File.join(@output_dir,@class_fname), 'w+')
|
19
19
|
f.write(library.result(binding))
|
20
20
|
f.close
|
21
21
|
end
|
22
22
|
|
23
23
|
def generate_executable
|
24
|
+
return unless @gen_executable
|
24
25
|
executable = ERB.new(IO.read(@template_base+'executable.erb'),nil,'-')
|
25
|
-
f = File.new(@exe_fname, 'w+')
|
26
|
+
f = File.new(File.join(@output_dir,@exe_fname), 'w+')
|
26
27
|
f.write(executable.result(binding))
|
27
28
|
f.chmod(0755)
|
28
29
|
f.close
|
@@ -3,9 +3,10 @@ module GenMachine
|
|
3
3
|
# it'll eventually be replaced when the real parser is written as a
|
4
4
|
# genmachine table.
|
5
5
|
class SpecParser
|
6
|
-
def initialize(files)
|
6
|
+
def initialize(files,opts)
|
7
7
|
@table = []
|
8
8
|
@files = files
|
9
|
+
@opts = opts
|
9
10
|
end
|
10
11
|
|
11
12
|
def build
|
@@ -58,8 +59,10 @@ module GenMachine
|
|
58
59
|
@table << [c_name, c_args, c_cmds, c_first_state, process_states(c_states)]
|
59
60
|
end
|
60
61
|
end
|
61
|
-
|
62
|
-
|
62
|
+
if @opts[:debug]
|
63
|
+
require 'pp'
|
64
|
+
pp @table
|
65
|
+
end
|
63
66
|
return @table
|
64
67
|
end
|
65
68
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genmachine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joseph Wecker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-16 00:00:00 -07:00
|
19
19
|
default_executable: genmachine
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- VERSION
|
99
99
|
- bin/genmachine
|
100
100
|
- genmachine.gemspec
|
101
|
+
- lib/VERSION
|
101
102
|
- lib/genmachine.rb
|
102
103
|
- lib/genmachine/char_set.rb
|
103
104
|
- lib/genmachine/generator.rb
|