genmachine 0.1.2 → 0.1.3
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 +1 -1
- data/genmachine.gemspec +3 -2
- data/lib/VERSION +1 -1
- data/lib/genmachine/generators/templates/ruby/lib.erb.rb +23 -12
- data/lib/genmachine/spec_parser.rb +6 -4
- data/machines/genmachine.machine +3 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
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.3"
|
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-17}
|
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}
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/genmachine/generators/templates/ruby/executable.erb",
|
40
40
|
"lib/genmachine/generators/templates/ruby/lib.erb.rb",
|
41
41
|
"lib/genmachine/spec_parser.rb",
|
42
|
+
"machines/genmachine.machine",
|
42
43
|
"misc/genmachine.vim",
|
43
44
|
"test/helper.rb",
|
44
45
|
"test/test_genmachine.rb"
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -5,17 +5,22 @@ 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
|
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@
|
16
|
-
@
|
8
|
+
class UHash < Hash
|
9
|
+
def <<(kv) k,v = kv; self[k] = v end
|
10
|
+
end
|
11
|
+
|
12
|
+
class UNode
|
13
|
+
attr_accessor :name, :m,:a,:c
|
14
|
+
def initialize(params={})
|
15
|
+
@m = params.delete(:m) || UHash.new
|
16
|
+
@m[:sline] ||= params.delete(:sline)
|
17
|
+
@m[:schr] ||= params.delete(:schr)
|
18
|
+
@a= params.delete(:a) || UHash.new
|
19
|
+
@c= params.delete(:c) || []
|
20
|
+
@name = params.delete(:name)
|
17
21
|
end
|
18
|
-
def <<(val) @
|
22
|
+
def <<(val) @c<<val end
|
23
|
+
def [](key) @c[key] end
|
19
24
|
end
|
20
25
|
|
21
26
|
class Parser < StringScanner
|
@@ -115,7 +120,7 @@ module <%= @classname %>
|
|
115
120
|
|
116
121
|
def eof?() return @last_c == :eof end
|
117
122
|
|
118
|
-
<%- @spec_ast.each do |name, args, cmds, first_state, states| -%>
|
123
|
+
<%- @spec_ast.each do |name, otype, args, cmds, first_state, states| -%>
|
119
124
|
<%- args << "p=nil" -%>
|
120
125
|
<%- args << "name='#{name}'" -%>
|
121
126
|
def <%= name %>(<%= args.join(',') %>)
|
@@ -124,7 +129,13 @@ module <%= @classname %>
|
|
124
129
|
<%- end -%>
|
125
130
|
state='<%= first_state %>'
|
126
131
|
<%- if states.size > 1 or accumulates?(states) or makes_calls?(states) -%>
|
127
|
-
|
132
|
+
<%- if otype == 'U' -%>
|
133
|
+
s = UNode.new(:name=>name,:sline=>@line,:schr=>@pos)
|
134
|
+
<%- elsif otype == '[]' -%>
|
135
|
+
s = []
|
136
|
+
<%- elsif otype == '{}' -%>
|
137
|
+
s = UHash.new
|
138
|
+
<%- end -%>
|
128
139
|
<%- end -%>
|
129
140
|
<%- accumulators(states).each do |_acc| -%>
|
130
141
|
<%= _acc %> ||= ''
|
@@ -10,7 +10,7 @@ module GenMachine
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
-
c_name = c_args = c_cmds = c_first_state = c_states = nil
|
13
|
+
c_name = c_type = c_args = c_cmds = c_first_state = c_states = nil
|
14
14
|
new_fun = false
|
15
15
|
@files.each do |fname|
|
16
16
|
File.new(fname,'r').each_with_index do |line, line_no|
|
@@ -22,11 +22,13 @@ module GenMachine
|
|
22
22
|
if det=='|' && cols[0].include?('(')
|
23
23
|
new_fun = true
|
24
24
|
unless c_name.nil?
|
25
|
-
@table << [c_name, c_args, c_cmds, c_first_state, process_states(c_states)]
|
25
|
+
@table << [c_name, c_type, c_args, c_cmds, c_first_state, process_states(c_states)]
|
26
26
|
end
|
27
27
|
parts = cols[0].split('(')
|
28
28
|
c_name = parts.shift.to_underscored
|
29
|
-
c_args = parts.join('(').
|
29
|
+
c_args, c_type = parts.join('(').split(/::(U|\[\]|\{\})$/)
|
30
|
+
c_args = c_args[0..-2].split(',')
|
31
|
+
c_type ||= '[]'
|
30
32
|
c_states = []
|
31
33
|
c_cmds = (cols[3]||'').split(';')
|
32
34
|
c_first_state = cols[4]
|
@@ -56,7 +58,7 @@ module GenMachine
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
unless c_name.nil?
|
59
|
-
@table << [c_name, c_args, c_cmds, c_first_state, process_states(c_states)]
|
61
|
+
@table << [c_name, c_type, c_args, c_cmds, c_first_state, process_states(c_states)]
|
60
62
|
end
|
61
63
|
end
|
62
64
|
if @opts[:debug]
|
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: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
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-17 00:00:00 -07:00
|
19
19
|
default_executable: genmachine
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/genmachine/generators/templates/ruby/executable.erb
|
109
109
|
- lib/genmachine/generators/templates/ruby/lib.erb.rb
|
110
110
|
- lib/genmachine/spec_parser.rb
|
111
|
+
- machines/genmachine.machine
|
111
112
|
- misc/genmachine.vim
|
112
113
|
- test/helper.rb
|
113
114
|
- test/test_genmachine.rb
|