kicad 0.8.0
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +58 -0
- data/README.md +37 -0
- data/Rakefile +23 -0
- data/kicad.gemspec +28 -0
- data/lib/kicad/ast.rb +146 -0
- data/lib/kicad/grammar.tt +44 -0
- data/lib/kicad/parser.rb +20 -0
- data/lib/kicad/version.rb +3 -0
- data/lib/kicad.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ea6528c30596177b5286780246f20331ff0a82109b527d0c311e5aca88d6b42
|
4
|
+
data.tar.gz: b439278fbd1dd60ff5f931f67d7f6009517b179937b16cf0998de12beb3d8e1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57e43e2a123bb69b0497b7fd62cf66a54e5fcec279b3047dfdc7701bf8ae7016c33bfdc63fb298c28628a90a6e232b601e2eb0729495d8c4c8b4000dd9bb13f7
|
7
|
+
data.tar.gz: 7a4474f86498962aa00c14aee3dc89a4a8c7d0d73aa66eee185cd526928b0286fd15a08762cd8604ce1fdcde651c65ed3348ba1a3e960c3bf5e034ca19d78871
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kicad (0.8.0)
|
5
|
+
irb (~> 1.14, >= 1.14)
|
6
|
+
treetop (~> 1.6, >= 1.6.9)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
date (3.4.1)
|
12
|
+
diff-lcs (1.6.1)
|
13
|
+
io-console (0.8.0)
|
14
|
+
irb (1.15.2)
|
15
|
+
pp (>= 0.6.0)
|
16
|
+
rdoc (>= 4.0.0)
|
17
|
+
reline (>= 0.4.2)
|
18
|
+
polyglot (0.3.5)
|
19
|
+
pp (0.6.2)
|
20
|
+
prettyprint
|
21
|
+
prettyprint (0.2.0)
|
22
|
+
psych (5.2.4)
|
23
|
+
date
|
24
|
+
stringio
|
25
|
+
rake (13.2.1)
|
26
|
+
rdoc (6.13.1)
|
27
|
+
psych (>= 4.0.0)
|
28
|
+
reline (0.6.1)
|
29
|
+
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
|
+
stringio (3.1.7)
|
44
|
+
treetop (1.6.14)
|
45
|
+
polyglot (~> 0.3)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
x86_64-darwin-22
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
bundler (>= 1.11)
|
53
|
+
kicad!
|
54
|
+
rake (>= 13)
|
55
|
+
rspec (~> 3.3)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.6.2
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# KiCad
|
2
|
+
|
3
|
+
Parse, load, modify and rewrite Kicad (s-epression) files into a convenient tree structure for scripting
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'kicad'
|
9
|
+
```
|
10
|
+
|
11
|
+
or
|
12
|
+
|
13
|
+
gem install kicad
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
$ irb -r kicad
|
18
|
+
irb(main):001> k = KiCad.load("my_file.kicad_lib").value
|
19
|
+
irb(main):001> k.children.filter{|c| c === KiCad::AST::Symbol}.map{|c| c.values[1]}
|
20
|
+
["BC107", "CD4046"]
|
21
|
+
irb(main):001> puts k.emit
|
22
|
+
...
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests.
|
27
|
+
|
28
|
+
To install this gem onto your local machine from local source code, run `rake install`.
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cjheath/kicad-rb
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
desc "Bump gem version patch number"
|
9
|
+
task :bump do
|
10
|
+
path = File.expand_path('../lib/kicad/version.rb', __FILE__)
|
11
|
+
lines = File.open(path) do |fp| fp.readlines; end
|
12
|
+
File.open(path, "w") do |fp|
|
13
|
+
fp.write(
|
14
|
+
lines.map do |line|
|
15
|
+
line.gsub(/(VERSION *= *"[0-9.]*\.)([0-9]+)"\n/) do
|
16
|
+
version = "#{$1}#{$2.to_i+1}"
|
17
|
+
puts "Version bumped to #{version}\""
|
18
|
+
version+"\"\n"
|
19
|
+
end
|
20
|
+
end*''
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
data/kicad.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kicad/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kicad"
|
8
|
+
spec.version = KiCad::VERSION
|
9
|
+
spec.authors = ["Clifford Heath"]
|
10
|
+
spec.email = ["clifford.heath@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Load and rewrite Kicad s-expression files into a tree structure for scripting}
|
13
|
+
spec.description = %q{Load and rewrite Kicad s-expression files into a tree structure for scripting}
|
14
|
+
spec.homepage = "https://github.com/cjheath/kicad"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = ">= 3.0"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
# spec.bindir = "bin"
|
20
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 13"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "treetop", ["~> 1.6", ">= 1.6.9"]
|
27
|
+
spec.add_runtime_dependency "irb", ["~> 1.14", ">= 1.14"]
|
28
|
+
end
|
data/lib/kicad/ast.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
module KiCad
|
2
|
+
module AST
|
3
|
+
class Node
|
4
|
+
attr_reader :values, :children
|
5
|
+
|
6
|
+
def initialize values, children
|
7
|
+
@values = values
|
8
|
+
@children = children
|
9
|
+
end
|
10
|
+
|
11
|
+
def emit depth = 0
|
12
|
+
"\t"*depth +
|
13
|
+
'(' +
|
14
|
+
@values.map{|v| value(v) }*' ' +
|
15
|
+
(@children.size == 0 ? '' : "\n" + @children.map{|c| c.emit(depth+1) }*''+"\t"*depth) +
|
16
|
+
")\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def value(v)
|
20
|
+
case v
|
21
|
+
when ::Symbol
|
22
|
+
v.to_s
|
23
|
+
when String
|
24
|
+
v.inspect
|
25
|
+
when Float, Integer
|
26
|
+
v.to_s
|
27
|
+
else
|
28
|
+
"Internal error"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class KicadSymbolLib < Node
|
34
|
+
def initialize values, children
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Uncomment or add whatever class you need to customise:
|
40
|
+
|
41
|
+
class Symbol < Node
|
42
|
+
end
|
43
|
+
|
44
|
+
=begin
|
45
|
+
class At < Node
|
46
|
+
end
|
47
|
+
|
48
|
+
class Center < Node
|
49
|
+
end
|
50
|
+
|
51
|
+
class Circle < Node
|
52
|
+
end
|
53
|
+
|
54
|
+
class Effects < Node
|
55
|
+
end
|
56
|
+
|
57
|
+
class EmbeddedFonts < Node
|
58
|
+
end
|
59
|
+
|
60
|
+
class End < Node
|
61
|
+
end
|
62
|
+
|
63
|
+
class ExcludeFromSim < Node
|
64
|
+
end
|
65
|
+
|
66
|
+
class Fill < Node
|
67
|
+
end
|
68
|
+
|
69
|
+
class Font < Node
|
70
|
+
end
|
71
|
+
|
72
|
+
class Generator < Node
|
73
|
+
end
|
74
|
+
|
75
|
+
class GeneratorVersion < Node
|
76
|
+
end
|
77
|
+
|
78
|
+
class Hide < Node
|
79
|
+
end
|
80
|
+
|
81
|
+
class InBom < Node
|
82
|
+
end
|
83
|
+
|
84
|
+
class Length < Node
|
85
|
+
end
|
86
|
+
|
87
|
+
class Name < Node
|
88
|
+
end
|
89
|
+
|
90
|
+
class Number < Node
|
91
|
+
end
|
92
|
+
|
93
|
+
class Offset < Node
|
94
|
+
end
|
95
|
+
|
96
|
+
class OnBoard < Node
|
97
|
+
end
|
98
|
+
|
99
|
+
class Pin < Node
|
100
|
+
end
|
101
|
+
|
102
|
+
class PinNames < Node
|
103
|
+
end
|
104
|
+
|
105
|
+
class PinNumbers < Node
|
106
|
+
end
|
107
|
+
|
108
|
+
class Polyline < Node
|
109
|
+
end
|
110
|
+
|
111
|
+
class Property < Node
|
112
|
+
end
|
113
|
+
|
114
|
+
class Pts < Node
|
115
|
+
end
|
116
|
+
|
117
|
+
class Radius < Node
|
118
|
+
end
|
119
|
+
|
120
|
+
class Rectangle < Node
|
121
|
+
end
|
122
|
+
|
123
|
+
class Size < Node
|
124
|
+
end
|
125
|
+
|
126
|
+
class Start < Node
|
127
|
+
end
|
128
|
+
|
129
|
+
class Stroke < Node
|
130
|
+
end
|
131
|
+
|
132
|
+
class Type < Node
|
133
|
+
end
|
134
|
+
|
135
|
+
class Version < Node
|
136
|
+
end
|
137
|
+
|
138
|
+
class Width < Node
|
139
|
+
end
|
140
|
+
|
141
|
+
class Xy < Node
|
142
|
+
end
|
143
|
+
=end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'kicad/ast'
|
2
|
+
|
3
|
+
module KiCad
|
4
|
+
grammar SExpr
|
5
|
+
rule node
|
6
|
+
'(' s values:( value s)+ nodes:(node s)* ')' s
|
7
|
+
{ def value
|
8
|
+
klass_name = values.elements[0].value.value
|
9
|
+
klass = KiCad::AST::Node
|
10
|
+
if klass_name.is_a? ::Symbol
|
11
|
+
# See if we have a defined class for this node type
|
12
|
+
klass_name = klass_name.to_s.gsub(/\A[a-z]|_[a-z]/) {|from| from[-1].upcase }
|
13
|
+
klass = KiCad::AST.const_get(klass_name, false) rescue KiCad::AST::Node
|
14
|
+
end
|
15
|
+
klass.new values.elements.map(&:value).map(&:value),
|
16
|
+
nodes.elements.map(&:node).map(&:value)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
rule value
|
22
|
+
string / number / symbol
|
23
|
+
end
|
24
|
+
|
25
|
+
rule symbol
|
26
|
+
[a-zA-Z_]+
|
27
|
+
{ def value; :"#{text_value}"; end }
|
28
|
+
end
|
29
|
+
|
30
|
+
rule string
|
31
|
+
'"' ('\\"' / !'"' .)* '"'
|
32
|
+
{ def value; eval(text_value); end } # REVISIT: Risk of evaluating code
|
33
|
+
end
|
34
|
+
|
35
|
+
rule number
|
36
|
+
'-'? [0-9]+ ( '.' [0-9]* )?
|
37
|
+
{ def value; eval(text_value); end }
|
38
|
+
end
|
39
|
+
|
40
|
+
rule s
|
41
|
+
[ \t\r\n]*
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/kicad/parser.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'treetop'
|
2
|
+
require_relative 'grammar'
|
3
|
+
|
4
|
+
module KiCad
|
5
|
+
def self.parse string
|
6
|
+
p = Parser.new
|
7
|
+
result = p.parse string
|
8
|
+
if !result
|
9
|
+
throw "KiCad::SExpr parse failed at line #{p.failure_line} column #{p.failure_column}: #{p.failure_reason}"
|
10
|
+
end
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load filename
|
15
|
+
self.parse File.read(filename)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Parser < KiCad::SExprParser
|
19
|
+
end
|
20
|
+
end
|
data/lib/kicad.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kicad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clifford Heath
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-05-05 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: bundler
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.11'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.11'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '13'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '13'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: treetop
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.6'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.6.9
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.6'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.6.9
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: irb
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.14'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.14'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.14'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.14'
|
80
|
+
description: Load and rewrite Kicad s-expression files into a tree structure for scripting
|
81
|
+
email:
|
82
|
+
- clifford.heath@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- ".gitignore"
|
88
|
+
- Gemfile
|
89
|
+
- Gemfile.lock
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- kicad.gemspec
|
93
|
+
- lib/kicad.rb
|
94
|
+
- lib/kicad/ast.rb
|
95
|
+
- lib/kicad/grammar.tt
|
96
|
+
- lib/kicad/parser.rb
|
97
|
+
- lib/kicad/version.rb
|
98
|
+
homepage: https://github.com/cjheath/kicad
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.6.2
|
117
|
+
specification_version: 4
|
118
|
+
summary: Load and rewrite Kicad s-expression files into a tree structure for scripting
|
119
|
+
test_files: []
|