Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Output the generated AST helpers in a module so they can be reused. #24

Merged
merged 2 commits into from

2 participants

@dudleyf

I wanted to use the generated AST helper methods to simplify some tests. Putting them inside a module which the generated parser class extends allows other classes to use the helpers, too.

@evanphx
Owner

Helpers is not the greatest name. How about Construction?

@dudleyf

Confirm. Helpers is a bad name; Construction is much betterer.

@evanphx evanphx merged commit 2fbf077 into evanphx:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 13 deletions.
  1. +6 −3 lib/kpeg/code_generator.rb
  2. +16 −10 test/test_kpeg_code_generator.rb
View
9 lib/kpeg/code_generator.rb
@@ -83,11 +83,14 @@ def handle_ast(code)
if output_node
code << " end\n"
+ code << " module #{root}Construction\n"
methods.each do |short, name, attrs|
- code << " def #{short}(#{attrs.join(', ')})\n"
- code << " #{root}::#{name}.new(#{attrs.join(', ')})\n"
- code << " end\n"
+ code << " def #{short}(#{attrs.join(', ')})\n"
+ code << " #{root}::#{name}.new(#{attrs.join(', ')})\n"
+ code << " end\n"
end
+ code << " end\n"
+ code << " include #{root}Construction\n"
end
end
View
26 test/test_kpeg_code_generator.rb
@@ -1661,15 +1661,18 @@ def initialize()
end
end
end
- def bracket(receiver, argument)
- AST::BracketOperator.new(receiver, argument)
- end
- def simple()
- AST::Simple.new()
- end
- def simple2()
- AST::Simple2.new()
+ module ASTConstruction
+ def bracket(receiver, argument)
+ AST::BracketOperator.new(receiver, argument)
+ end
+ def simple()
+ AST::Simple.new()
+ end
+ def simple2()
+ AST::Simple2.new()
+ end
end
+ include ASTConstruction
# root = .
def _root
@@ -1715,9 +1718,12 @@ def initialize(receiver, argument)
attr_reader :argument
end
end
- def bracket(receiver, argument)
- MegaAST::BracketOperator.new(receiver, argument)
+ module MegaASTConstruction
+ def bracket(receiver, argument)
+ MegaAST::BracketOperator.new(receiver, argument)
+ end
end
+ include MegaASTConstruction
# root = .
def _root
Something went wrong with that request. Please try again.