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
-
#attach_remarks(model, remarks) ⇒ Object
Attach remarks to model elements based on their tagged paths.
-
#extract_remarks(ast, source) ⇒ Array<Hash>
Extract all remarks from the AST with their tags and source positions.
Instance Method Details
#attach_remarks(model, remarks) ⇒ Object
Attach remarks to model elements based on their tagged paths.
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.
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 (*...*) (ast, source, remarks) # Extract tail remarks (--...) extract_tail_remarks(ast, source, remarks) remarks end |