ghostwheel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
1
  require "rake/testtask"
2
2
  require "rake/gempackagetask"
3
3
 
4
- DIR = File.dirname(__FILE__)
5
- LIB = File.join(DIR, "lib", "ghost_wheel.rb")
6
- VERSION = File.read(LIB)[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d)\1/, 2]
4
+ DIR = File.dirname(__FILE__)
5
+ LIB = File.join(DIR, "lib", "ghost_wheel.rb")
6
+ GW_VERSION = File.read(LIB)[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d)\1/, 2]
7
7
 
8
8
  task :default => [:test]
9
9
 
@@ -15,16 +15,17 @@ end
15
15
 
16
16
  GEM_SPEC = Gem::Specification.new do |spec|
17
17
  spec.name = "ghostwheel"
18
- spec.version = VERSION
18
+ spec.version = GW_VERSION
19
19
  spec.platform = Gem::Platform::RUBY
20
20
  spec.summary = "Ghost Wheel is a pure Ruby parser generator."
21
21
  spec.files = Dir.glob("{lib,test}/**/*.rb").
22
22
  delete_if { |item| item.include?(".svn") } +
23
23
  ["Rakefile", "setup.rb"]
24
24
 
25
- spec.test_suite_file = "test/ts_all.rb"
25
+ spec.test_files = "test/ts_all.rb"
26
26
  # spec.has_rdoc = true
27
- # spec.extra_rdoc_files = %w{README INSTALL TODO CHANGELOG LICENSE}
27
+ # spec.extra_rdoc_files = %w[ AUTHORS COPYING README INSTALL TODO CHANGELOG
28
+ # LICENSE ]
28
29
  # spec.rdoc_options << '--title' << 'Ghost Wheel Documentation' <<
29
30
  # '--main' << 'README'
30
31
 
@@ -36,7 +37,7 @@ GEM_SPEC = Gem::Specification.new do |spec|
36
37
  spec.homepage = "http://ghostwheel.rubyforge.org"
37
38
  spec.description = <<END_DESC
38
39
  Ghost Wheel is a packrat parser generator handling scanning and parsing of
39
- context-free grammars. Parsers can be built using an EBNF-like syntax or a with
40
+ context-free grammars. Parsers can be built using an PEG-like syntax or a with
40
41
  a Ruby DSL.
41
42
  END_DESC
42
43
  end
@@ -24,5 +24,5 @@ require "ghost_wheel/parser_builder/ruby"
24
24
  require "ghost_wheel/parser_builder/ghost_wheel"
25
25
 
26
26
  module GhostWheel
27
- VERSION = "0.0.1"
27
+ VERSION = "0.0.2"
28
28
  end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby -w
2
2
 
3
3
  module GhostWheel
4
- def self.build_parser(grammar = nil, &parser_init)
4
+ def self.build_parser(grammar = nil, options = Hash.new, &parser_init)
5
5
  if grammar
6
- ParserBuilder::GhostWheel.new(grammar).to_parser
6
+ ParserBuilder::GhostWheel.new(grammar, options).to_parser
7
7
  else
8
8
  ParserBuilder::Ruby.new(&parser_init).to_parser
9
9
  end
@@ -64,8 +64,9 @@ module GhostWheel
64
64
 
65
65
  extend Forwardable
66
66
 
67
- def initialize(grammar)
68
- @parser = ParserBuilder::Ruby.new
67
+ def initialize(grammar, optons = Hash.new)
68
+ @parser = ParserBuilder::Ruby.new
69
+ @context = optons[:context] || Object.new.send(:binding)
69
70
 
70
71
  grammar_to_dsl(GRAMMER_PARSER.parse(grammar))
71
72
  end
@@ -82,7 +83,7 @@ module GhostWheel
82
83
  @parser.send( *sexp.map do |e|
83
84
  if e.is_a? Array
84
85
  if e[0] == :trans
85
- blk = eval(e[2].sub("{", "lambda { |ast|"))
86
+ blk = eval(e[2].sub("{", "lambda { |ast|"), @context)
86
87
  @parser.trans(
87
88
  (e[1].is_a?(Array) ? build_expression(e[1]) : e[1]),
88
89
  &blk
@@ -7,6 +7,21 @@ require File.join(File.dirname(__FILE__), %w[.. helpers ghost_wheel_namespace])
7
7
  class TestGhostWheelDSL < Test::Unit::TestCase
8
8
  include GhostWheelNamespace
9
9
 
10
+ class Context
11
+ def initialize
12
+ @bar = 2
13
+ end
14
+
15
+ def to_binding
16
+ foo = 1
17
+ binding
18
+ end
19
+
20
+ def baz
21
+ 3
22
+ end
23
+ end
24
+
10
25
  def test_rule_definition
11
26
  build "word = 'word'"
12
27
  assert_instance_of(Rule, @parser[:word])
@@ -134,10 +149,22 @@ class TestGhostWheelDSL < Test::Unit::TestCase
134
149
  assert_equal(Literal.new("two"), @parser[:two].expression)
135
150
  end
136
151
 
152
+ def test_providing_a_context_for_grammar_transforms
153
+ build <<-END_GRAMMAR, :context => Context.new.to_binding
154
+ foo = 'foo' { foo }
155
+ bar = 'bar' { @bar }
156
+ baz = 'baz' { baz() }
157
+ test := foo | bar | baz
158
+ END_GRAMMAR
159
+ assert_equal(1, @parser.parse("foo"))
160
+ assert_equal(2, @parser.parse("bar"))
161
+ assert_equal(3, @parser.parse("baz"))
162
+ end
163
+
137
164
  private
138
165
 
139
- def build(grammar)
140
- @builder = ParserBuilder::GhostWheel.new(grammar)
166
+ def build(grammar, options = Hash.new)
167
+ @builder = ParserBuilder::GhostWheel.new(grammar, options)
141
168
  @parser = @builder.to_parser
142
169
  end
143
170
  end
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: ghostwheel
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-07-02 00:00:00 -05:00
8
- summary: Ghost Wheel is a pure Ruby parser generator.
9
- require_paths:
10
- - lib
11
- email: james@grayproductions.net
12
- homepage: http://ghostwheel.rubyforge.org
13
- rubyforge_project: ghostwheel
14
- description: Ghost Wheel is a packrat parser generator handling scanning and parsing of context-free grammars. Parsers can be built using an EBNF-like syntax or a with a Ruby DSL.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - James Edward Gray II
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-21 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ghost Wheel is a packrat parser generator handling scanning and parsing of context-free grammars. Parsers can be built using an PEG-like syntax or a with a Ruby DSL.
17
+ email: james@grayproductions.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - lib/ghost_wheel/build_parser.rb
33
26
  - lib/ghost_wheel/errors.rb
@@ -78,17 +71,31 @@ files:
78
71
  - test/ts_parser.rb
79
72
  - Rakefile
80
73
  - setup.rb
81
- test_files:
82
- - test/ts_all.rb
74
+ has_rdoc: false
75
+ homepage: http://ghostwheel.rubyforge.org
76
+ post_install_message:
83
77
  rdoc_options: []
84
78
 
85
- extra_rdoc_files: []
86
-
87
- executables: []
88
-
89
- extensions: []
90
-
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
91
93
  requirements: []
92
94
 
93
- dependencies: []
94
-
95
+ rubyforge_project: ghostwheel
96
+ rubygems_version: 1.0.1
97
+ signing_key:
98
+ specification_version: 2
99
+ summary: Ghost Wheel is a pure Ruby parser generator.
100
+ test_files:
101
+ - test/ts_all.rb