Module: Expressir::Express::RemarkHandling

Extended by:
RemarkHandling
Included in:
RemarkHandling
Defined in:
lib/expressir/express/transformer/remark_handling.rb

Overview

Handles remark extraction and attachment for the Transformer. Works with the AST directly, without needing Ctx objects.

Instance Method Summary collapse

Instance Method Details

#attach_remarks(model, remarks) ⇒ Object

Attach remarks to model elements based on their tagged paths.

Parameters:

  • model (Model::ModelElement)

    The root model element

  • remarks (Array<Hash>)

    The extracted remarks



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/expressir/express/transformer/remark_handling.rb', line 31

def attach_remarks(model, remarks)
  # Group remarks by their tag
  tagged_remarks, untagged_remarks = remarks.partition { |r| r[:tag] }

  # Process tagged remarks
  tagged_remarks.each do |remark|
    target = find_by_path(model, remark[:tag])
    if target
      add_remark(target, remark[:text])
    end
  end

  # Process untagged remarks (attach based on position)
  attach_untagged_remarks(model, untagged_remarks)
end

#extract_remarks(ast, source) ⇒ Array<Hash>

Extract all remarks from the AST with their tags and source positions.

Parameters:

  • ast (Hash)

    The AST from Parsanol parser

  • source (String)

    The original source code

Returns:

  • (Array<Hash>)

    Array of remark info hashes



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/expressir/express/transformer/remark_handling.rb', line 16

def extract_remarks(ast, source)
  remarks = []

  # Extract embedded remarks (*...*)
  extract_embedded_remarks(ast, source, remarks)

  # Extract tail remarks (--...)
  extract_tail_remarks(ast, source, remarks)

  remarks
end