shunting_yard 0.1.2 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/shunting_yard/lexer.rb +5 -10
- data/lib/shunting_yard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d0b8a2d962c3ee8b9b416d729dd4d72c57ef4c4f53ae1962215afd08d79b67e
|
4
|
+
data.tar.gz: 174cb0e75d168499608eff7be798249fbdaa89682612b0cdd24ef396474e89ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38f3557a80197e08b0b301b1c28e512ac55f6808e5f7c025f4e17bfc0e9b5c76e2cc1b6b29a608ff47fbb7735e2a2962020e91d634a62ef43636c9a9c59f7abf
|
7
|
+
data.tar.gz: '018c673de3b9cc1e3b719a3538fdcdef7eea35f1febb34666a80bcd3777e2c3e2122e1bcb07bfdbf8c5de18f0acebb3e44b254dad432d08aad7d6bb14e4d57ce'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ parser.evaluate(input) #=> 24
|
|
32
32
|
`ShuntingYard::Lexer` is responsible for splitting source string into tokens.
|
33
33
|
To recognize each possible token it needs to know corresponding patterns represented as regular expressions.
|
34
34
|
|
35
|
-
If substring is matched to multiple patterns, **the
|
35
|
+
If substring is matched to multiple patterns, **the first match** will be used.
|
36
36
|
|
37
37
|
After matching a token, its lexeme is evaluated with provided function. If function is not provided - it returns the lexeme itself.
|
38
38
|
|
data/lib/shunting_yard/lexer.rb
CHANGED
@@ -21,29 +21,24 @@ module ShuntingYard
|
|
21
21
|
matches = []
|
22
22
|
|
23
23
|
until sc.eos?
|
24
|
-
match = nil
|
25
24
|
last_match = nil
|
26
|
-
longest_match_size = 0
|
27
25
|
|
28
26
|
@patterns.each do |name, regex, evaluator|
|
29
27
|
match = sc.check(regex)
|
30
28
|
next if match.nil?
|
31
29
|
|
32
|
-
longest_match_size = [longest_match_size, match.bytesize].max
|
33
|
-
|
34
30
|
value = evaluator.(match)
|
35
|
-
|
36
|
-
|
37
|
-
last_match = [name, match, value] if last_match.nil? || last_match[1].size < match.size
|
31
|
+
last_match = [name, match, value]
|
32
|
+
break
|
38
33
|
end
|
39
34
|
|
40
|
-
if
|
35
|
+
if last_match.nil?
|
41
36
|
unknown_token = sc.check_until(separator_pattern).sub(separator_pattern, "")
|
42
37
|
raise UnknownTokenError.new(unknown_token, sc.pos + 1)
|
43
38
|
end
|
44
39
|
|
45
|
-
sc.pos +=
|
46
|
-
matches << build_token(last_match) unless last_match.nil?
|
40
|
+
sc.pos += last_match[1].bytesize
|
41
|
+
matches << build_token(last_match) unless last_match[2].nil?
|
47
42
|
end
|
48
43
|
|
49
44
|
matches
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Rashev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|