Class: Gitlab::TemplateParser::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/gitlab/template_parser/parser.rb

Overview

A parser for a simple template syntax, used for example to generate changelogs.

As a quick primer on the template syntax, a basic template looks like this:

{% each users %}
Name: {{name}}
Age: {{age}}

{% if birthday %}
This user is celebrating their birthday today! Yay!
{% end %}
{% end %}

For more information, refer to the Parslet documentation found at kschiess.github.io/parslet/.

Instance Method Summary collapse

Instance Method Details

#parse_and_transform(input) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/gitlab/template_parser/parser.rb', line 166

def parse_and_transform(input)
  AST::Transformer.new.apply(parse(input))
rescue Parslet::ParseFailed => ex
  # We raise a custom error so it's easier to catch different parser
  # related errors. In addition, this ensures the caller of this method
  # doesn't depend on a Parslet specific error class.
  raise Error, "Failed to parse the template: #{ex.message}"
end