Class: Elisp2any::File
- Inherits:
-
Object
- Object
- Elisp2any::File
- Defined in:
- lib/elisp2any/file.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#commentary ⇒ Object
readonly
Returns the value of attribute commentary.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#synopsis ⇒ Object
readonly
Returns the value of attribute synopsis.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, synopsis:, commentary:, code:) ⇒ File
constructor
:nodoc:.
Constructor Details
#initialize(name:, synopsis:, commentary:, code:) ⇒ File
:nodoc:
24 25 26 27 28 29 |
# File 'lib/elisp2any/file.rb', line 24 def initialize(name:, synopsis:, commentary:, code:) # :nodoc: @name = name @synopsis = synopsis @commentary = commentary @code = code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/elisp2any/file.rb', line 6 def code @code end |
#commentary ⇒ Object (readonly)
Returns the value of attribute commentary.
6 7 8 |
# File 'lib/elisp2any/file.rb', line 6 def commentary @commentary end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/elisp2any/file.rb', line 6 def name @name end |
#synopsis ⇒ Object (readonly)
Returns the value of attribute synopsis.
6 7 8 |
# File 'lib/elisp2any/file.rb', line 6 def synopsis @synopsis end |
Class Method Details
.parse(source) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elisp2any/file.rb', line 8 def self.parse(source) source = source.respond_to?(:read) ? source.read : source ts_node = TreeSitterParser.parse(source) first_heading, second_heading, *nodes, last_heading = Node.from_tree_sitter(source, ts_node) name, synopsis = first_heading.name_and_synopsis second_heading.commentary? or raise Error, "no commentary heading: #{second_heading.inspect}" commentary = [] until nodes.empty? (node = nodes.shift).code? and break commentary << node end code = nodes last_heading.final_name == name or raise Error, 'different names' new(name: name, synopsis: synopsis, commentary: commentary, code: code) end |