Module: Markly::Merge

Extended by:
Merge
Included in:
Merge
Defined in:
lib/markly/merge.rb,
lib/markly/merge/version.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

PACKAGE_NAME =
"markly-merge"
BACKEND_REFERENCE =
TreeHaver::BackendReference.new(id: "markly", family: "native").freeze
VERSION =
Version::VERSION

Class Method Summary collapse

Class Method Details

.available_markdown_backendsObject



18
19
20
# File 'lib/markly/merge.rb', line 18

def available_markdown_backends
  [BACKEND_REFERENCE]
end

.markdown_backend_feature_profile(backend: nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/markly/merge.rb', line 22

def markdown_backend_feature_profile(backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  markdown_feature_profile.merge(backend: BACKEND_REFERENCE.id, backend_ref: BACKEND_REFERENCE.to_h)
end

.markdown_embedded_families(analysis) ⇒ Object



460
461
462
# File 'lib/markly/merge.rb', line 460

def markdown_embedded_families(analysis)
  Markdown::Merge.markdown_embedded_families(analysis)
end

.markdown_feature_profileObject



14
15
16
# File 'lib/markly/merge.rb', line 14

def markdown_feature_profile
  Markdown::Merge.markdown_feature_profile
end

.markdown_plan_context(backend: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/markly/merge.rb', line 29

def markdown_plan_context(backend: nil)
  profile = markdown_backend_feature_profile(backend: backend)
  return profile if profile[:ok] == false

  {
    family_profile: markdown_feature_profile,
    feature_profile: {
      backend: profile[:backend],
      supports_dialects: true,
      supported_policies: []
    }
  }
end

.markdown_structured_edit_application_projectionObject



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/markly/merge.rb', line 154

def markdown_structured_edit_application_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_application: Ast::Merge.structured_edit_application(
      request: markdown_structured_edit_request_projection[:structured_edit_request],
      result: markdown_structured_edit_result_projection[:structured_edit_result],
      metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
    )
  }
end

.markdown_structured_edit_batch_report_projectionObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/markly/merge.rb', line 220

def markdown_structured_edit_batch_report_projection
  content = "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\n"
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_batch_report: Ast::Merge.structured_edit_batch_report(
      reports: [
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: "replace",
              content: content,
              source_label: "README.md",
              target_selector: "Synopsis@2",
              target_selector_family: "section_branch",
              payload_text: "## Synopsis\n\nNew synopsis.\n",
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: "replace",
              updated_content: "# Title\n\n## Synopsis\n\nNew synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\n",
              changed: true,
              captured_text: "## Synopsis\n\nOld synopsis.\n",
              match_count: 1,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: "replace",
                operation_family: "rewrite",
                known_operation_kind: true,
                source_requirement: "required",
                destination_requirement: "none",
                replacement_source: "explicit_text",
                captures_source_text: true,
                supports_if_missing: false,
                metadata: { source: "legacy_crispr_reference" }
              ),
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
          ),
          provider_family: "markdown",
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: "legacy_crispr_reference" }
        ),
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: "insert",
              content: content,
              source_label: "source",
              destination_selector: "/heading/usage",
              destination_selector_family: "section_branch",
              payload_text: "### Managed Usage\n\nInserted usage text.\n",
              if_missing: "append",
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: "insert",
              updated_content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n### Managed Usage\n\nInserted usage text.\n\n## Deprecated\n\nDeprecated text.\n",
              changed: true,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: "insert",
                operation_family: "insertion",
                known_operation_kind: true,
                source_requirement: "none",
                destination_requirement: "optional",
                replacement_source: "explicit_text",
                captures_source_text: false,
                supports_if_missing: true,
                metadata: { source: "legacy_crispr_reference" }
              ),
              destination_profile: Ast::Merge.structured_edit_destination_profile(
                resolution_kind: "append_fallback",
                resolution_source: "none",
                anchor_boundary: "none",
                resolution_family: "append",
                resolution_source_family: "implicit",
                anchor_boundary_family: "none",
                known_resolution_kind: true,
                known_resolution_source: true,
                known_anchor_boundary: true,
                used_if_missing: true,
                metadata: { family: "shared", source: "legacy_crispr_reference" }
              ),
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
          ),
          provider_family: "markdown",
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: "legacy_crispr_reference" }
        ),
        Ast::Merge.structured_edit_execution_report(
          application: Ast::Merge.structured_edit_application(
            request: Ast::Merge.structured_edit_request(
              operation_kind: "delete",
              content: content,
              source_label: "README.md",
              target_selector: "Deprecated@2",
              target_selector_family: "section_branch",
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            result: Ast::Merge.structured_edit_result(
              operation_kind: "delete",
              updated_content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n",
              changed: true,
              captured_text: "## Deprecated\n\nDeprecated text.\n",
              match_count: 1,
              operation_profile: Ast::Merge.structured_edit_operation_profile(
                operation_kind: "delete",
                operation_family: "removal",
                known_operation_kind: true,
                source_requirement: "required",
                destination_requirement: "none",
                replacement_source: "none",
                captures_source_text: true,
                supports_if_missing: false,
                metadata: { source: "legacy_crispr_reference" }
              ),
              metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
            ),
            metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
          ),
          provider_family: "markdown",
          provider_backend: BACKEND_REFERENCE.id,
          diagnostics: [],
          metadata: { source: "legacy_crispr_reference" }
        )
      ],
      diagnostics: [
        {
          severity: "info",
          category: "assumed_default",
          message: "markdown batch preserved request ordering."
        }
      ],
      metadata: { batch_label: "markdown_markly_triad", source: "legacy_crispr_reference" }
    )
  }
end

.markdown_structured_edit_batch_request_projectionObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/markly/merge.rb', line 180

def markdown_structured_edit_batch_request_projection
  content = "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Usage\n\nExisting text.\n\n## Deprecated\n\nDeprecated text.\n"
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_batch_request: Ast::Merge.structured_edit_batch_request(
      requests: [
        Ast::Merge.structured_edit_request(
          operation_kind: "replace",
          content: content,
          source_label: "README.md",
          target_selector: "Synopsis@2",
          target_selector_family: "section_branch",
          payload_text: "## Synopsis\n\nNew synopsis.\n",
          metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: "insert",
          content: content,
          source_label: "source",
          destination_selector: "/heading/usage",
          destination_selector_family: "section_branch",
          payload_text: "### Managed Usage\n\nInserted usage text.\n",
          if_missing: "append",
          metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
        ),
        Ast::Merge.structured_edit_request(
          operation_kind: "delete",
          content: content,
          source_label: "README.md",
          target_selector: "Deprecated@2",
          target_selector_family: "section_branch",
          metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
        )
      ],
      metadata: { batch_label: "markdown_markly_triad", source: "legacy_crispr_reference" }
    )
  }
end

.markdown_structured_edit_execution_report_projectionObject



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/markly/merge.rb', line 166

def markdown_structured_edit_execution_report_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_execution_report: Ast::Merge.structured_edit_execution_report(
      application: markdown_structured_edit_application_projection[:structured_edit_application],
      provider_family: "markdown",
      provider_backend: BACKEND_REFERENCE.id,
      diagnostics: [],
      metadata: { source: "legacy_crispr_reference" }
    )
  }
end

.markdown_structured_edit_provider_profileObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/markly/merge.rb', line 43

def markdown_structured_edit_provider_profile
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_profile: {
      family: "markdown",
      structure_profile: Ast::Merge.structured_edit_structure_profile(
        owner_scope: "heading_sections",
        owner_selector: "heading_sections",
        owner_selector_family: "section_branch",
        known_owner_selector: true,
        supported_comment_regions: [],
        metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
      ),
      selection_profile: Ast::Merge.structured_edit_selection_profile(
        owner_scope: "heading_sections",
        owner_selector: "heading_sections",
        owner_selector_family: "section_branch",
        selector_kind: "heading_section",
        selection_intent: "section_branch",
        selection_intent_family: "section_branch",
        known_selection_intent: true,
        comment_region: nil,
        include_trailing_gap: false,
        comment_anchored: false,
        metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
      ),
      match_profile: Ast::Merge.structured_edit_match_profile(
        start_boundary: "owner_start",
        start_boundary_family: "structural_owner",
        known_start_boundary: true,
        end_boundary: "owner_end",
        end_boundary_family: "structural_owner",
        known_end_boundary: true,
        payload_kind: "section_branch",
        payload_family: "section_branch",
        known_payload_kind: true,
        comment_anchored: false,
        trailing_gap_extended: false,
        metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
      )
    }
  }
end

.markdown_structured_edit_request_projectionObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/markly/merge.rb', line 88

def markdown_structured_edit_request_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_request: Ast::Merge.structured_edit_request(
      operation_kind: "replace",
      content: "# Title\n\n## Synopsis\n\nOld synopsis.\n\n## Install\n\nInstall text.\n",
      source_label: "README.md",
      target_selector: "Synopsis@2",
      target_selector_family: "section_branch",
      target_selection: Ast::Merge.structured_edit_target_selection(
        selector_kind: "heading_section",
        selection_intent: "section_branch",
        selection_intent_family: "section_branch",
        known_selection_intent: true,
        comment_region: nil,
        include_trailing_gap: false,
        comment_anchored: false,
        metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
      ),
      target_match: Ast::Merge.structured_edit_target_match(
        start_boundary: "owner_start",
        start_boundary_family: "structural_owner",
        known_start_boundary: true,
        end_boundary: "owner_end",
        end_boundary_family: "structural_owner",
        known_end_boundary: true,
        payload_kind: "section_branch",
        payload_family: "section_branch",
        known_payload_kind: true,
        comment_anchored: false,
        trailing_gap_extended: false,
        metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
      ),
      payload_text: "## Synopsis\n\nNew synopsis.\n",
      metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
    )
  }
