farseer 0.7.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22cbc0c49fc2a306b2e0e7291dd58e09047bd2eef4b679d2be9f9e307c6db2e1
4
- data.tar.gz: a3a1a49b2748d129931af363e3a4bcbb9fdbd174956de07a4de0daceb0cc07cb
3
+ metadata.gz: 1f6d2e808d2e8ac8a9b119598834508dc1482f0cfaf68c34737fefb4bd261db6
4
+ data.tar.gz: 7282626a92655eb5b4044edef19689042127e22fb83e7751b5128c80f3749a89
5
5
  SHA512:
6
- metadata.gz: 8b3bc436e67fcd46f61964cb6e3e70c7f3a8c374a1712680f4a91901daaf9ae071c79428ac40da19038619e8a05556cbbfd0167d43b5841020b082d730f909a6
7
- data.tar.gz: 2303e7849b72c10e9353ff9faf362c3d8e0113f24247dbd95104ea45d2c5877e96bcf2444d402853909f14590f4a3c8295f813f99ebc23e1c4bbccbb33c11ae8
6
+ metadata.gz: f970a3b6804799587f2e715de0bff16efbaa6904e86259f735f6d417c5590cf0eb8bda85349509782c0258a215405c55c285159f7e31905406d08340891c3453
7
+ data.tar.gz: 7c5eaffc7d1b135bff0eae234f1322c1ded4971e0c8a68bfcd47cd43783037193d242a39e3fd2a59e06d76a267e8543967e1cde846f5dea7f2db03deb08d5ef9
data/CHANGELOG.md CHANGED
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.0] - 2024-06-11
11
+ ### Added
12
+ - `Farseer::Empty` which always succeeds and parses nothing, returning the whole
13
+ string as rest.
14
+
15
+ ### Changed
16
+ - Change usage of `#eql?` to `#==` in `Farseer::Result`.
17
+ - `Farseer::And` does not join the resulting tokens anymore, but rather return
18
+ an array of tokens.
19
+ - Remove all development dependencies from `Gemfile` in favor of having
20
+ `lollipop` in the `gemspec`.
21
+
22
+ ## [0.8.0] - 2024-06-04
23
+ ### Added
24
+ - `Farseer::Map` which is a parser with a callback to map the resulting token
25
+ into something else.
26
+ - `Farseer::MapFactory` which adds `#map`, a factory method for new parsers with
27
+ callbacks. It creates a new instance of `Farseer::Map`.
28
+ - Included `Farseer::MapFactory` into all parsers.
29
+
30
+
10
31
  ## [0.7.0] - 2024-06-04
11
32
  ### Added
12
33
  - `Farseer::And` to run a sequence of parsers that must all succeed.
@@ -23,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
44
  ### Changed
24
45
  - Update development dependencies.
25
46
 
47
+
26
48
  ## [0.6.0] - 2024-06-03
27
49
  ### Added
28
50
  - `Farseer::Opt` to parse `0` to `1` times the wrapped parser. (`?`)
@@ -37,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
37
59
  ### Changed
38
60
  - Updated development dependencies
39
61
 
62
+
40
63
  ## [0.5.0] - 2024-06-03
41
64
  ### Added
42
65
  - `Farseer::Char` as a single character parser.
@@ -54,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
54
77
  ### Changed
55
78
  - Update `muina` version requirement to `~> 0.5`
56
79
 
80
+
57
81
  ## [0.4.0] - 2024-06-03
58
82
  ### Added
59
83
  - `Farseer.any_char_parser` to parse a single character from a given set.
@@ -64,6 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
64
88
  - Stop using `module_function` and change methods into singleton methods.
65
89
  - Update `bundler` version.
66
90
 
91
+
67
92
  ## [0.3.0] - 2024-06-02
68
93
  ### Added
69
94
  - `Farseer#ws_parser` to parse all leading whitespace.
data/SECURITY.md CHANGED
@@ -6,8 +6,8 @@ Currently supported version are:
6
6
 
7
7
  | Version | Supported |
8
8
  | ------- | ------------------ |
9
- | 0.6.0 | :white_check_mark: |
10
- | < 0.6.0 | :x: |
9
+ | 0.9.0 | :white_check_mark: |
10
+ | < 0.9.0 | :x: |
11
11
 
12
12
  ## Reporting a Vulnerability
13
13
 
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
@@ -10,7 +12,7 @@ module Farseer
10
12
  def parse(input)
11
13
  return Maybe.none if @parsers.empty?
12
14
 
13
- initial = Maybe.return(Result.new('', input))
15
+ initial = Maybe.return(Result.new([], input))
14
16
 
15
17
  @parsers.reduce(initial) do |maybe_acc, parser|
16
18
  bind_accumulator(maybe_acc, parser)
@@ -30,7 +32,7 @@ module Farseer
30
32
  end
31
33
 
32
34
  def combine_results(acc_result, result)
33
- combined_tokens = acc_result.token + result.token
35
+ combined_tokens = acc_result.token + [result.token]
34
36
  Maybe.return(Result.new(combined_tokens, result.rest))
35
37
  end
36
38
  end
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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Empty
5
+ include MapFactory
6
+
7
+ def initialize
8
+ freeze
9
+ end
10
+
11
+ def parse(input)
12
+ Maybe.return Result.new('', input)
13
+ end
14
+ end
15
+ end
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
 
@@ -9,11 +9,11 @@ module Farseer
9
9
  end
10
10
  attr_reader :token, :rest
11
11
 
12
- def eql?(other)
12
+ def ==(other)
13
13
  self.class.eql?(other.class) and
14
- token.eql?(other.token) and
14
+ token == (other.token) and
15
15
  rest.eql?(other.rest)
16
16
  end
17
- alias == eql?
17
+ alias eql? ==
18
18
  end
19
19
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Farseer
4
- VERSION = '0.7.0'
4
+ VERSION = '0.9.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.9.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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: muina
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lollipop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
41
55
  description: Functional Parsing Library for Ruby
42
56
  email:
43
57
  - roanvilina@gmail.com
@@ -54,7 +68,10 @@ files:
54
68
  - lib/farseer/any.rb
55
69
  - lib/farseer/char.rb
56
70
  - lib/farseer/chars.rb
71
+ - lib/farseer/empty.rb
57
72
  - lib/farseer/many.rb
73
+ - lib/farseer/map.rb
74
+ - lib/farseer/map_factory.rb
58
75
  - lib/farseer/opt.rb
59
76
  - lib/farseer/or.rb
60
77
  - lib/farseer/regexp.rb