Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

. A really small erb parser.

eval, anyone?
  • Loading branch information...
commit 332dab1a71d4ec373a16f7a8e33bedbc50dd2d17 1 parent f24ef18
@kschiess authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.