Skip to content
Browse files

Move transforms into subdir.

  • Loading branch information...
1 parent f54c72e commit b1826793513443ed12331e3672f57b4cbc50a178 @threedaymonk threedaymonk committed Mar 23, 2012
View
4 lib/sibyl/graph.rb
@@ -1,6 +1,6 @@
require "sibyl/errors"
require "sibyl/parser"
-require "sibyl/ruby_transform"
+require "sibyl/transform/ruby"
require "tsort"
module Sibyl
@@ -98,7 +98,7 @@ def sink_names
def parse(source)
parser = Sibyl::Parser.new
- transform = Sibyl::RubyTransform.new
+ transform = Sibyl::Transform::Ruby.new
transform.apply(parser.parse(source))
end
View
49 lib/sibyl/ruby_transform.rb
@@ -1,49 +0,0 @@
-require "parslet"
-require "sibyl/nodes"
-
-module Sibyl
- class RubyTransform < Parslet::Transform
- include Nodes
-
- rule(text: simple(:x)) { x.to_s }
- rule(numeric: simple(:x)) { x.to_i }
- rule(code: simple(:x)) { x.to_s.strip }
- rule(empty: simple(:x)) { [] }
- rule(type: 'if', expr: simple(:expr), target: simple(:target)) {
- ConditionalJump.new(expr, target)
- }
- rule(type: 'set', var: simple(:var), expr: simple(:expr)) {
- Set.new(var, expr)
- }
- rule(type: 'otherwise', target: simple(:target)) {
- Jump.new(target)
- }
- rule(type: 'branch', branch: subtree(:branch), from: simple(:from)) {
- OptionBrancher.new(from, branch)
- }
- rule(type: 'option', branch: subtree(:branch), from: simple(:from)) {
- OptionBrancher.new(from, branch)
- }
- rule(type: 'option', target: simple(:target), from: simple(:from)) {
- OptionBrancher.new(from, [Jump.new(target)])
- }
- rule(type: 'go', branch: subtree(:branch)) {
- Brancher.new(branch)
- }
- rule(type: 'go', target: simple(:target)) {
- Brancher.new([Jump.new(target)])
- }
- rule(type: 'reject', expr: simple(:expr)) {
- Reject.new(expr)
- }
- rule(type: 'step', subtype: simple(:subtype), name: simple(:name), body: subtree(:body)) {
- Step.new(subtype, name, body)
- }
- rule(type: 'outcome', name: simple(:name)) {
- Outcome.new(name)
- }
- rule(type: 'metadata', key: simple(:key), value: simple(:value)) {
- Metadata.new(key, value)
- }
- end
-end
View
43 lib/sibyl/sexp_transform.rb
@@ -1,43 +0,0 @@
-require "parslet"
-
-module Sibyl
- class SexpTransform < Parslet::Transform
- rule(text: simple(:x)) { x.to_s }
- rule(numeric: simple(:x)) { x.to_i }
- rule(code: simple(:x)) { x.to_s.strip }
- rule(empty: simple(:x)) { [] }
- rule(type: 'if', expr: simple(:expr), target: simple(:target)) {
- [:if, expr, target]
- }
- rule(type: 'set', var: simple(:var), expr: simple(:expr)) {
- [:set, var, expr]
- }
- rule(type: 'otherwise', target: simple(:target)) {
- [:otherwise, target]
- }
- rule(type: 'option', branch: subtree(:branch), from: simple(:from)) {
- [:option, :branch, from, branch]
- }
- rule(type: 'option', target: simple(:target), from: simple(:from)) {
- [:option, :simple, from, target]
- }
- rule(type: 'go', branch: subtree(:branch)) {
- [:go, :branch, branch]
- }
- rule(type: 'go', target: simple(:target)) {
- [:go, :simple, target]
- }
- rule(type: 'reject', expr: simple(:expr)) {
- [:reject, expr.to_s.strip]
- }
- rule(type: 'step', subtype: simple(:subtype), name: simple(:name), body: subtree(:body)) {
- [:step, subtype, name, body]
- }
- rule(type: 'outcome', name: simple(:name)) {
- [:outcome, name]
- }
- rule(type: 'metadata', key: simple(:key), value: simple(:value)) {
- [:metadata, key, value]
- }
- end
-end
View
51 lib/sibyl/transform/ruby.rb
@@ -0,0 +1,51 @@
+require "parslet"
+require "sibyl/nodes"
+
+module Sibyl
+ module Transform
+ class Ruby < Parslet::Transform
+ include Nodes
+
+ rule(text: simple(:x)) { x.to_s }
+ rule(numeric: simple(:x)) { x.to_i }
+ rule(code: simple(:x)) { x.to_s.strip }
+ rule(empty: simple(:x)) { [] }
+ rule(type: 'if', expr: simple(:expr), target: simple(:target)) {
+ ConditionalJump.new(expr, target)
+ }
+ rule(type: 'set', var: simple(:var), expr: simple(:expr)) {
+ Set.new(var, expr)
+ }
+ rule(type: 'otherwise', target: simple(:target)) {
+ Jump.new(target)
+ }
+ rule(type: 'branch', branch: subtree(:branch), from: simple(:from)) {
+ OptionBrancher.new(from, branch)
+ }
+ rule(type: 'option', branch: subtree(:branch), from: simple(:from)) {
+ OptionBrancher.new(from, branch)
+ }
+ rule(type: 'option', target: simple(:target), from: simple(:from)) {
+ OptionBrancher.new(from, [Jump.new(target)])
+ }
+ rule(type: 'go', branch: subtree(:branch)) {
+ Brancher.new(branch)
+ }
+ rule(type: 'go', target: simple(:target)) {
+ Brancher.new([Jump.new(target)])
+ }
+ rule(type: 'reject', expr: simple(:expr)) {
+ Reject.new(expr)
+ }
+ rule(type: 'step', subtype: simple(:subtype), name: simple(:name), body: subtree(:body)) {
+ Step.new(subtype, name, body)
+ }
+ rule(type: 'outcome', name: simple(:name)) {
+ Outcome.new(name)
+ }
+ rule(type: 'metadata', key: simple(:key), value: simple(:value)) {
+ Metadata.new(key, value)
+ }
+ end
+ end
+end
View
45 lib/sibyl/transform/sexp.rb
@@ -0,0 +1,45 @@
+require "parslet"
+
+module Sibyl
+ module Transform
+ class Sexp < Parslet::Transform
+ rule(text: simple(:x)) { x.to_s }
+ rule(numeric: simple(:x)) { x.to_i }
+ rule(code: simple(:x)) { x.to_s.strip }
+ rule(empty: simple(:x)) { [] }
+ rule(type: 'if', expr: simple(:expr), target: simple(:target)) {
+ [:if, expr, target]
+ }
+ rule(type: 'set', var: simple(:var), expr: simple(:expr)) {
+ [:set, var, expr]
+ }
+ rule(type: 'otherwise', target: simple(:target)) {
+ [:otherwise, target]
+ }
+ rule(type: 'option', branch: subtree(:branch), from: simple(:from)) {
+ [:option, :branch, from, branch]
+ }
+ rule(type: 'option', target: simple(:target), from: simple(:from)) {
+ [:option, :simple, from, target]
+ }
+ rule(type: 'go', branch: subtree(:branch)) {
+ [:go, :branch, branch]
+ }
+ rule(type: 'go', target: simple(:target)) {
+ [:go, :simple, target]
+ }
+ rule(type: 'reject', expr: simple(:expr)) {
+ [:reject, expr.to_s.strip]
+ }
+ rule(type: 'step', subtype: simple(:subtype), name: simple(:name), body: subtree(:body)) {
+ [:step, subtype, name, body]
+ }
+ rule(type: 'outcome', name: simple(:name)) {
+ [:outcome, name]
+ }
+ rule(type: 'metadata', key: simple(:key), value: simple(:value)) {
+ [:metadata, key, value]
+ }
+ end
+ end
+end
View
4 test/parsing_test.rb
@@ -1,11 +1,11 @@
require "common"
require "sibyl/parser"
-require "sibyl/sexp_transform"
+require "sibyl/transform/sexp"
describe "Parser" do
def sexp(source)
parser = Sibyl::Parser.new
- transform = Sibyl::SexpTransform.new
+ transform = Sibyl::Transform::Sexp.new
transform.apply(parser.parse(source))
end
View
4 test/step_test.rb
@@ -1,13 +1,13 @@
require "common"
require "sibyl/parser"
-require "sibyl/ruby_transform"
+require "sibyl/transform/ruby"
require "sibyl/errors"
require "ostruct"
describe "Step" do
def ruby(source)
parser = Sibyl::Parser.new
- transform = Sibyl::RubyTransform.new
+ transform = Sibyl::Transform::Ruby.new
transform.apply(parser.parse(source)).first
end
View
4 test/transform_test.rb
@@ -1,11 +1,11 @@
require "common"
require "sibyl/parser"
-require "sibyl/ruby_transform"
+require "sibyl/transform/ruby"
describe "Ruby Transform" do
def ruby(source)
parser = Sibyl::Parser.new
- transform = Sibyl::RubyTransform.new
+ transform = Sibyl::Transform::Ruby.new
transform.apply(parser.parse(source)).first
end

0 comments on commit b182679

Please sign in to comment.
Something went wrong with that request. Please try again.