def transform_node(node)
case node.rule_type
when :Step
step_line = node.get_token(:StepLine)
step_argument = node.get_single(:DataTable) || node.get_single(:DocString) || nil
reject_nils(
type: node.rule_type,
location: get_location(step_line),
keyword: step_line.matched_keyword,
text: step_line.matched_text,
argument: step_argument
)
when :DocString
separator_token = node.get_tokens(:DocStringSeparator)[0]
content_type = separator_token.matched_text == '' ? nil : separator_token.matched_text
line_tokens = node.get_tokens(:Other)
content = line_tokens.map { |t| t.matched_text }.join("\n")
reject_nils(
type: node.rule_type,
location: get_location(separator_token),
contentType: content_type,
content: content
)
when :DataTable
rows = get_table_rows(node)
reject_nils(
type: node.rule_type,
location: rows[0][:location],
rows: rows,
)
when :Background
background_line = node.get_token(:BackgroundLine)
description = get_description(node)
steps = get_steps(node)
reject_nils(
type: node.rule_type,
location: get_location(background_line),
keyword: background_line.matched_keyword,
name: background_line.matched_text,
description: description,
steps: steps
)
when :Scenario_Definition
tags = get_tags(node)
scenario_node = node.get_single(:Scenario)
if(scenario_node)
scenario_line = scenario_node.get_token(:ScenarioLine)
description = get_description(scenario_node)
steps = get_steps(scenario_node)
reject_nils(
type: scenario_node.rule_type,
tags: tags,
location: get_location(scenario_line),
keyword: scenario_line.matched_keyword,
name: scenario_line.matched_text,
description: description,
steps: steps
)
else
scenario_outline_node = node.get_single(:ScenarioOutline)
raise 'Internal grammar error' unless scenario_outline_node
scenario_outline_line = scenario_outline_node.get_token(:ScenarioOutlineLine)
description = get_description(scenario_outline_node)
steps = get_steps(scenario_outline_node)
examples = scenario_outline_node.get_items(:Examples_Definition)
reject_nils(
type: scenario_outline_node.rule_type,
tags: tags,
location: get_location(scenario_outline_line),
keyword: scenario_outline_line.matched_keyword,
name: scenario_outline_line.matched_text,
description: description,
steps: steps,
examples: examples
)
end
when :Examples_Definition
tags = get_tags(node)
examples_node = node.get_single(:Examples)
examples_line = examples_node.get_token(:ExamplesLine)
description = get_description(examples_node)
examples_table = examples_node.get_single(:Examples_Table)
reject_nils(
type: examples_node.rule_type,
tags: tags,
location: get_location(examples_line),
keyword: examples_line.matched_keyword,
name: examples_line.matched_text,
description: description,
tableHeader: !examples_table.nil? ? examples_table[:tableHeader] : nil,
tableBody: !examples_table.nil? ? examples_table[:tableBody] : nil
)
when :Examples_Table
rows = get_table_rows(node)
reject_nils(
tableHeader: rows.first,
tableBody: rows[1..-1]
)
when :Description
line_tokens = node.get_tokens(:Other)
last_non_empty = line_tokens.rindex { |token| !token.line.trimmed_line_text.empty? }
description = line_tokens[0..last_non_empty].map { |token| token.matched_text }.join("\n")
return description
when :Feature
header = node.get_single(:Feature_Header)
return unless header
tags = get_tags(header)
feature_line = header.get_token(:FeatureLine)
return unless feature_line
children = []
background = node.get_single(:Background)
children.push(background) if background
children.concat(node.get_items(:Scenario_Definition))
description = get_description(header)
language = feature_line.matched_gherkin_dialect
reject_nils(
type: node.rule_type,
tags: tags,
location: get_location(feature_line),
language: language,
keyword: feature_line.matched_keyword,
name: feature_line.matched_text,
description: description,
children: children,
)
when :GherkinDocument
feature = node.get_single(:Feature)
reject_nils(
type: node.rule_type,
feature: feature,
comments: @comments
)
else
return node
end
end