Class: YARD::Parser::Rustdoc::Parser
- Inherits:
-
Base
- Object
- Base
- YARD::Parser::Rustdoc::Parser
- Defined in:
- lib/yard-rustdoc/parser.rb
Constant Summary collapse
- TOP_LEVEL_KINDS =
["struct", "enum"].freeze
Instance Method Summary collapse
-
#enumerator ⇒ Array?
abstract
This method should be implemented to return a list of semantic tokens representing the source code to be post-processed.
-
#initialize(source, filename) ⇒ Parser
constructor
This default constructor does nothing.
-
#inspect ⇒ Object
Override inspect instead of dumping the file content because it is huge.
-
#parse ⇒ Base
Finds Rust Struct for the current crate marked with @yard and extract all the marked methods.
- #tokenize ⇒ Object
Constructor Details
#initialize(source, filename) ⇒ Parser
This default constructor does nothing. The subclass is responsible for storing the source contents and filename if they are required.
11 12 13 14 15 16 17 18 |
# File 'lib/yard-rustdoc/parser.rb', line 11 def initialize(source, filename) @source = source @rustdoc_json = JSON.parse(@source).fetch("index") do raise "Expected `index` top-level key in Rustdoc json format" end @filename = filename @entries = [] end |
Instance Method Details
#enumerator ⇒ Array?
This method should be implemented to return a list of semantic tokens representing the source code to be post-processed. Otherwise the method should return nil.
63 64 65 |
# File 'lib/yard-rustdoc/parser.rb', line 63 def enumerator @entries end |
#inspect ⇒ Object
Override inspect instead of dumping the file content because it is huge.
21 22 23 |
# File 'lib/yard-rustdoc/parser.rb', line 21 def inspect "<#{self.class.name} @filename=#{@filename.inspect}>" end |
#parse ⇒ Base
Finds Rust Struct for the current crate marked with @yard and extract all the marked methods.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yard-rustdoc/parser.rb', line 28 def parse @entries = [] @rustdoc_json.each do |id, entry| next unless relevant_entry?(entry) next unless TOP_LEVEL_KINDS.include?(entry["kind"]) methods = entry .dig("inner", "impls") .flat_map { |impl_id| @rustdoc_json.dig(impl_id, "inner", "items") } .filter_map do |method_id| method_entry = @rustdoc_json.fetch(method_id) next unless relevant_entry?(method_entry) Statements::Method.new(method_entry) end @entries << Statements::Struct.new(entry, methods) end self end |
#tokenize ⇒ Object
51 52 53 |
# File 'lib/yard-rustdoc/parser.rb', line 51 def tokenize raise "Rustdoc Parser does not tokenize" end |