Permalink
Browse files

+ Assigns AST

  • Loading branch information...
1 parent 88c4c17 commit 1e95a97415a5a3183d8a9968226869754f2c922a @kschiess committed Jan 2, 2011
Showing with 10 additions and 1 deletion.
  1. +3 −0 lib/wt/ast.rb
  2. +2 −1 lib/wt/transform.rb
  3. +5 −0 spec/wt/transform_spec.rb
View
@@ -6,4 +6,7 @@ class IntLit < Struct.new(:int)
class Expression < Struct.new(:left, :op, :right)
end
+
+ class Assign < Struct.new(:ident, :exp)
+ end
end
View
@@ -6,5 +6,6 @@ class Wt::Transform < Parslet::Transform
IntLit.new(Integer(int)) }
rule(left: simple(:left), op: simple(:op), right: simple(:right)) {
Expression.new(left, op, right) }
-
+ rule(ident: simple(:ident), exp: simple(:exp)) {
+ Assign.new(ident, exp) }
end
@@ -16,4 +16,9 @@
it { should == Expression.new('l', '+', 'r') }
end
+ describe "assignments (ident: 'a', exp: ...)" do
+ let(:tree) { {ident: 'a', exp: 'e'} }
+
+ it { should == Assign.new('a', 'e') }
+ end
end

0 comments on commit 1e95a97

Please sign in to comment.