genmachine 0.0.1 → 0.1.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/bin/genmachine CHANGED
@@ -57,9 +57,8 @@ unless languages.include? options[:language]
57
57
  exit 2
58
58
  end
59
59
 
60
- #spec_parser = GenMachine::SpecParser.new(files)
61
- #options[:spec_ast] = spec_parser.build
62
- options[:spec_ast] = []
60
+ spec_parser = GenMachine::SpecParser.new(files)
61
+ options[:spec_ast] = spec_parser.build
63
62
  gen = generators[options[:language]].new(options)
64
63
  gen.generate_class
65
64
  gen.generate_executable
data/genmachine.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{genmachine}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
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"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/genmachine/generators/helpers/general.rb",
34
34
  "lib/genmachine/generators/helpers/ruby.rb",
35
35
  "lib/genmachine/generators/ruby.rb",
36
+ "lib/genmachine/generators/templates/ruby/executable.erb",
36
37
  "lib/genmachine/generators/templates/ruby/lib.erb.rb",
37
38
  "lib/genmachine/spec_parser.rb",
38
39
  "test/helper.rb",
@@ -35,8 +35,8 @@ module GenMachine
35
35
  def include_char(char) include_range(char,char) end
36
36
 
37
37
  def include_range(from, to)
38
- from = from.utf8_chars[0] if from.is_a?(String)
39
- to = to.utf8_chars[0] if to.is_a?(String)
38
+ from = from.to_utf8_char_array[0] if from.is_a?(String)
39
+ to = to.to_utf8_char_array[0] if to.is_a?(String)
40
40
  @include_intervals << [from,to].sort
41
41
  if @include_intervals.length > 1
42
42
  @include_intervals.sort!
@@ -14,24 +14,17 @@ module GenMachine
14
14
  end
15
15
 
16
16
  def generate_class
17
- puts "Generate class (#{@classname}): #{@class_fname}"
18
- #f = File.new(@class_fname, 'w+')
19
- #f.write(@libraries[language].result(binding))
20
- #f.close
17
+ puts "TODO: Generate class (#{@classname}): #{@class_fname}"
21
18
  end
22
19
 
23
20
  def generate_executable
24
21
  return unless @gen_executable
25
- puts "Generate executable: #{@exe_fname}"
26
- #f = File.new(@exe_fname, 'w+')
27
- #f.write(@executables[language].result(binding))
28
- #f.chmod(0755)
29
- #f.close
22
+ puts "TODO: Generate executable: #{@exe_fname}"
30
23
  end
31
24
 
32
25
  def run_test
33
26
  return if @test_file.nil?
34
- puts "Run test"
27
+ puts "TODO: Run test"
35
28
  end
36
29
  end
37
30
  end
@@ -52,7 +52,7 @@ module GenMachine
52
52
  end
53
53
 
54
54
  def rb_transition_commands(st,currstate)
55
- st = st.strip.split(';').map{|s|s.strip}
55
+ st = st.strip.split(';').map(&:strip)
56
56
  out = []
57
57
  add_next = false
58
58
  st.each do |s|
@@ -1,8 +1,32 @@
1
1
  module GenMachine
2
2
  module Generators
3
3
  class RubyGenerator
4
+ require 'erb'
5
+ require 'genmachine/generators/helpers/ruby'
4
6
  include Generator
7
+ include GenMachine::Helpers::Ruby
8
+ include GenMachine::Helpers::General
5
9
  GENMACHINE_TARGET = 'ruby'
10
+
11
+ def initialize(opts)
12
+ @template_base = File.expand_path(File.dirname(__FILE__))+'/templates/ruby/'
13
+ super(opts)
14
+ end
15
+
16
+ def generate_class
17
+ library = ERB.new(IO.read(@template_base+'lib.erb.rb'),nil,'-')
18
+ f = File.new(@class_fname, 'w+')
19
+ f.write(library.result(binding))
20
+ f.close
21
+ end
22
+
23
+ def generate_executable
24
+ executable = ERB.new(IO.read(@template_base+'executable.erb'),nil,'-')
25
+ f = File.new(@exe_fname, 'w+')
26
+ f.write(executable.result(binding))
27
+ f.chmod(0755)
28
+ f.close
29
+ end
6
30
  end
7
31
  end
8
32
  end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # continuation based (if required) or full-file parsing
3
+ require '<%= @classname.to_underscored %>'
4
+ require 'pp'
5
+ pp <%= @classname %>.parse(ARGF.read)
@@ -1,7 +1,7 @@
1
1
  require 'strscan'
2
2
  $KCODE="U"
3
3
 
4
- module <%= classname %>
4
+ module <%= @classname %>
5
5
  def self.parse(str) Parser.new(str).parse end
6
6
  def self.parse_file(fname) Parser.new(IO.read(fname)).parse end
7
7
 
@@ -61,7 +61,7 @@ module <%= classname %>
61
61
  @pos = 1
62
62
  @leading = true
63
63
  @indent = 0
64
- @ast = <%= @table[0][0] %>
64
+ @ast = <%= @spec_ast[0][0] %>
65
65
  return @ast
66
66
  end
67
67
 
@@ -115,7 +115,7 @@ module <%= classname %>
115
115
 
116
116
  def eof?() return @last_c == :eof end
117
117
 
118
- <%- @table.each do |name, args, cmds, first_state, states| -%>
118
+ <%- @spec_ast.each do |name, args, cmds, first_state, states| -%>
119
119
  <%- args << "p=nil" -%>
120
120
  <%- args << "name='#{name}'" -%>
121
121
  def <%= name %>(<%= args.join(',') %>)
@@ -170,6 +170,7 @@ module <%= classname %>
170
170
  <%- end -%>
171
171
  end
172
172
  end
173
+
173
174
  <%- end -%>
174
175
  end
175
176
  end
@@ -6,14 +6,6 @@ module GenMachine
6
6
  def initialize(files)
7
7
  @table = []
8
8
  @files = files
9
- @libraries = {}
10
- @executables = {}
11
- template_base = File.expand_path(File.dirname(__FILE__))+'/templates/'
12
- LANGUAGES.each do |lang|
13
- tbase = template_base + lang.to_s + '/'
14
- @libraries[lang] = ERB.new(IO.read(tbase+'library.erb.rb'),nil,'-')
15
- @executables[lang] = ERB.new(IO.read(tbase+'executable.erb'),nil,'-')
16
- end
17
9
  end
18
10
 
19
11
  def build
@@ -25,14 +17,14 @@ module GenMachine
25
17
  det = line[0..0]
26
18
  if det == '|' or det == ':'
27
19
  re = (det=='|' ? '\|' : det) + '(?: |$)'
28
- cols = line.split(/#{re}/,-1)[1..-1].map{|c| c.strip}
20
+ cols = line.split(/#{re}/,-1)[1..-1].map(&:strip)
29
21
  if det=='|' && cols[0].include?('(')
30
22
  new_fun = true
31
23
  unless c_name.nil?
32
24
  @table << [c_name, c_args, c_cmds, c_first_state, process_states(c_states)]
33
25
  end
34
26
  parts = cols[0].split('(')
35
- c_name = parts.shift.underscore
27
+ c_name = parts.shift.to_underscored
36
28
  c_args = parts.join('(').sub(/\)$/,'').split(',')
37
29
  c_states = []
38
30
  c_cmds = (cols[3]||'').split(';')
@@ -49,7 +41,7 @@ module GenMachine
49
41
  :input => inputs,
50
42
  :cond => conditionals,
51
43
  :acc => cols[2],
52
- :exprs => (cols[3]||'').split(';'),
44
+ :exprs => (cols[3]||'').split(';').map(&:strip),
53
45
  :next => cols[4]}
54
46
  elsif det == ':' && (c_states.size > 0)
55
47
  conditionals, inputs = parse_input(cols[1],c_states[-1][:input])
@@ -57,7 +49,7 @@ module GenMachine
57
49
  c_states[-1][:input] = inputs
58
50
  c_states[-1][:cond] += conditionals
59
51
  c_states[-1][:acc] += cols[2]
60
- c_states[-1][:exprs]+= (cols[3]||'').split(';')
52
+ c_states[-1][:exprs]+= (cols[3]||'').split(';').map(&:strip)
61
53
  c_states[-1][:next] += cols[4]
62
54
  end
63
55
  end
@@ -66,7 +58,9 @@ module GenMachine
66
58
  @table << [c_name, c_args, c_cmds, c_first_state, process_states(c_states)]
67
59
  end
68
60
  end
61
+ require 'pp'
69
62
  pp @table
63
+ return @table
70
64
  end
71
65
 
72
66
  # consolidate same-name states and (eventually) combine / optimize where
data/lib/genmachine.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'genmachine/spec_parser'
2
2
  require 'genmachine/generator'
3
3
  require 'genmachine/generators/helpers/general'
4
+ require 'genmachine/char_set'
4
5
 
5
6
  Dir[File.join(File.dirname(__FILE__),'genmachine','generators','*.rb')].each do |fname|
6
7
  name = File.basename(fname)
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joseph Wecker
@@ -102,6 +102,7 @@ files:
102
102
  - lib/genmachine/generators/helpers/general.rb
103
103
  - lib/genmachine/generators/helpers/ruby.rb
104
104
  - lib/genmachine/generators/ruby.rb
105
+ - lib/genmachine/generators/templates/ruby/executable.erb
105
106
  - lib/genmachine/generators/templates/ruby/lib.erb.rb
106
107
  - lib/genmachine/spec_parser.rb
107
108
  - test/helper.rb