Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aupajo/21d3de5ae11af5bb6796 to your computer and use it in GitHub Desktop.
Save Aupajo/21d3de5ae11af5bb6796 to your computer and use it in GitHub Desktop.
JSP tag parser in Ruby using Parslet
class JSPTagParser < Parslet::Parser
rule(:java) { (str('%>').absent? >> any).repeat.as(:java) }
rule(:jsp) { java.as(:code) }
rule(:jsp_with_tags) { str('<%') >> jsp >> str('%>') }
rule(:text) { (str('<%').absent? >> any).repeat(1) }
rule(:text_with_java) { (text.as(:text) | jsp_with_tags).repeat.as(:text) }
root(:text_with_java)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment