basic_math_parser 0.2.1 → 0.2.2
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/README.md +16 -5
- data/basic_math_parser.gemspec +2 -4
- data/lib/basic_math_parser/tokenizer.rb +2 -2
- data/lib/basic_math_parser/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a86b2cf7041356eb22499e68b700a775e93c823b9ef407aae8cb2d280f711e
|
4
|
+
data.tar.gz: 2cd56f0f2fe0fc347f5d36f7dd772900f4ac9f07c6e5182bf976142ec96957d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffe283c33e0ca2baf8aaf78d455b0c33d8ae8f6e3daa2a5ce69de01a67167ac0197cf0ef564a24459066cbb70b296e2700c94f353fcb57135ec358c2fab842b6
|
7
|
+
data.tar.gz: 59e467fb49cf8e2a8ceaba4695685b206d9e389a7c8a8ab81ce45ef19571db104159df9145056643f155ca6d8632dd9f6e28f43301417483d2266fc5dc57e32a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BasicMathParser
|
2
2
|
|
3
|
-
BasicMathParser is an simple expression parser
|
3
|
+
BasicMathParser is an simple expression parser built based on the postfix expression parsing.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -12,12 +12,23 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
12
12
|
|
13
13
|
$ gem install basic_math_parser
|
14
14
|
|
15
|
-
##
|
15
|
+
## Examples
|
16
16
|
|
17
|
-
|
17
|
+
To parse an expression:
|
18
|
+
```
|
19
|
+
BasicMathParser.evaluate("3+5")
|
20
|
+
# => 8.0
|
21
|
+
```
|
22
|
+
BasicMathParser will support Order precedence and use of parentheses to group expressions, by this Proper evaluation is ensured.
|
23
|
+
```
|
24
|
+
BasicMathParser.evaluate("(10 + 5) / 5")
|
25
|
+
# => 3.0
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
BasicMathParser.evaluate("10 + 5 / 5")
|
28
|
+
# => 11.0
|
29
|
+
```
|
30
|
+
|
31
|
+
**Supported operations:** `+`, `-`, `/`, `*`, `%`, `^`, `(` , `)`
|
21
32
|
|
22
33
|
## Development
|
23
34
|
|
data/basic_math_parser.gemspec
CHANGED
@@ -7,14 +7,12 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = BasicMathParser::VERSION
|
8
8
|
spec.authors = ["srkrishna412"]
|
9
9
|
spec.email = ["srkrishna412@gmail.com"]
|
10
|
-
|
10
|
+
spec.licenses = ['AGPLv3']
|
11
11
|
spec.summary = "Evalute a basic arithmetic expression"
|
12
|
-
spec.description = "Evalute a basic arithmetic expression"
|
12
|
+
spec.description = "Evalute a basic arithmetic expression using postfix parsing approach."
|
13
13
|
spec.homepage = "https://gitlab.com/srkrishna/basic_math_parser"
|
14
14
|
spec.required_ruby_version = ">= 2.6.0"
|
15
15
|
|
16
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
-
|
18
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
17
|
spec.metadata["source_code_uri"] = "https://gitlab.com/srkrishna/basic_math_parser"
|
20
18
|
spec.metadata["changelog_uri"] = "https://gitlab.com/srkrishna/basic_math_parser/-/blob/main/CHANGELOG.md"
|
@@ -4,7 +4,7 @@ class Tokenizer
|
|
4
4
|
RULES = {
|
5
5
|
/\d+\.\d+|\d+|\.\d+/ => :number,
|
6
6
|
/[\/+\-*^%\()]/ => :op,
|
7
|
-
/\d+[a-zA-z]+|[a-zA-z]+\d+|[a-zA-z]+/ => :variable
|
7
|
+
/\d+[a-zA-z]+|[a-zA-z]+\d+|[a-zA-z]+|[`~^$#@!<>=_-]+/ => :variable,
|
8
8
|
}
|
9
9
|
|
10
10
|
def initialize
|
@@ -29,7 +29,7 @@ class Tokenizer
|
|
29
29
|
def find_token(regex, type)
|
30
30
|
token = @buffer.scan(regex)
|
31
31
|
|
32
|
-
raise BasicMathParser::ParseError.for('
|
32
|
+
raise BasicMathParser::ParseError.for('Expression contains unsupported Symbol/character!', info: {variable: token} ) if token && type == :variable
|
33
33
|
|
34
34
|
@tokens << Token.new(type, token) if token
|
35
35
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic_math_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- srkrishna412
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Evalute a basic arithmetic expression
|
13
|
+
description: Evalute a basic arithmetic expression using postfix parsing approach.
|
14
14
|
email:
|
15
15
|
- srkrishna412@gmail.com
|
16
16
|
executables: []
|
@@ -36,7 +36,8 @@ files:
|
|
36
36
|
- lib/basic_math_parser/version.rb
|
37
37
|
- sig/basic_math_parser.rbs
|
38
38
|
homepage: https://gitlab.com/srkrishna/basic_math_parser
|
39
|
-
licenses:
|
39
|
+
licenses:
|
40
|
+
- AGPLv3
|
40
41
|
metadata:
|
41
42
|
homepage_uri: https://gitlab.com/srkrishna/basic_math_parser
|
42
43
|
source_code_uri: https://gitlab.com/srkrishna/basic_math_parser
|