shunting_yard 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 825936faa9f1c872f460b25d5e988e418abe6b98a2bd167af2c83fe13b25bf03
4
- data.tar.gz: 2c91cb879600cc2dc260475ae03d3f1d763d0173f77a9060f43f1dd7609a9029
3
+ metadata.gz: 98bef382dc6cddbf6c4e177bcfe58a37f16478ce1e00f5dd8026a7dda5a05827
4
+ data.tar.gz: 3aa6aeab3023e988b317836d061b7f448e1e7e7020dcd239a11a2c75d9c807a2
5
5
  SHA512:
6
- metadata.gz: d4484b313d0106bb9279290fab1f86413701a673d0e4d2f43521f8f1cb95bb5fb62feb773f1d6e2abc921fc0711939ebca3ae8b9e6f2225c0cbdfe4d9114c504
7
- data.tar.gz: ad729d6a29a484d3c3c77ba36e9080a3bf90c7f64d4ef8c021112d7817efd3732f0ce7d264431187ea73528b5f035d3820962d3f50867575043febea69fc7743
6
+ metadata.gz: 68ba5b01954c7f3ede70ca02fc89e49143ee574c6ea918869ed031552d824e0f5ecc3d2959ba0b5a0169e4d712ab60b21bd07afce62a11df457b26fa8116b3cd
7
+ data.tar.gz: 5a26d06f878b4fd68176680dad9ea30af56967f977fb65d41ad77632f7ad76564bcdf2508352064fc3893b2d2fa040c9d098287e3f5ffaea541ab9478a8c7db9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shunting_yard (0.1.0)
4
+ shunting_yard (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/example.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "pry"
2
+ require "bigdecimal"
3
+ require "shunting_yard"
4
+
5
+ sy = ShuntingYard::Parser.new
6
+
7
+ sy.separator_pattern = /(?:\s|$|\,|\(|\))/
8
+
9
+ sy.add_pattern :space, /\s+/, -> (_) { nil }
10
+ sy.add_pattern :argument_separator, /\,/
11
+ sy.add_pattern :operator, /[\+\-\*\/\^]/
12
+ sy.add_pattern :parenthesis, /[\(\)]/
13
+ sy.add_pattern :function, /(?:min|max)/
14
+ sy.add_pattern :operand, /\-?(?:0|[1-9]\d*)(?:\.\d+)?/, -> (lexeme) { BigDecimal(lexeme) }
15
+ sy.add_pattern :operand, /(\w+)_(\w+)_(\w+)/, -> (lexeme) { 300 }
16
+
17
+ sy.add_operator "+", 0, :left, -> (left, right) { left + right }
18
+ sy.add_operator "-", 0, :left, -> (left, right) { left - right }
19
+ sy.add_operator "*", 1, :left, -> (left, right) { left * right }
20
+ sy.add_operator "/", 1, :left, -> (left, right) { left / right }
21
+ sy.add_operator "^", 2, :right, -> (left, right) { left**right }
22
+
23
+ sy.add_function "min", -> (left, right) { [left, right].min }
24
+ sy.add_function "max", -> (left, right) { [left, right].max }
25
+
26
+ input = "min(max(3, 4 / 2) * 2 ^ 3, 25)"
27
+
28
+ puts sy.to_rpn(input).to_s
29
+ puts sy.evaluate(input)
@@ -1,3 +1,3 @@
1
1
  module ShuntingYard
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,19 +3,19 @@ require_relative 'lib/shunting_yard/version'
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "shunting_yard"
5
5
  spec.version = ShuntingYard::VERSION
6
- spec.authors = ["Donkey Kong"]
7
- spec.email = ["584951-highaf@users.noreply.gitlab.com"]
6
+ spec.authors = ["Artem Rashev"]
7
+ spec.email = ["artem.rashev@protonmail.com"]
8
8
 
9
9
  spec.summary = "ShuntingYard algorithm implementation"
10
10
  spec.description = ""
11
- spec.homepage = "https://gitlab.com/hodlhodl-public/shunting_yard"
11
+ spec.homepage = "https://github.com/mgpnd/shunting_yard"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://gitlab.com/hodlhodl-public/shunting_yard"
18
+ spec.metadata["source_code_uri"] = "https://github.com/mgpnd/shunting_yard"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shunting_yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Donkey Kong
7
+ - Artem Rashev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-02 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  description: ''
70
70
  email:
71
- - 584951-highaf@users.noreply.gitlab.com
71
+ - artem.rashev@protonmail.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -80,6 +80,7 @@ files:
80
80
  - LICENSE.txt
81
81
  - README.md
82
82
  - Rakefile
83
+ - example.rb
83
84
  - lib/shunting_yard.rb
84
85
  - lib/shunting_yard/errors.rb
85
86
  - lib/shunting_yard/interpreter.rb
@@ -89,13 +90,13 @@ files:
89
90
  - lib/shunting_yard/structs.rb
90
91
  - lib/shunting_yard/version.rb
91
92
  - shunting_yard.gemspec
92
- homepage: https://gitlab.com/hodlhodl-public/shunting_yard
93
+ homepage: https://github.com/mgpnd/shunting_yard
93
94
  licenses:
94
95
  - MIT
95
96
  metadata:
96
97
  allowed_push_host: https://rubygems.org
97
- homepage_uri: https://gitlab.com/hodlhodl-public/shunting_yard
98
- source_code_uri: https://gitlab.com/hodlhodl-public/shunting_yard
98
+ homepage_uri: https://github.com/mgpnd/shunting_yard
99
+ source_code_uri: https://github.com/mgpnd/shunting_yard
99
100
  post_install_message:
100
101
  rdoc_options: []
101
102
  require_paths:
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
114
  requirements: []
114
- rubygems_version: 3.1.2
115
+ rubygems_version: 3.0.9
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: ShuntingYard algorithm implementation