shunting_yard 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75535fce560ff196525060c8cc74fa8b15fb085f5042b442bc766399f9075072
4
- data.tar.gz: 2a6f28b8f4a10bfd25e5f93cd32ee3d8bca1f2a65a604f8e1cb16a55c3786de9
3
+ metadata.gz: 0d0b8a2d962c3ee8b9b416d729dd4d72c57ef4c4f53ae1962215afd08d79b67e
4
+ data.tar.gz: 174cb0e75d168499608eff7be798249fbdaa89682612b0cdd24ef396474e89ab
5
5
  SHA512:
6
- metadata.gz: 6974a00a4694382d711e18358c76ebbe225f768155eaf3d30feed68fd8047845e1e0d7aacbff116f3da3f6ea823b697c98225a661b62de05740b7d70e957d106
7
- data.tar.gz: 6c51c7ad5d8ec75a17f7825099fe1894e198048006d44deca00a20d2603fccc79f2aa4d83ecd60c3cbefbdc7080fabc81c98f189d140ef6c2b715fd36c807fea
6
+ metadata.gz: 38f3557a80197e08b0b301b1c28e512ac55f6808e5f7c025f4e17bfc0e9b5c76e2cc1b6b29a608ff47fbb7735e2a2962020e91d634a62ef43636c9a9c59f7abf
7
+ data.tar.gz: '018c673de3b9cc1e3b719a3538fdcdef7eea35f1febb34666a80bcd3777e2c3e2122e1bcb07bfdbf8c5de18f0acebb3e44b254dad432d08aad7d6bb14e4d57ce'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shunting_yard (0.1.2)
4
+ shunting_yard (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 longest match** wil be used.
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
 
@@ -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
- next if value.nil?
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 longest_match_size == 0
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 += longest_match_size
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
@@ -1,3 +1,3 @@
1
1
  module ShuntingYard
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.2
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-07 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase