This repository has been archived by the owner on Apr 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f54c72e
commit b182679
Showing
8 changed files
with
104 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters