plt 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0fabb3b2014aa632f2782bce6d9320e1ba8b56471c692e87fddaad373680f1ad
4
+ data.tar.gz: 2704fe0e2748e6af2983971e895e2080d52d4fdc89199d09cf3a761091c0a4f8
5
+ SHA512:
6
+ metadata.gz: 17a2ab86224efbbdf3b9c8a35228bdb2042a6a1d0b0629b7024cc2ce1decf20ce9524fa2b8b48f07ba00302ed2f0da4c828af73e5ab3c6dcb42d982be9d2d59a
7
+ data.tar.gz: 8b37e6b2b34680668d2634704d798b81f9a7f69387f403cea1606c0118d3a64da9021099fbdf8f4a2ff81553cb8c6205adce784d32649a02c3829df64c10b1b7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jonas Mueller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Plt
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plt`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plt.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/lib/plt/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+
4
+ require "thor"
5
+
6
+ module Plt
7
+ class CLI < Thor
8
+
9
+ desc "show FILE", "Show all signals in FILE"
10
+ def show(file=nil)
11
+ puts Plt::Config.from_file(file).to_s
12
+ end
13
+
14
+ desc "lab FILE", "List all signals in FILE as *.lab file"
15
+ def list(file=nil)
16
+ puts "[RAMCELL]"
17
+ puts Plt::Config.from_file(file).groups.flat_map(&:signals)
18
+ end
19
+
20
+ desc "cat FILE", "Output PLT for FILE"
21
+ def cat(file=nil)
22
+ puts Plt::Config.from_file(file).to_plt
23
+ end
24
+
25
+ desc "open FILE", "Open PLT in UNIVIEW"
26
+ def open(file=nil)
27
+ Plt::Config.from_file(file).open!
28
+ end
29
+
30
+ end
31
+ end
data/lib/plt/config.rb ADDED
@@ -0,0 +1,76 @@
1
+ require "fileutils"
2
+
3
+ module Plt
4
+ UNIVIEW_PATH = "/mnt/c/Program\ Files/Uniview/UNIVW64.exe"
5
+ TMP_PATH = "/mnt/c/tmp"
6
+
7
+ class Config
8
+ attr_reader :name, :elements
9
+ def initialize(name, elements)
10
+ @name = name
11
+ @elements = elements
12
+ end
13
+
14
+ def self.from_file(filepath)
15
+ elements = []
16
+ group = nil
17
+ File.readlines(filepath).each do |line|
18
+ line = line.sub(/^~ /, "") # Remove disabled comments, group has info already
19
+ case line
20
+ in %r{^//BEGIN_GROUP}
21
+ fail "Invalid GROUP definition: #{line} (still inside previous definition)" if group
22
+ group = Group.from_line(line)
23
+ in %r{^//END_GROUP}
24
+ fail "Cannot end GROUP definition (none open)" unless group
25
+ elements << group
26
+ group = nil
27
+ in %r{^\w+}
28
+ if group
29
+ group.signals << Signal.from_line(line)
30
+ else
31
+ elements << Signal.from_line(line)
32
+ end
33
+ in %r{^+}
34
+ # ignore, expression from previous signal
35
+ end
36
+ end
37
+ new(File.basename(filepath), elements)
38
+ end
39
+
40
+ def groups
41
+ elements.select { _1.is_a?(Group) }
42
+ end
43
+
44
+ def signals
45
+ elements.flat_map do
46
+ case _1
47
+ in Group then _1.signals
48
+ in Signal then _1
49
+ end
50
+ end
51
+ end
52
+
53
+ def save_to(path)
54
+ File.join(path, name)
55
+ .tap { File.write(_1, to_plt) }
56
+ end
57
+
58
+ def save_to_tmp
59
+ `wslpath -w #{save_to(TMP_PATH)}`
60
+ end
61
+
62
+ def open!
63
+ spawn(UNIVIEW_PATH, "/n", save_to_tmp, out: "/dev/null", err: "/dev/null")
64
+ .then { Process.detach(_1) }
65
+ end
66
+
67
+ def to_s
68
+ "#{name}:\n" +
69
+ elements.map(&:to_s).join("\n")
70
+ end
71
+
72
+ def to_plt
73
+ elements.map(&:to_plt).join("\n")
74
+ end
75
+ end
76
+ end
data/lib/plt/group.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Plt
2
+ class Group
3
+ attr_reader :name, :color, :enabled, :signals
4
+ attr_writer :signals
5
+ def initialize(name, color, enabled=true)
6
+ @name = name
7
+ @color = color
8
+ @enabled = enabled
9
+ @signals = []
10
+ end
11
+
12
+ REGEXP = %r{//BEGIN_GROUP "(?<name>[^"]+)" ?(?<status>DISABLED|ENABLED)?(?: COLOR=(?<color>\d+))?}
13
+
14
+ def enabled? = enabled
15
+
16
+ def self.from_line(line)
17
+ fail "Cannot parse line #{line}" unless match = line.match(REGEXP)
18
+
19
+ new(match[:name], match[:color], match[:status] != "DISABLED")
20
+ end
21
+
22
+ def to_s
23
+ "Group \"#{name}\"" +
24
+ (enabled? ? "" : " (disabled)") +
25
+ "\n" +
26
+ signals.map { " #{_1}" }.join("\n") +
27
+ "\n"
28
+ end
29
+
30
+ def to_plt
31
+ "//BEGIN_GROUP \"#{name}\" #{enabled? ? "ENABLED" : "DISABLED"}#{color ? " COLOR=#{color}" : ""}\n" +
32
+ signals.map { "#{_1.to_plt(enabled?)}\n" }.join +
33
+ "//END_GROUP"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ module Plt
2
+ class Property
3
+ def self.parse(str)
4
+ key, value = str.split("=")
5
+ case key.to_sym
6
+ in :unit then { unit: value }
7
+ in :scansc then { scansc: true }
8
+ in :emphasize then { emphasize: value.to_i }
9
+ else { key.to_sym => value.to_f }
10
+ end
11
+ end
12
+
13
+ def self.to_plt(key, value)
14
+ case key
15
+ when :scansc then "scansc"
16
+ else "#{key}=#{value}"
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/plt/signal.rb ADDED
@@ -0,0 +1,38 @@
1
+ require_relative "property"
2
+
3
+ module Plt
4
+ class Signal
5
+ attr_reader :name, :color, :properties
6
+ def initialize(name, typestr, color, *properties)
7
+ @name = name
8
+ @bit = typestr == "bit"
9
+ @color = color.to_i
10
+ @properties = properties
11
+ .map { Property.parse(_1) }
12
+ .reduce({}) { |acc, e| acc.merge(e) }
13
+ end
14
+
15
+ def bit? = @bit
16
+
17
+ def self.from_line(line)
18
+ new(*line.chomp.split(/\s+/))
19
+ rescue
20
+ raise ArgumentError, "Cannot parse line \"#{line}\""
21
+ end
22
+
23
+ def to_s
24
+ name + (bit? ? " (bit)" : "")
25
+ end
26
+
27
+ def to_plt(enabled=true)
28
+ [
29
+ (enabled ? nil : "~"),
30
+ name,
31
+ "",
32
+ (bit? ? "bit" : "nobit"),
33
+ color,
34
+ *properties.map { |k, v| Property.to_plt(k, v) }
35
+ ].compact.join(" ")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plt
4
+ VERSION = "0.1.1"
5
+ end
data/lib/plt.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "plt/version"
4
+
5
+ require_relative "plt/cli"
6
+ require_relative "plt/config"
7
+ require_relative "plt/group"
8
+ require_relative "plt/signal"
9
+
10
+ module Plt
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
data/sig/plt.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Plt
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Mueller
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: thor
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Parse and generate *.plt files for working with Uniview
27
+ email:
28
+ - jonas@tigger.cloud
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".rspec"
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - lib/plt.rb
38
+ - lib/plt/cli.rb
39
+ - lib/plt/config.rb
40
+ - lib/plt/group.rb
41
+ - lib/plt/property.rb
42
+ - lib/plt/signal.rb
43
+ - lib/plt/version.rb
44
+ - sig/plt.rbs
45
+ homepage: https://github.com/plt/plt
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/plt/plt
50
+ source_code_uri: https://github.com/plt/plt
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.0.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 4.0.16
66
+ specification_version: 4
67
+ summary: PLT parser for working with Uniview
68
+ test_files: []