Browse files

. A really small erb parser.

eval, anyone?
  • Loading branch information...
1 parent f24ef18 commit 332dab1a71d4ec373a16f7a8e33bedbc50dd2d17 @kschiess committed Jan 21, 2011
Showing with 14 additions and 0 deletions.
  1. +14 −0 example/erb.rb
View
14 example/erb.rb
@@ -0,0 +1,14 @@
+
+$:.unshift File.dirname(__FILE__) + "/../lib"
+require 'parslet'
+
+class ErbParser < Parslet::Parser
+ rule(:ruby) { str('<%') >> (str('%>').absnt? >> any).repeat >> str('%>') }
+ rule(:html) { (str('<%').absnt? >> any).repeat(1) }
+ rule(:html_with_ruby) { (html.as(:html) | ruby.as(:ruby)).repeat }
+ root(:html_with_ruby)
+end
+
+p ErbParser.new.parse <<ERB
+The value of x is: <%= x %>
+ERB

0 comments on commit 332dab1

Please sign in to comment.