kicad 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +2 -17
- data/README.md +2 -8
- data/kicad.gemspec +1 -1
- data/lib/kicad/grammar.rb +539 -0
- data/lib/kicad/grammar.tt +4 -5
- data/lib/kicad/parser.rb +1 -1
- data/lib/kicad/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 679cc2e86c98081d38458ec0503b64fc176dec709a412bcc8fcee6ff1ccc9fbc
|
4
|
+
data.tar.gz: 5c4c4d2e0fa767c8c9c841f3235f7124c6f81b4aef66841e24c0e652b17dad52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae34e7b3091ed815b836ca0f5f3f9f73ba5c622411279122f436949bb1a9e372c5d440795ba1f494cec5f5033a51f65578405c574ff70591a3db42640d5d7011
|
7
|
+
data.tar.gz: 8cf7ebfc425f27b4bd89389db45c6f3528236dd2c534b930a3102f5d06931ab383883db724d898f7eb67d518fdb5127aa384d91df74ef6fe03f59269f050d7d1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kicad (0.8.
|
4
|
+
kicad (0.8.1)
|
5
5
|
irb (~> 1.14, >= 1.14)
|
6
6
|
treetop (~> 1.6, >= 1.6.9)
|
7
7
|
|
@@ -9,7 +9,6 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
date (3.4.1)
|
12
|
-
diff-lcs (1.6.1)
|
13
12
|
io-console (0.8.0)
|
14
13
|
irb (1.15.2)
|
15
14
|
pp (>= 0.6.0)
|
@@ -27,19 +26,6 @@ GEM
|
|
27
26
|
psych (>= 4.0.0)
|
28
27
|
reline (0.6.1)
|
29
28
|
io-console (~> 0.5)
|
30
|
-
rspec (3.13.0)
|
31
|
-
rspec-core (~> 3.13.0)
|
32
|
-
rspec-expectations (~> 3.13.0)
|
33
|
-
rspec-mocks (~> 3.13.0)
|
34
|
-
rspec-core (3.13.3)
|
35
|
-
rspec-support (~> 3.13.0)
|
36
|
-
rspec-expectations (3.13.4)
|
37
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.13.0)
|
39
|
-
rspec-mocks (3.13.3)
|
40
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.13.0)
|
42
|
-
rspec-support (3.13.3)
|
43
29
|
stringio (3.1.7)
|
44
30
|
treetop (1.6.14)
|
45
31
|
polyglot (~> 0.3)
|
@@ -51,8 +37,7 @@ PLATFORMS
|
|
51
37
|
DEPENDENCIES
|
52
38
|
bundler (>= 1.11)
|
53
39
|
kicad!
|
54
|
-
rake (
|
55
|
-
rspec (~> 3.3)
|
40
|
+
rake (~> 13)
|
56
41
|
|
57
42
|
BUNDLED WITH
|
58
43
|
2.6.2
|
data/README.md
CHANGED
@@ -4,19 +4,13 @@ Parse, load, modify and rewrite Kicad (s-epression) files into a convenient tree
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
```ruby
|
8
|
-
gem 'kicad'
|
9
|
-
```
|
10
|
-
|
11
|
-
or
|
12
|
-
|
13
7
|
gem install kicad
|
14
8
|
|
15
9
|
## Usage
|
16
10
|
|
17
11
|
$ irb -r kicad
|
18
|
-
irb(main):001> k = KiCad.load("my_file.
|
19
|
-
irb(main):001> k.children.filter{|c|
|
12
|
+
irb(main):001> k = KiCad.load("my_file.kicad_sym").value
|
13
|
+
irb(main):001> k.children.filter{|c| KiCad::AST::Symbol === c }.map{|c| c.values[1]}
|
20
14
|
["BC107", "CD4046"]
|
21
15
|
irb(main):001> puts k.emit
|
22
16
|
...
|
data/kicad.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "
|
23
|
+
spec.add_development_dependency "bundler", ">= 1.11"
|
24
24
|
spec.add_development_dependency "rake", "~> 13"
|
25
25
|
|
26
26
|
spec.add_runtime_dependency "treetop", ["~> 1.6", ">= 1.6.9"]
|
@@ -0,0 +1,539 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
require 'kicad/ast'
|
5
|
+
|
6
|
+
module KiCad
|
7
|
+
module SExpr
|
8
|
+
include Treetop::Runtime
|
9
|
+
|
10
|
+
def root
|
11
|
+
@root ||= :node
|
12
|
+
end
|
13
|
+
|
14
|
+
module Node0
|
15
|
+
def value
|
16
|
+
elements[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
def s
|
20
|
+
elements[1]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Node1
|
25
|
+
def node
|
26
|
+
elements[0]
|
27
|
+
end
|
28
|
+
|
29
|
+
def s
|
30
|
+
elements[1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Node2
|
35
|
+
def s1
|
36
|
+
elements[1]
|
37
|
+
end
|
38
|
+
|
39
|
+
def values
|
40
|
+
elements[2]
|
41
|
+
end
|
42
|
+
|
43
|
+
def nodes
|
44
|
+
elements[3]
|
45
|
+
end
|
46
|
+
|
47
|
+
def s2
|
48
|
+
elements[5]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module Node3
|
53
|
+
def value
|
54
|
+
klass_name = values.elements[0].value.value
|
55
|
+
klass = KiCad::AST::Node
|
56
|
+
if klass_name.is_a? ::Symbol # See if we have a defined class for this node type
|
57
|
+
klass_name = klass_name.to_s.gsub(/\A[a-z]|_[a-z]/) {|from| from[-1].upcase }
|
58
|
+
klass = KiCad::AST.const_get(klass_name, false) rescue KiCad::AST::Node
|
59
|
+
end
|
60
|
+
klass.new values.elements.map(&:value).map(&:value),
|
61
|
+
nodes.elements.map(&:node).map(&:value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def _nt_node
|
66
|
+
start_index = index
|
67
|
+
if node_cache[:node].has_key?(index)
|
68
|
+
cached = node_cache[:node][index]
|
69
|
+
if cached
|
70
|
+
node_cache[:node][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
71
|
+
@index = cached.interval.end
|
72
|
+
end
|
73
|
+
return cached
|
74
|
+
end
|
75
|
+
|
76
|
+
i0, s0 = index, []
|
77
|
+
if (match_len = has_terminal?('(', false, index))
|
78
|
+
r1 = true
|
79
|
+
@index += match_len
|
80
|
+
else
|
81
|
+
terminal_parse_failure('\'(\'')
|
82
|
+
r1 = nil
|
83
|
+
end
|
84
|
+
s0 << r1
|
85
|
+
if r1
|
86
|
+
r2 = _nt_s
|
87
|
+
s0 << r2
|
88
|
+
if r2
|
89
|
+
s3, i3 = [], index
|
90
|
+
loop do
|
91
|
+
i4, s4 = index, []
|
92
|
+
r5 = _nt_value
|
93
|
+
s4 << r5
|
94
|
+
if r5
|
95
|
+
r6 = _nt_s
|
96
|
+
s4 << r6
|
97
|
+
end
|
98
|
+
if s4.last
|
99
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
100
|
+
r4.extend(Node0)
|
101
|
+
else
|
102
|
+
@index = i4
|
103
|
+
r4 = nil
|
104
|
+
end
|
105
|
+
if r4
|
106
|
+
s3 << r4
|
107
|
+
else
|
108
|
+
break
|
109
|
+
end
|
110
|
+
end
|
111
|
+
if s3.empty?
|
112
|
+
@index = i3
|
113
|
+
r3 = nil
|
114
|
+
else
|
115
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
116
|
+
end
|
117
|
+
s0 << r3
|
118
|
+
if r3
|
119
|
+
s7, i7 = [], index
|
120
|
+
loop do
|
121
|
+
i8, s8 = index, []
|
122
|
+
r9 = _nt_node
|
123
|
+
s8 << r9
|
124
|
+
if r9
|
125
|
+
r10 = _nt_s
|
126
|
+
s8 << r10
|
127
|
+
end
|
128
|
+
if s8.last
|
129
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
130
|
+
r8.extend(Node1)
|
131
|
+
else
|
132
|
+
@index = i8
|
133
|
+
r8 = nil
|
134
|
+
end
|
135
|
+
if r8
|
136
|
+
s7 << r8
|
137
|
+
else
|
138
|
+
break
|
139
|
+
end
|
140
|
+
end
|
141
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
142
|
+
s0 << r7
|
143
|
+
if r7
|
144
|
+
if (match_len = has_terminal?(')', false, index))
|
145
|
+
r11 = true
|
146
|
+
@index += match_len
|
147
|
+
else
|
148
|
+
terminal_parse_failure('\')\'')
|
149
|
+
r11 = nil
|
150
|
+
end
|
151
|
+
s0 << r11
|
152
|
+
if r11
|
153
|
+
r12 = _nt_s
|
154
|
+
s0 << r12
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
if s0.last
|
161
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
162
|
+
r0.extend(Node2)
|
163
|
+
r0.extend(Node3)
|
164
|
+
else
|
165
|
+
@index = i0
|
166
|
+
r0 = nil
|
167
|
+
end
|
168
|
+
|
169
|
+
node_cache[:node][start_index] = r0
|
170
|
+
|
171
|
+
r0
|
172
|
+
end
|
173
|
+
|
174
|
+
def _nt_value
|
175
|
+
start_index = index
|
176
|
+
if node_cache[:value].has_key?(index)
|
177
|
+
cached = node_cache[:value][index]
|
178
|
+
if cached
|
179
|
+
node_cache[:value][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
180
|
+
@index = cached.interval.end
|
181
|
+
end
|
182
|
+
return cached
|
183
|
+
end
|
184
|
+
|
185
|
+
i0 = index
|
186
|
+
r1 = _nt_string
|
187
|
+
if r1
|
188
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
189
|
+
r0 = r1
|
190
|
+
else
|
191
|
+
r2 = _nt_number
|
192
|
+
if r2
|
193
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
194
|
+
r0 = r2
|
195
|
+
else
|
196
|
+
r3 = _nt_symbol
|
197
|
+
if r3
|
198
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
199
|
+
r0 = r3
|
200
|
+
else
|
201
|
+
@index = i0
|
202
|
+
r0 = nil
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
node_cache[:value][start_index] = r0
|
208
|
+
|
209
|
+
r0
|
210
|
+
end
|
211
|
+
|
212
|
+
module Symbol0
|
213
|
+
def value; :"#{text_value}"; end
|
214
|
+
end
|
215
|
+
|
216
|
+
def _nt_symbol
|
217
|
+
start_index = index
|
218
|
+
if node_cache[:symbol].has_key?(index)
|
219
|
+
cached = node_cache[:symbol][index]
|
220
|
+
if cached
|
221
|
+
node_cache[:symbol][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
222
|
+
@index = cached.interval.end
|
223
|
+
end
|
224
|
+
return cached
|
225
|
+
end
|
226
|
+
|
227
|
+
s0, i0 = [], index
|
228
|
+
loop do
|
229
|
+
if has_terminal?(@regexps[gr = '\A[a-zA-Z_]'] ||= Regexp.new(gr), :regexp, index)
|
230
|
+
r1 = true
|
231
|
+
@index += 1
|
232
|
+
else
|
233
|
+
terminal_parse_failure('[a-zA-Z_]')
|
234
|
+
r1 = nil
|
235
|
+
end
|
236
|
+
if r1
|
237
|
+
s0 << r1
|
238
|
+
else
|
239
|
+
break
|
240
|
+
end
|
241
|
+
end
|
242
|
+
if s0.empty?
|
243
|
+
@index = i0
|
244
|
+
r0 = nil
|
245
|
+
else
|
246
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
247
|
+
r0.extend(Symbol0)
|
248
|
+
r0.extend(Symbol0)
|
249
|
+
end
|
250
|
+
|
251
|
+
node_cache[:symbol][start_index] = r0
|
252
|
+
|
253
|
+
r0
|
254
|
+
end
|
255
|
+
|
256
|
+
module String0
|
257
|
+
end
|
258
|
+
|
259
|
+
module String1
|
260
|
+
def contents
|
261
|
+
elements[1]
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
module String2
|
267
|
+
def value; contents.text_value.force_encoding(Encoding::UTF_8); end
|
268
|
+
end
|
269
|
+
|
270
|
+
def _nt_string
|
271
|
+
start_index = index
|
272
|
+
if node_cache[:string].has_key?(index)
|
273
|
+
cached = node_cache[:string][index]
|
274
|
+
if cached
|
275
|
+
node_cache[:string][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
276
|
+
@index = cached.interval.end
|
277
|
+
end
|
278
|
+
return cached
|
279
|
+
end
|
280
|
+
|
281
|
+
i0, s0 = index, []
|
282
|
+
if (match_len = has_terminal?('"', false, index))
|
283
|
+
r1 = true
|
284
|
+
@index += match_len
|
285
|
+
else
|
286
|
+
terminal_parse_failure('\'"\'')
|
287
|
+
r1 = nil
|
288
|
+
end
|
289
|
+
s0 << r1
|
290
|
+
if r1
|
291
|
+
s2, i2 = [], index
|
292
|
+
loop do
|
293
|
+
i3 = index
|
294
|
+
if (match_len = has_terminal?('\\"', false, index))
|
295
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
296
|
+
@index += match_len
|
297
|
+
else
|
298
|
+
terminal_parse_failure('\'\\\\"\'')
|
299
|
+
r4 = nil
|
300
|
+
end
|
301
|
+
if r4
|
302
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
303
|
+
r3 = r4
|
304
|
+
else
|
305
|
+
i5, s5 = index, []
|
306
|
+
i6 = index
|
307
|
+
if (match_len = has_terminal?('"', false, index))
|
308
|
+
r7 = true
|
309
|
+
@index += match_len
|
310
|
+
else
|
311
|
+
terminal_parse_failure('\'"\'')
|
312
|
+
r7 = nil
|
313
|
+
end
|
314
|
+
if r7
|
315
|
+
@index = i6
|
316
|
+
r6 = nil
|
317
|
+
terminal_parse_failure('\'"\'', true)
|
318
|
+
else
|
319
|
+
@terminal_failures.pop
|
320
|
+
@index = i6
|
321
|
+
r6 = instantiate_node(SyntaxNode,input, index...index)
|
322
|
+
end
|
323
|
+
s5 << r6
|
324
|
+
if r6
|
325
|
+
if index < input_length
|
326
|
+
r8 = true
|
327
|
+
@index += 1
|
328
|
+
else
|
329
|
+
terminal_parse_failure("any character")
|
330
|
+
r8 = nil
|
331
|
+
end
|
332
|
+
s5 << r8
|
333
|
+
end
|
334
|
+
if s5.last
|
335
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
336
|
+
r5.extend(String0)
|
337
|
+
else
|
338
|
+
@index = i5
|
339
|
+
r5 = nil
|
340
|
+
end
|
341
|
+
if r5
|
342
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
343
|
+
r3 = r5
|
344
|
+
else
|
345
|
+
@index = i3
|
346
|
+
r3 = nil
|
347
|
+
end
|
348
|
+
end
|
349
|
+
if r3
|
350
|
+
s2 << r3
|
351
|
+
else
|
352
|
+
break
|
353
|
+
end
|
354
|
+
end
|
355
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
356
|
+
s0 << r2
|
357
|
+
if r2
|
358
|
+
if (match_len = has_terminal?('"', false, index))
|
359
|
+
r9 = true
|
360
|
+
@index += match_len
|
361
|
+
else
|
362
|
+
terminal_parse_failure('\'"\'')
|
363
|
+
r9 = nil
|
364
|
+
end
|
365
|
+
s0 << r9
|
366
|
+
end
|
367
|
+
end
|
368
|
+
if s0.last
|
369
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
370
|
+
r0.extend(String1)
|
371
|
+
r0.extend(String2)
|
372
|
+
else
|
373
|
+
@index = i0
|
374
|
+
r0 = nil
|
375
|
+
end
|
376
|
+
|
377
|
+
node_cache[:string][start_index] = r0
|
378
|
+
|
379
|
+
r0
|
380
|
+
end
|
381
|
+
|
382
|
+
module Number0
|
383
|
+
end
|
384
|
+
|
385
|
+
module Number1
|
386
|
+
end
|
387
|
+
|
388
|
+
module Number2
|
389
|
+
def value; eval(text_value); end
|
390
|
+
end
|
391
|
+
|
392
|
+
def _nt_number
|
393
|
+
start_index = index
|
394
|
+
if node_cache[:number].has_key?(index)
|
395
|
+
cached = node_cache[:number][index]
|
396
|
+
if cached
|
397
|
+
node_cache[:number][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
398
|
+
@index = cached.interval.end
|
399
|
+
end
|
400
|
+
return cached
|
401
|
+
end
|
402
|
+
|
403
|
+
i0, s0 = index, []
|
404
|
+
if (match_len = has_terminal?('-', false, index))
|
405
|
+
r2 = true
|
406
|
+
@index += match_len
|
407
|
+
else
|
408
|
+
terminal_parse_failure('\'-\'')
|
409
|
+
r2 = nil
|
410
|
+
end
|
411
|
+
if r2
|
412
|
+
r1 = r2
|
413
|
+
else
|
414
|
+
r1 = instantiate_node(SyntaxNode,input, index...index)
|
415
|
+
end
|
416
|
+
s0 << r1
|
417
|
+
if r1
|
418
|
+
s3, i3 = [], index
|
419
|
+
loop do
|
420
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
421
|
+
r4 = true
|
422
|
+
@index += 1
|
423
|
+
else
|
424
|
+
terminal_parse_failure('[0-9]')
|
425
|
+
r4 = nil
|
426
|
+
end
|
427
|
+
if r4
|
428
|
+
s3 << r4
|
429
|
+
else
|
430
|
+
break
|
431
|
+
end
|
432
|
+
end
|
433
|
+
if s3.empty?
|
434
|
+
@index = i3
|
435
|
+
r3 = nil
|
436
|
+
else
|
437
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
438
|
+
end
|
439
|
+
s0 << r3
|
440
|
+
if r3
|
441
|
+
i6, s6 = index, []
|
442
|
+
if (match_len = has_terminal?('.', false, index))
|
443
|
+
r7 = true
|
444
|
+
@index += match_len
|
445
|
+
else
|
446
|
+
terminal_parse_failure('\'.\'')
|
447
|
+
r7 = nil
|
448
|
+
end
|
449
|
+
s6 << r7
|
450
|
+
if r7
|
451
|
+
s8, i8 = [], index
|
452
|
+
loop do
|
453
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
454
|
+
r9 = true
|
455
|
+
@index += 1
|
456
|
+
else
|
457
|
+
terminal_parse_failure('[0-9]')
|
458
|
+
r9 = nil
|
459
|
+
end
|
460
|
+
if r9
|
461
|
+
s8 << r9
|
462
|
+
else
|
463
|
+
break
|
464
|
+
end
|
465
|
+
end
|
466
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
467
|
+
s6 << r8
|
468
|
+
end
|
469
|
+
if s6.last
|
470
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
471
|
+
r6.extend(Number0)
|
472
|
+
else
|
473
|
+
@index = i6
|
474
|
+
r6 = nil
|
475
|
+
end
|
476
|
+
if r6
|
477
|
+
r5 = r6
|
478
|
+
else
|
479
|
+
r5 = instantiate_node(SyntaxNode,input, index...index)
|
480
|
+
end
|
481
|
+
s0 << r5
|
482
|
+
end
|
483
|
+
end
|
484
|
+
if s0.last
|
485
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
486
|
+
r0.extend(Number1)
|
487
|
+
r0.extend(Number2)
|
488
|
+
else
|
489
|
+
@index = i0
|
490
|
+
r0 = nil
|
491
|
+
end
|
492
|
+
|
493
|
+
node_cache[:number][start_index] = r0
|
494
|
+
|
495
|
+
r0
|
496
|
+
end
|
497
|
+
|
498
|
+
def _nt_s
|
499
|
+
start_index = index
|
500
|
+
if node_cache[:s].has_key?(index)
|
501
|
+
cached = node_cache[:s][index]
|
502
|
+
if cached
|
503
|
+
node_cache[:s][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
504
|
+
@index = cached.interval.end
|
505
|
+
end
|
506
|
+
return cached
|
507
|
+
end
|
508
|
+
|
509
|
+
s0, i0 = [], index
|
510
|
+
loop do
|
511
|
+
if has_terminal?(@regexps[gr = '\A[ \\t\\r\\n]'] ||= Regexp.new(gr), :regexp, index)
|
512
|
+
r1 = true
|
513
|
+
@index += 1
|
514
|
+
else
|
515
|
+
terminal_parse_failure('[ \\t\\r\\n]')
|
516
|
+
r1 = nil
|
517
|
+
end
|
518
|
+
if r1
|
519
|
+
s0 << r1
|
520
|
+
else
|
521
|
+
break
|
522
|
+
end
|
523
|
+
end
|
524
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
525
|
+
|
526
|
+
node_cache[:s][start_index] = r0
|
527
|
+
|
528
|
+
r0
|
529
|
+
end
|
530
|
+
|
531
|
+
|
532
|
+
class Parser < Treetop::Runtime::CompiledParser
|
533
|
+
include SExpr
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
SExprParser = SExpr::Parser
|
538
|
+
|
539
|
+
end
|
data/lib/kicad/grammar.tt
CHANGED
@@ -7,9 +7,8 @@ module KiCad
|
|
7
7
|
{ def value
|
8
8
|
klass_name = values.elements[0].value.value
|
9
9
|
klass = KiCad::AST::Node
|
10
|
-
if klass_name.is_a? ::Symbol
|
11
|
-
|
12
|
-
klass_name = klass_name.to_s.gsub(/\A[a-z]|_[a-z]/) {|from| from[-1].upcase }
|
10
|
+
if klass_name.is_a? ::Symbol # See if we have a defined class for this node type
|
11
|
+
klass_name = klass_name.to_s.gsub(/\A[a-z]|_[a-z]/) {|from| from[-1].upcase }
|
13
12
|
klass = KiCad::AST.const_get(klass_name, false) rescue KiCad::AST::Node
|
14
13
|
end
|
15
14
|
klass.new values.elements.map(&:value).map(&:value),
|
@@ -28,8 +27,8 @@ module KiCad
|
|
28
27
|
end
|
29
28
|
|
30
29
|
rule string
|
31
|
-
'"' ('\\"' / !'"' .)* '"'
|
32
|
-
{ def value;
|
30
|
+
'"' contents:( ('\\"' / !'"' .)* ) '"'
|
31
|
+
{ def value; contents.text_value.force_encoding(Encoding::UTF_8); end }
|
33
32
|
end
|
34
33
|
|
35
34
|
rule number
|
data/lib/kicad/parser.rb
CHANGED
data/lib/kicad/version.rb
CHANGED
metadata
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kicad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clifford Heath
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- - "
|
16
|
+
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: '1.11'
|
19
19
|
type: :development
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
|
-
- - "
|
23
|
+
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '1.11'
|
26
26
|
- !ruby/object:Gem::Dependency
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- kicad.gemspec
|
93
93
|
- lib/kicad.rb
|
94
94
|
- lib/kicad/ast.rb
|
95
|
+
- lib/kicad/grammar.rb
|
95
96
|
- lib/kicad/grammar.tt
|
96
97
|
- lib/kicad/parser.rb
|
97
98
|
- lib/kicad/version.rb
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
requirements: []
|
116
|
-
rubygems_version: 3.6.
|
117
|
+
rubygems_version: 3.6.8
|
117
118
|
specification_version: 4
|
118
119
|
summary: Load and rewrite Kicad s-expression files into a tree structure for scripting
|
119
120
|
test_files: []
|