genmachine 0.2.2 → 0.2.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/TODO CHANGED
@@ -1,7 +1,7 @@
1
1
  - Fix "unexpected ..." so it works again
2
2
  - Automatically put {eof?} (by itself) clauses at beginning
3
3
  - Get per-state eof? detection working again (for final else clause)
4
-
4
+ - Errors when state isn't present. Warnings even if it is never referenced
5
5
  - highlight `c` specially
6
6
  - Allow `b<<` etc. in statements - implied 'c' source
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.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.2.2"
8
+ s.version = "0.2.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-19}
12
+ s.date = %q{2011-08-20}
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}
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -107,9 +107,9 @@ module GenMachine
107
107
  return []
108
108
  when acc_phrase =~ /^\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*>>\s*$/
109
109
  return ["#{rb_vars($1)}.reset!"]
110
- when acc_phrase =~ /^\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*>>\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*$/
110
+ when acc_phrase =~ /^\s*(["'a-zA-Z_][^>]*)\s*>>\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*$/
111
111
  return ["#{rb_vars($1)}.into(#{rb_vars($2)})"]
112
- when acc_phrase =~ /^\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*>>>\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*$/
112
+ when acc_phrase =~ /^\s*(["'a-zA-Z_][^>]*)\s*>>>\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*$/
113
113
  return ["#{rb_vars($1)}.into!(#{rb_vars($2)})"]
114
114
  else raise("Can't figure out your accumulator statement: #{acc_phrase}")
115
115
  end
@@ -8,6 +8,21 @@ class Integer
8
8
  def reset; :nop end
9
9
  end
10
10
 
11
+ class String
12
+ def into(v); into!(v) unless size == 0 end
13
+ def into!(v); v << self.dup; reset! end
14
+ def <<(v)
15
+ begin
16
+ concat([v].pack('U*'))
17
+ rescue
18
+ concat(v)
19
+ end
20
+ end
21
+ def reset!; self.gsub! /./um,'' end
22
+ def reset; d=dup;d.reset!;d end
23
+ end
24
+
25
+
11
26
  module <%= @classname %>
12
27
  def self.parse(str) Parser.new(str).parse end
13
28
  def self.parse_file(fname) Parser.new(IO.read(fname)).parse end
@@ -28,21 +43,6 @@ module <%= @classname %>
28
43
  def reset; d=dup; d.reset!; d end
29
44
  end
30
45
 
31
- class UString < String
32
- def into(v); into!(v) unless size == 0 end
33
- def into!(v)
34
- v << self.dup
35
- reset!
36
- end
37
-
38
- def <<(v)
39
- begin; super([v].pack('U*'))
40
- rescue; super(v) end
41
- end
42
- def reset!; self.gsub! /./um,'' end
43
- def reset; d=dup;d.reset!;d end
44
- end
45
-
46
46
  class UNode
47
47
  attr_accessor :name, :m,:a,:c
48
48
  def initialize(params={})
@@ -123,12 +123,12 @@ module <%= @classname %>
123
123
  @leading = true; @indent = 0
124
124
  when 0x0a
125
125
  nc = peek(4).unpack('U')[0]
126
- if nc == 0x0d then getch; c = UString.new("\n\r") end
126
+ if nc == 0x0d then getch; c = "\n\r" end
127
127
  @last_is_newline = true; @line += 1; @pos = 1
128
128
  @leading = true; @indent = 0
129
129
  when 0x0d
130
130
  nc = peek(4).unpack('U')[0]
131
- if nc == 0x0a then getch; c = UString.new("\r\n") end
131
+ if nc == 0x0a then getch; c = "\r\n" end
132
132
  @last_is_newline = true; @line += 1; @pos = 1
133
133
  @leading = true; @indent = 0
134
134
  when 0x20,0x09
@@ -158,7 +158,7 @@ module <%= @classname %>
158
158
 
159
159
  <%- @spec_ast.each do |name, otype, args, cmds, first_state, states| -%>
160
160
  <%- args << "p=nil" -%>
161
- <%- args << "name=UString.new('#{name}')" -%>
161
+ <%- args << "name='#{name}'" -%>
162
162
  def <%= name %>(<%= args.join(',') %>)
163
163
  <%- cmds.each do |c| -%>
164
164
  <%= rb_vars(c) %>
@@ -174,7 +174,7 @@ module <%= @classname %>
174
174
  <%- end -%>
175
175
  <%- end -%>
176
176
  <%- accumulators(states).each do |_acc| -%>
177
- <%= _acc %> ||= UString.new
177
+ <%= _acc %> ||= ''
178
178
  <%- end -%>
179
179
  loop do
180
180
  <%= INPUT %> = nextchar
@@ -211,7 +211,7 @@ module <%= @classname %>
211
211
  <%- end -%>
212
212
  end
213
213
  <%- if has_fallthru -%>
214
- error("Unexpected #{<%= INPUT %>}")
214
+ error("Unexpected \"#{[<%= INPUT %>].pack("U*")}\"")
215
215
  @fwd = true
216
216
  return
217
217
  <%- end -%>
data/misc/genmachine.vim CHANGED
@@ -39,7 +39,7 @@ syn match gmSpecState /\s*{[^}]\+}\s*/ contained
39
39
  syn match gmState /\s*:[^ )({}]\+\s*/ contained
40
40
  syn match gmGlobals /\$\w\+/ contained
41
41
 
42
- syn region gmRange start=/\[/ end=/\]/ skip=/\\\]/ keepend contained contains=gmSpecMetas,gmMetachars,gmRangeDelims
42
+ syn region gmRange start=/\[/ end=/\]/ skip=/\\./ keepend contained contains=gmSpecMetas,gmMetachars,gmRangeDelims
43
43
  syn match gmSpecMetas /\\s\|\\n/ contained
44
44
  syn match gmMetachars /\\t\|\\r\|\\f\|\\b\|\\a\|\\e\|\\\[\|\\\]\|\\\\/ contained
45
45
  syn match gmRangeDelims /\\\@!\[\|\\\@!]/ contained
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.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-19 00:00:00 -07:00
18
+ date: 2011-08-20 00:00:00 -07:00
19
19
  default_executable: genmachine
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency