farseer 0.7.0 → 0.8.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: 22cbc0c49fc2a306b2e0e7291dd58e09047bd2eef4b679d2be9f9e307c6db2e1
4
- data.tar.gz: a3a1a49b2748d129931af363e3a4bcbb9fdbd174956de07a4de0daceb0cc07cb
3
+ metadata.gz: 656cdb47ea0c930c3706c4ecb11eba8df657c4890e84a5537ba7e1aa4bcb1624
4
+ data.tar.gz: 14ec99cefd66715c3d2338fabb10ef56c8e371d2aacef140a835761e42057440
5
5
  SHA512:
6
- metadata.gz: 8b3bc436e67fcd46f61964cb6e3e70c7f3a8c374a1712680f4a91901daaf9ae071c79428ac40da19038619e8a05556cbbfd0167d43b5841020b082d730f909a6
7
- data.tar.gz: 2303e7849b72c10e9353ff9faf362c3d8e0113f24247dbd95104ea45d2c5877e96bcf2444d402853909f14590f4a3c8295f813f99ebc23e1c4bbccbb33c11ae8
6
+ metadata.gz: d658b63d11e9c0aac8ffda570a1a2ab43e225645433a178981fb1850a7d6e23cf98027684e86354974082719655dad75c4b7d14386b5013e007c1bac3ad53092
7
+ data.tar.gz: e9fec41b0d13895de5c9404997f7cf6474fbda1370584806b35caa426d4c2204761650a8a874b11efbb645fc5b941fa7ba1fd9888f8334bc59472af8b7d13b7b
data/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.0] - 2024-06-04
11
+ ### Added
12
+ - `Farseer::Map` which is a parser with a callback to map the resulting token
13
+ into something else.
14
+ - `Farseer::MapFactory` which adds `#map`, a factory method for new parsers with
15
+ callbacks. It creates a new instance of `Farseer::Map`.
16
+ - Included `Farseer::MapFactory` into all parsers.
17
+
18
+
10
19
  ## [0.7.0] - 2024-06-04
11
20
  ### Added
12
21
  - `Farseer::And` to run a sequence of parsers that must all succeed.
@@ -23,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
32
  ### Changed
24
33
  - Update development dependencies.
25
34
 
35
+
26
36
  ## [0.6.0] - 2024-06-03
27
37
  ### Added
28
38
  - `Farseer::Opt` to parse `0` to `1` times the wrapped parser. (`?`)
@@ -37,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
47
  ### Changed
38
48
  - Updated development dependencies
39
49
 
50
+
40
51
  ## [0.5.0] - 2024-06-03
41
52
  ### Added
42
53
  - `Farseer::Char` as a single character parser.
@@ -54,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
54
65
  ### Changed
55
66
  - Update `muina` version requirement to `~> 0.5`
56
67
 
68
+
57
69
  ## [0.4.0] - 2024-06-03
58
70
  ### Added
59
71
  - `Farseer.any_char_parser` to parse a single character from a given set.
@@ -64,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
64
76
  - Stop using `module_function` and change methods into singleton methods.
65
77
  - Update `bundler` version.
66
78
 
79
+
67
80
  ## [0.3.0] - 2024-06-02
68
81
  ### Added
69
82
  - `Farseer#ws_parser` to parse all leading whitespace.
data/lib/farseer/and.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class And
5
+ include MapFactory
6
+
5
7
  def initialize(*parsers)
6
8
  @parsers = parsers.flatten
7
9
  freeze
data/lib/farseer/any.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Any
5
+ include MapFactory
6
+
5
7
  def initialize(parser)
6
8
  @parser = parser
7
9
  freeze
data/lib/farseer/char.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Char
5
+ include MapFactory
6
+
5
7
  def initialize(char)
6
8
  @char = char
7
9
  freeze
data/lib/farseer/chars.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Chars
5
+ include MapFactory
6
+
5
7
  def initialize(*chars)
6
8
  @chars = chars.flatten
7
9
  freeze
data/lib/farseer/many.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Many
5
+ include MapFactory
6
+
5
7
  def initialize(parser)
6
8
  @parser = parser
7
9
  freeze
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Map
5
+ include MapFactory
6
+
7
+ def initialize(parser, &map)
8
+ @parser = parser
9
+ @map = map
10
+ freeze
11
+ end
12
+
13
+ def parse(input)
14
+ @parser.parse(input).map { |r| Result.new(@map.call(r.token), r.rest) }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Farseer
2
+ module MapFactory
3
+ def map(&)
4
+ Map.new(self, &)
5
+ end
6
+ end
7
+ end
data/lib/farseer/opt.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Opt
5
+ include MapFactory
6
+
5
7
  def initialize(parser)
6
8
  @parser = parser
7
9
  freeze
data/lib/farseer/or.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Or
5
+ include MapFactory
6
+
5
7
  def initialize(*parsers)
6
8
  @parsers = parsers.flatten
7
9
  freeze
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Regexp
5
+ include MapFactory
6
+
5
7
  WS_REGEXP = /^(?'token'\s*)(?'rest'.*)$/
6
8
  RegexpError = Class.new(ArgumentError)
7
9
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Farseer
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  public_constant :VERSION
6
6
  end
data/lib/farseer/word.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Farseer
4
4
  class Word
5
+ include MapFactory
6
+
5
7
  def initialize(word)
6
8
  @word = word
7
9
  freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farseer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaporyhumo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-04 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: muina
@@ -55,6 +55,8 @@ files:
55
55
  - lib/farseer/char.rb
56
56
  - lib/farseer/chars.rb
57
57
  - lib/farseer/many.rb
58
+ - lib/farseer/map.rb
59
+ - lib/farseer/map_factory.rb
58
60
  - lib/farseer/opt.rb
59
61
  - lib/farseer/or.rb
60
62
  - lib/farseer/regexp.rb