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 +4 -4
- data/Gemfile.lock +1 -1
- data/example.rb +29 -0
- data/lib/shunting_yard/version.rb +1 -1
- data/shunting_yard.gemspec +4 -4
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bef382dc6cddbf6c4e177bcfe58a37f16478ce1e00f5dd8026a7dda5a05827
|
4
|
+
data.tar.gz: 3aa6aeab3023e988b317836d061b7f448e1e7e7020dcd239a11a2c75d9c807a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68ba5b01954c7f3ede70ca02fc89e49143ee574c6ea918869ed031552d824e0f5ecc3d2959ba0b5a0169e4d712ab60b21bd07afce62a11df457b26fa8116b3cd
|
7
|
+
data.tar.gz: 5a26d06f878b4fd68176680dad9ea30af56967f977fb65d41ad77632f7ad76564bcdf2508352064fc3893b2d2fa040c9d098287e3f5ffaea541ab9478a8c7db9
|
data/Gemfile.lock
CHANGED
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)
|
data/shunting_yard.gemspec
CHANGED
@@ -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 = ["
|
7
|
-
spec.email = ["
|
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://
|
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://
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Artem Rashev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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
|
-
-
|
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://
|
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://
|
98
|
-
source_code_uri: https://
|
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.
|
115
|
+
rubygems_version: 3.0.9
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: ShuntingYard algorithm implementation
|