natspec 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +5 -0
- data/README.md +32 -0
- data/Rakefile +30 -0
- data/lib/natspec.rb +139 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9c9f2377b94fed29636cb0895bb347c6879af7daf032a0b22c6e1d0c2543bc3
|
4
|
+
data.tar.gz: 13269cbe3eb879e217cabbb56128312a0349c4ecb23ce6a0da405eaed4bd671f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4fbca50fe5cfaa526d94c39b75e9f635b794a3281124a5179343168ddce0f6c2baeb8eb3e45da62457ad32044c397fcb72f37c10198b9ea3c7ba3fdcf4951093
|
7
|
+
data.tar.gz: c7dfd9ea9d0e3423b6497db39c74deca392eed8e6b78e3ce8190566ef46ba3c192f7fc12de3040ca69907ee8d8ba8f71a6255e5fa846465d86737c2ca627d3d0
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Natspec - Natural Spec(ification) Documentation Parser
|
2
|
+
|
3
|
+
natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
* home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
|
8
|
+
* bugs :: [github.com/rubycocos/blockchain/issues](https://github.com/rubycocos/blockchain/issues)
|
9
|
+
* gem :: [rubygems.org/gems/natspec](https://rubygems.org/gems/natspec)
|
10
|
+
* rdoc :: [rubydoc.info/gems/natspec](http://rubydoc.info/gems/natspec)
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
To be done
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
The scripts are dedicated to the public domain.
|
24
|
+
Use it as you please with no restrictions whatsoever.
|
25
|
+
|
26
|
+
|
27
|
+
## Questions? Comments?
|
28
|
+
|
29
|
+
|
30
|
+
Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
|
31
|
+
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
|
3
|
+
|
4
|
+
Hoe.spec 'natspec' do
|
5
|
+
|
6
|
+
self.version = '0.0.1'
|
7
|
+
|
8
|
+
self.summary = "natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts"
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
self.urls = { home: 'https://github.com/rubycocos/blockchain' }
|
12
|
+
|
13
|
+
self.author = 'Gerald Bauer'
|
14
|
+
self.email = 'wwwmake@googlegroups.com'
|
15
|
+
|
16
|
+
# switch extension to .markdown for gihub formatting
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
|
20
|
+
self.extra_deps = [
|
21
|
+
]
|
22
|
+
|
23
|
+
self.licenses = ['Public Domain']
|
24
|
+
|
25
|
+
self.spec_extras = {
|
26
|
+
required_ruby_version: '>= 2.3'
|
27
|
+
}
|
28
|
+
|
29
|
+
end
|
30
|
+
|
data/lib/natspec.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'cocos'
|
2
|
+
|
3
|
+
|
4
|
+
module Natspec
|
5
|
+
|
6
|
+
|
7
|
+
class Document
|
8
|
+
attr_reader :head, :sections,
|
9
|
+
:storage, :functions
|
10
|
+
def initialize( head, sections )
|
11
|
+
@head = head
|
12
|
+
@sections = sections
|
13
|
+
|
14
|
+
@storage, @functions = _parse_sections( @sections )
|
15
|
+
end
|
16
|
+
|
17
|
+
def _parse_sections( sections )
|
18
|
+
|
19
|
+
storage = {}
|
20
|
+
functions = {}
|
21
|
+
|
22
|
+
sections.each do |heading, lines|
|
23
|
+
|
24
|
+
if (m=heading.match(/\Astorage[ ]+(.+)[ ]+(?<id>[_A-Za-z0-9]+)\z/))
|
25
|
+
storage[ m[:id] ] = [heading,lines]
|
26
|
+
elsif (m=heading.match(/\Afunction[ ]+(?<id>[_A-Za-z0-9]+)([ (]|\z)/))
|
27
|
+
functions[ m[:id] ] = [heading,lines]
|
28
|
+
else
|
29
|
+
puts "!! ERROR - unsupported heading type in line >#{heading}<; sorry"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
[storage, functions]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class Parser
|
40
|
+
def initialize( txt )
|
41
|
+
@txt = txt
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse
|
45
|
+
head = []
|
46
|
+
sections = []
|
47
|
+
|
48
|
+
section = nil
|
49
|
+
@txt.each_line do |line|
|
50
|
+
|
51
|
+
line = line.rstrip
|
52
|
+
if (m=line.match( /\A[ ]*\#{2}[ ]*(?<heading>.+)[ ]*\z/ ))
|
53
|
+
puts " found heading >#{m[:heading]}<"
|
54
|
+
sections << section if section
|
55
|
+
section = [m[:heading],[]]
|
56
|
+
elsif (m=line.match(/\A[ ]*\#{1,}/ ))
|
57
|
+
puts " !! ERROR - unsupported heading level in line >#{line}<; sorry"
|
58
|
+
exit 1
|
59
|
+
else
|
60
|
+
if section
|
61
|
+
section[1] << line
|
62
|
+
else
|
63
|
+
head << line
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
sections << section if section
|
69
|
+
|
70
|
+
|
71
|
+
## pre-process sections
|
72
|
+
## remove trailing empty lines
|
73
|
+
_strip_empty_leading_lines( head )
|
74
|
+
_strip_empty_trailing_lines( head )
|
75
|
+
_indent_code_block( head )
|
76
|
+
|
77
|
+
sections.each do |heading, lines|
|
78
|
+
_strip_empty_leading_lines( lines )
|
79
|
+
_strip_empty_trailing_lines( lines )
|
80
|
+
_strip_code_block( lines )
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
Document.new( head, sections )
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def _strip_code_block( sect )
|
89
|
+
sect.reject! { |line| line.start_with?( '```' ) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def _indent_code_block( sect )
|
93
|
+
## step 1: indent code blocks
|
94
|
+
inside_block = false
|
95
|
+
sect.each_with_index do |line,i|
|
96
|
+
if line.start_with?( '```' )
|
97
|
+
inside_block = !inside_block
|
98
|
+
elsif inside_block
|
99
|
+
sect[i] = (' '*4) + sect[i]
|
100
|
+
else
|
101
|
+
## regular line; keep going
|
102
|
+
end
|
103
|
+
end
|
104
|
+
## step 2: remove all code block lines
|
105
|
+
_strip_code_block( sect )
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def _strip_empty_trailing_lines( sect )
|
110
|
+
loop do
|
111
|
+
line = sect[-1]
|
112
|
+
if line && line.empty?
|
113
|
+
sect.pop
|
114
|
+
else
|
115
|
+
break
|
116
|
+
end
|
117
|
+
end
|
118
|
+
sect
|
119
|
+
end
|
120
|
+
|
121
|
+
def _strip_empty_leading_lines( sect )
|
122
|
+
loop do
|
123
|
+
line = sect[0]
|
124
|
+
if line && line.empty?
|
125
|
+
sect.shift
|
126
|
+
else
|
127
|
+
break
|
128
|
+
end
|
129
|
+
end
|
130
|
+
sect
|
131
|
+
end
|
132
|
+
end # class Parser
|
133
|
+
|
134
|
+
|
135
|
+
def self.read( path )
|
136
|
+
Parser.new( read_text( path ) ).parse
|
137
|
+
end
|
138
|
+
|
139
|
+
end # module Natspec
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: natspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rdoc
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.23'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.23'
|
47
|
+
description: natspec - natural specification (comments) parser / machinery; document
|
48
|
+
application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts
|
49
|
+
email: wwwmake@googlegroups.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- CHANGELOG.md
|
54
|
+
- Manifest.txt
|
55
|
+
- README.md
|
56
|
+
files:
|
57
|
+
- CHANGELOG.md
|
58
|
+
- Manifest.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/natspec.rb
|
62
|
+
homepage: https://github.com/rubycocos/blockchain
|
63
|
+
licenses:
|
64
|
+
- Public Domain
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- "--main"
|
69
|
+
- README.md
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.3'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: natspec - natural specification (comments) parser / machinery; document application
|
87
|
+
binary interfaces (abis) for Ethereum & Co. (blockchain) contracts
|
88
|
+
test_files: []
|