Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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

Dudley Flanders Evan Phoenix
Dudley Flanders

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.

Evan Phoenix
Owner

Helpers is not the greatest name. How about Construction?

Dudley Flanders

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

Evan Phoenix evanphx merged commit 2fbf077 into from
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
9 lib/kpeg/code_generator.rb
View
@@ -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
26 test/test_kpeg_code_generator.rb
View
@@ -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.