Sha256: 25d84a256148248b77a6c7f9ae7ee9661c5bdd46a1814f2ba79f13cf2439484b

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

module Wool
  module SexpAnalysis
    # This is a simple inherited attribute applied to each node,
    # giving a pointer to that node's next and previous AST node.
    # That way AST traversal is easier.
    module NextPrevAnnotation
      extend BasicAnnotation
      add_properties :next, :prev
      
      # This is the annotator for the next and prev annotation.
      class Annotator
        def annotate!(root)
          children = root.children
          children.each_with_index do |elt, idx|
            # ignore non-sexps. Primitives can't be annotated, sadly.
            if SexpAnalysis::Sexp === elt
              elt.next = children[idx+1]
              elt.prev = children[idx-1] if idx >= 1
            end
          end
        end
      end
      add_annotator Annotator
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wool-0.5.1 lib/wool/analysis/annotations/next_annotation.rb