end

.markdown_structured_edit_result_projectionObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/markly/merge.rb', line 128

def markdown_structured_edit_result_projection
  {
    package: PACKAGE_NAME,
    backend: BACKEND_REFERENCE.id,
    structured_edit_result: Ast::Merge.structured_edit_result(
      operation_kind: "replace",
      updated_content: "# Title\n\n## Synopsis\n\nNew synopsis.\n\n## Install\n\nInstall text.\n",
      changed: true,
      captured_text: "## Synopsis\n\nOld synopsis.\n",
      match_count: 1,
      operation_profile: Ast::Merge.structured_edit_operation_profile(
        operation_kind: "replace",
        operation_family: "rewrite",
        known_operation_kind: true,
        source_requirement: "required",
        destination_requirement: "none",
        replacement_source: "explicit_text",
        captures_source_text: true,
        supports_if_missing: false,
        metadata: { source: "legacy_crispr_reference" }
      ),
      metadata: { family: "markdown", provider: BACKEND_REFERENCE.id, source: "legacy_crispr_reference" }
    )
  }
end

.match_markdown_owners(template, destination) ⇒ Object



388
389
390
# File 'lib/markly/merge.rb', line 388

def match_markdown_owners(template, destination)
  Markdown::Merge.match_markdown_owners(template, destination)
end

.merge_markdown(template_source, destination_source, dialect, backend: nil) ⇒ Object



392
393
394
395
396
397
# File 'lib/markly/merge.rb', line 392

def merge_markdown(template_source, destination_source, dialect, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown(template_source, destination_source, dialect)
end

.merge_markdown_with_reviewed_nested_outputs(template_source, destination_source, dialect, review_state, applied_children, backend: nil) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/markly/merge.rb', line 399

def merge_markdown_with_reviewed_nested_outputs(template_source, destination_source, dialect, review_state, applied_children, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs(
    template_source,
    destination_source,
    dialect,
    review_state,
    applied_children
  )
end

.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle(template_source, destination_source, dialect, replay_bundle, backend: nil) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
# File 'lib/markly/merge.rb', line 412

def merge_markdown_with_reviewed_nested_outputs_from_replay_bundle(template_source, destination_source, dialect, replay_bundle, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle(
    template_source,
    destination_source,
    dialect,
    replay_bundle
  )
end

.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle_envelope(template_source, destination_source, dialect, envelope, backend: nil) ⇒ Object



424
425
426
427
428
429
430
431
432
433
434
# File 'lib/markly/merge.rb', line 424

def merge_markdown_with_reviewed_nested_outputs_from_replay_bundle_envelope(template_source, destination_source, dialect, envelope, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_replay_bundle_envelope(
    template_source,
    destination_source,
    dialect,
    envelope
  )
end

.merge_markdown_with_reviewed_nested_outputs_from_review_state(template_source, destination_source, dialect, review_state, backend: nil) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
# File 'lib/markly/merge.rb', line 436

def merge_markdown_with_reviewed_nested_outputs_from_review_state(template_source, destination_source, dialect, review_state, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_review_state(
    template_source,
    destination_source,
    dialect,
    review_state
  )
end

.merge_markdown_with_reviewed_nested_outputs_from_review_state_envelope(template_source, destination_source, dialect, envelope, backend: nil) ⇒ Object



448
449
450
451
452
453
454
455
456
457
458
# File 'lib/markly/merge.rb', line 448

def merge_markdown_with_reviewed_nested_outputs_from_review_state_envelope(template_source, destination_source, dialect, envelope, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  Markdown::Merge.merge_markdown_with_reviewed_nested_outputs_from_review_state_envelope(
    template_source,
    destination_source,
    dialect,
    envelope
  )
end

.parse_markdown(source, dialect, backend: nil) ⇒ Object



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/markly/merge.rb', line 362

def parse_markdown(source, dialect, backend: nil)
  requested = backend.to_s.empty? ? BACKEND_REFERENCE.id : backend.to_s
  return unsupported_feature_result("Unsupported Markdown backend #{requested}.") unless requested == BACKEND_REFERENCE.id

  ::Markly.parse(source, flags: ::Markly::DEFAULT, extensions: [:table])
  normalized = Markdown::Merge.normalize_source(source)
  {
    ok: true,
    diagnostics: [],
    analysis: {
      kind: "markdown",
      dialect: dialect,
      normalized_source: normalized,
      root_kind: "document",
      owners: Markdown::Merge.collect_markdown_owners(normalized)
    },
    policies: []
  }
rescue StandardError => e
  {
    ok: false,
    diagnostics: [{ severity: "error", category: "parse_error", message: e.message }],
    policies: []
  }
end

.unsupported_feature_result(message) ⇒ Object



464
465
466
467
468
469
470
# File 'lib/markly/merge.rb', line 464

def unsupported_feature_result(message)
  {
    ok: false,
    diagnostics: [{ severity: "error", category: "unsupported_feature", message: message }],
    policies: []
  }
end