Class: Ast::Crispr::Ruby::Prism::Adapter
- Inherits:
-
Object
- Object
- Ast::Crispr::Ruby::Prism::Adapter
- Defined in:
- lib/ast/crispr/ruby/prism.rb
Instance Method Summary collapse
- #comment_region_text(document, comment_region) ⇒ Object
- #comment_regions_for(document, owner, region: :leading, owner_scope: :shared_default) ⇒ Object
- #read_ast(document) ⇒ Object
- #structural_owners(document, owner_scope: :shared_default) ⇒ Object
- #structure_profile(owner_scope: :shared_default) ⇒ Object
Instance Method Details
#comment_region_text(document, comment_region) ⇒ Object
58 59 60 |
# File 'lib/ast/crispr/ruby/prism.rb', line 58 def comment_region_text(document, comment_region) document.location_slice(comment_region.location).rstrip end |
#comment_regions_for(document, owner, region: :leading, owner_scope: :shared_default) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ast/crispr/ruby/prism.rb', line 46 def comment_regions_for(document, owner, region: :leading, owner_scope: :shared_default) analysis = document.ast owners = structural_owners(document, owner_scope: owner_scope) case region when :leading analysis.leading_comments_for_owner(owner, owners: owners) else raise Ast::Crispr::Error.new('Unsupported CRISPR comment region', details: { region: region }) end end |
#read_ast(document) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ast/crispr/ruby/prism.rb', line 26 def read_ast(document) analysis = Utils.parse_analysis(document.content, source_label: document.source_label) return analysis if analysis.valid? raise Ast::Crispr::Error.new("Unable to read structural owners from #{document.source_label}", details: { source_label: document.source_label }) end |
#structural_owners(document, owner_scope: :shared_default) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ast/crispr/ruby/prism.rb', line 34 def structural_owners(document, owner_scope: :shared_default) analysis = document.ast case owner_scope when :shared_default, :line_bound_statements, :top_level_statements analysis.statements when :ruby_comments analysis.parse_result.comments else raise Ast::Crispr::Error.new('Unsupported CRISPR owner scope', details: { owner_scope: owner_scope }) end end |
#structure_profile(owner_scope: :shared_default) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ast/crispr/ruby/prism.rb', line 62 def structure_profile(owner_scope: :shared_default) case owner_scope when :shared_default, :line_bound_statements, :top_level_statements Ast::Crispr::StructureProfile.new( owner_scope: owner_scope, owner_selector: :line_bound_statements, supported_comment_regions: [:leading], metadata: { adapter: :prism } ) when :ruby_comments Ast::Crispr::StructureProfile.new( owner_scope: owner_scope, owner_selector: :line_bound_statements, supported_comment_regions: [], metadata: { adapter: :prism, selector: :ruby_comments } ) else raise Ast::Crispr::Error.new('Unsupported CRISPR owner scope', details: { owner_scope: owner_scope }) end end |