comment_strip-ruby 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 365f9e298b8b89aa08070e00af4b79218bff7a4f
4
+ data.tar.gz: ab83b0154b585c48128815611fb7d095d2bcb111
5
+ SHA512:
6
+ metadata.gz: b2330a16d54e0b3675d76883fb85a03e970ba59aedc37e232763a2b999efae4b10a53ce6fcabb317f3606dfe0e45fa38be3670792e88462fddadcd10a5a4819b
7
+ data.tar.gz: a5f0d316237a029cba4cd959ba8276147192cb7d62226654806ad08f60fb9c8d482c8f192ab8f010152250d8dafdf7ab3313846e4c673ae5e845a24677d83e2e
data/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ comment_strip.r
2
+
3
+ Copyright (c) 2021, Matthew Wilson and Synesis Information Systems
4
+ Copyright (c) 2008-2019, Matthew Wilson and Synesis Software
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ * Neither the name of xqsr3 nor the names of its
18
+ contributors may be used to endorse or promote products derived from
19
+ this software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # comment_strip.r
2
+ Comment Strip for Ruby
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/comment_strip-ruby.svg)](https://badge.fury.io/rb/comment_strip-ruby)
5
+
6
+ ## Introduction
7
+
8
+ T.B.C.
9
+
10
+ ## Table of Contents
11
+
12
+ 1. [Introduction](#introduction)
13
+ 2. [Installation](#installation)
14
+ 3. [Components](#components)
15
+ 4. [Project Information](#project-information)
16
+
17
+ ## Installation
18
+
19
+ Install using `gem install comment_strip-ruby` or add it to your `Gemfile`.
20
+
21
+ ## Components
22
+
23
+ T.B.C.
24
+
25
+ ## Examples
26
+
27
+ T.B.C.
28
+
29
+ ## Project Information
30
+
31
+ ### Where to get help
32
+
33
+ [GitHub Page](https://github.com/synesissoftware/comment_strip.r "GitHub Page")
34
+
35
+ ### Contribution guidelines
36
+
37
+ Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/comment_strip.r.
38
+
39
+ ### Related projects
40
+
41
+ T.B.C.
42
+
43
+ ### License
44
+
45
+ **comment_strip.r** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
46
+
@@ -0,0 +1,46 @@
1
+ # ######################################################################## #
2
+ # File: comment_strip.rb
3
+ #
4
+ # Purpose: Top-level include for comment_strip.r library
5
+ #
6
+ # Created: 14th September 2020
7
+ # Updated: 14th September 2020
8
+ #
9
+ # Home: http://github.com/synesissoftware/comment_strip.r
10
+ #
11
+ # Copyright (c) 2020, Matthew Wilson and Synesis Information Systems
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are
16
+ # met:
17
+ #
18
+ # * Redistributions of source code must retain the above copyright notice,
19
+ # this list of conditions and the following disclaimer.
20
+ #
21
+ # * Redistributions in binary form must reproduce the above copyright
22
+ # notice, this list of conditions and the following disclaimer in the
23
+ # documentation and/or other materials provided with the distribution.
24
+ #
25
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ #
37
+ # ######################################################################## #
38
+
39
+
40
+ =begin
41
+ =end
42
+
43
+ require File.join(File.dirname(__FILE__), 'comment_strip', 'comment_strip')
44
+
45
+ # ############################## end of file ############################# #
46
+
@@ -0,0 +1,52 @@
1
+ # ######################################################################## #
2
+ # File: comment_strip/comment_strip.rb
3
+ #
4
+ # Purpose: Main file for comment_strip.r library
5
+ #
6
+ # Created: 14th September 2020
7
+ # Updated: 14th September 2020
8
+ #
9
+ # Home: http://github.com/synesissoftware/comment_strip.r
10
+ #
11
+ # Copyright (c) 2020, Matthew Wilson and Synesis Information Systems
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are
16
+ # met:
17
+ #
18
+ # * Redistributions of source code must retain the above copyright notice,
19
+ # this list of conditions and the following disclaimer.
20
+ #
21
+ # * Redistributions in binary form must reproduce the above copyright
22
+ # notice, this list of conditions and the following disclaimer in the
23
+ # documentation and/or other materials provided with the distribution.
24
+ #
25
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ #
37
+ # ######################################################################## #
38
+
39
+
40
+ require File.join(File.dirname(__FILE__), 'strip')
41
+ require File.join(File.dirname(__FILE__), 'version')
42
+
43
+ =begin
44
+ =end
45
+
46
+ # Main module for comment_strip.r library
47
+ module CommentStrip
48
+ end # module CommentStrip
49
+
50
+ # ############################## end of file ############################# #
51
+
52
+
@@ -0,0 +1,253 @@
1
+ # ######################################################################## #
2
+ # File: comment_strip/strip.rb
3
+ #
4
+ # Purpose: Definition of strip() function
5
+ #
6
+ # Created: 14th September 2020
7
+ # Updated: 14th September 2020
8
+ #
9
+ # Home: http://github.com/synesissoftware/comment_strip.r
10
+ #
11
+ # Copyright (c) 2020, Matthew Wilson and Synesis Information Systems
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are
16
+ # met:
17
+ #
18
+ # * Redistributions of source code must retain the above copyright notice,
19
+ # this list of conditions and the following disclaimer.
20
+ #
21
+ # * Redistributions in binary form must reproduce the above copyright
22
+ # notice, this list of conditions and the following disclaimer in the
23
+ # documentation and/or other materials provided with the distribution.
24
+ #
25
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ #
37
+ # ######################################################################## #
38
+
39
+
40
+
41
+ =begin
42
+ =end
43
+
44
+ module CommentStrip
45
+
46
+ # Strips comments
47
+ def strip s, lf, *options
48
+
49
+ case lf.upcase
50
+ when 'C'
51
+
52
+ ;
53
+ else
54
+
55
+ raise "language family '#{lf}' unrecognised"
56
+ end
57
+
58
+ return nil if s.nil?
59
+ return s if s.empty?
60
+
61
+ line = 0
62
+ column = 0
63
+
64
+ state = :text
65
+
66
+ r = ''
67
+
68
+ cc_lines = 0
69
+
70
+ s.each_char do |c|
71
+
72
+ case c
73
+ when ?\r, ?\n
74
+
75
+ line += 1
76
+ column = 0
77
+ else
78
+
79
+ column += 1
80
+ end
81
+
82
+ skip = false
83
+
84
+ case c
85
+ when ?\r, ?\n
86
+
87
+ case state
88
+ when :c_comment, :c_comment_star
89
+
90
+ cc_lines += 1
91
+
92
+ state = :c_comment
93
+ when :cpp_comment
94
+
95
+ state = :text
96
+ when :sq_string, :sq_string_escape, :sq_string_closing
97
+
98
+ state = :text
99
+ when :dq_string_escape
100
+
101
+ state = :dq_string
102
+ when :slash_start
103
+
104
+ r << '/'
105
+
106
+ state = :text
107
+ end
108
+ else
109
+
110
+ # special cases:
111
+ #
112
+ # - for escaped single/double quote
113
+ # - for slash-start
114
+ # - for comment-star
115
+
116
+ case state
117
+ when :sq_string_open
118
+
119
+ state = (?\\ == c) ? :sq_string_escape : :sq_string_closing
120
+ when :sq_string_escape
121
+
122
+ state = :sq_string_closing
123
+ when :dq_string_escape
124
+
125
+ state = :dq_string
126
+ when :c_comment_star
127
+
128
+ case c
129
+ when ?/
130
+
131
+ r << ?\n * cc_lines
132
+ cc_lines = 0
133
+
134
+ state = :text
135
+ skip = true
136
+ when '*'
137
+
138
+ ;
139
+ else
140
+
141
+ state = :c_comment
142
+ end
143
+ else
144
+
145
+ if false
146
+ elsif state == :slash_start && ('/' != c && '*' != c)
147
+
148
+ state = :text
149
+ r << '/'
150
+ else
151
+
152
+ case c
153
+ when '/'
154
+
155
+ case state
156
+ when :text
157
+
158
+ state = :slash_start
159
+ when :slash_start
160
+
161
+ state = :cpp_comment
162
+ when :c_comment_star
163
+
164
+ r << ?\n * cc_lines
165
+ cc_lines = 0
166
+
167
+ state = :text
168
+ skip = true
169
+ end
170
+ when '*'
171
+
172
+ case state
173
+ when :slash_start
174
+
175
+ state = :c_comment
176
+ when :c_comment
177
+
178
+ state = :c_comment_star
179
+ else
180
+
181
+ end
182
+
183
+ when ?\'
184
+
185
+ case state
186
+ when :text
187
+
188
+ state = :sq_string_open
189
+ when :sq_string_closing
190
+
191
+ state = :text
192
+ else
193
+
194
+ end
195
+ when '"'
196
+
197
+ case state
198
+ when :text
199
+
200
+ state = :dq_string
201
+ when :dq_string
202
+
203
+ state = :text
204
+ else
205
+ end
206
+ when ?\\
207
+
208
+ case state
209
+ when :sq_string_open
210
+
211
+ state = :sq_string_escape
212
+ when :sq_string_escape
213
+
214
+ state = :sq_string
215
+ when :dq_string
216
+
217
+ state = :dq_string_escape
218
+ else
219
+
220
+ end
221
+ else
222
+
223
+ case state
224
+ when :sq_string_escape
225
+
226
+ state = :sq_string_closing
227
+ else
228
+
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ case state
236
+ when :slash_start
237
+ when :cpp_comment
238
+ when :c_comment
239
+ when :c_comment_star
240
+
241
+ else
242
+
243
+ r << c unless skip
244
+ end
245
+ end
246
+
247
+ r
248
+ end
249
+
250
+ end # module CommentStrip
251
+
252
+ # ############################## end of file ############################# #
253
+
@@ -0,0 +1,62 @@
1
+ # ######################################################################## #
2
+ # File: comment_strip/version.rb
3
+ #
4
+ # Purpose: Version for comment_strip.r library
5
+ #
6
+ # Created: 14th September 2020
7
+ # Updated: 14th September 2020
8
+ #
9
+ # Home: http://github.com/synesissoftware/comment_strip.r
10
+ #
11
+ # Copyright (c) 2020, Matthew Wilson and Synesis Information Systems
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are
16
+ # met:
17
+ #
18
+ # * Redistributions of source code must retain the above copyright notice,
19
+ # this list of conditions and the following disclaimer.
20
+ #
21
+ # * Redistributions in binary form must reproduce the above copyright
22
+ # notice, this list of conditions and the following disclaimer in the
23
+ # documentation and/or other materials provided with the distribution.
24
+ #
25
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
26
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+ #
37
+ # ######################################################################## #
38
+
39
+
40
+ =begin
41
+ =end
42
+
43
+ module CommentStrip
44
+
45
+ # Current version of the comment_strip.r library
46
+ VERSION = '0.0.13'
47
+
48
+ private
49
+ VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
50
+ public
51
+ # Major version of the comment_strip.r library
52
+ VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
53
+ # # Minor version of the comment_strip.r library
54
+ VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
55
+ # # Revision version of the comment_strip.r library
56
+ VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
57
+
58
+ end # module CommentStrip
59
+
60
+ # ############################## end of file ############################# #
61
+
62
+