farseer 0.4.0 → 0.6.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: 0def0ee29c72d62793716f625d64e599c00f02a30f790062d9e7ae61fb905fea
4
- data.tar.gz: 53701b2c7ce3ed0ff8744b43d48587be8ee4530cb776be24cd5ba87eb908dd19
3
+ metadata.gz: 2700438309a0da4774a6b4c33aa2f8dc01a61e4ae6eae9db5b5d4bc917f45263
4
+ data.tar.gz: da6f37d9b9582cfb731a39d6de9a7afbe4678b5e67df717008b8fdfa39281409
5
5
  SHA512:
6
- metadata.gz: 5ef7c3e3fc84215f25c5ea48d9e8af9d5c8bbed1f4bd01bd0756259c5228008ef0c519d01987da29b0dc200dcddc3e5161de9063a6af3c8611ba7e7c1e54c2fc
7
- data.tar.gz: a3d7fab449c4904680e265547c4416ddff9c2a16ba0b4c047ecb9975d6fedc825d50b78e2c0ff52d8a5aaa84b9e4ce1dda4348fe869bf76f276877280a06b107
6
+ metadata.gz: 9fdc000cff13a63b7ecd370d2a9f454736bc43a5b41ff4b001fdbc07a46ff5b6f2c17101eb27be07499c73b39faace6e00ca61ec04cfebac408054a16ba4cab2
7
+ data.tar.gz: a147d2daafaa1205e316fdcb811ddd8ae78150d060cf890081bd7ad46f2566398fad6b6941711355f13e2f897e37ac290b877e9e418a138a78759beb2fa0eeb3
data/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.6.0] - 2024-06-03
11
+ ### Added
12
+ - `Farseer::Opt` to parse `0` to `1` times the wrapped parser. (`?`)
13
+ - `Farseer::Any` to parse `0` to multiple times the wrapped parser. (`*`)
14
+ - `Farseer::Many` to parse `1` to multiple times the wrapped parser. (`+`)
15
+ - A couple of instances of `Farseer::Chars` as constants:
16
+ - `Farseer::Chars::DIGITS` to parse digits from `0` to `9`.
17
+ - `Farseer::Chars::BASIC_MATH_OP` to parse symbols `+`, `-`, `*`, `/`.
18
+ - Enabled more `Lint` `rubocop` rules.
19
+ - Enabled `Performance` `rubocop` rules.
20
+
21
+ ### Changed
22
+ - Updated development dependencies
23
+
24
+ ## [0.5.0] - 2024-06-03
25
+ ### Added
26
+ - `Farseer::Char` as a single character parser.
27
+ - `Farseer::Chars` as a single character from set parser.
28
+ - Multiple instances of `Farseer::Char` as constants:
29
+ - `Farseer::Char::L_PARENS` for `(`.
30
+ - `Farseer::Char::R_PARENS` for `)`.
31
+ - `Farseer::Char::PLUS` for `+`.
32
+ - `Farseer::Char::MINUS` for `-`.
33
+ - `Farseer::Char::STAR` for `*`.
34
+ - `Farseer::Char::SLASH` for `/`.
35
+ - Enabled `Lint` `rubocop` rules.
36
+ - Enabled a couple more `Layout` `rubocop` rules.
37
+
38
+ ### Changed
39
+ - Update `muina` version requirement to `~> 0.5`
40
+
41
+ ## [0.4.0] - 2024-06-03
42
+ ### Added
43
+ - `Farseer.any_char_parser` to parse a single character from a given set.
44
+ - `irb` development dependency.
45
+ - `.gitignore.local` symlink to `.git/info/exclude`.
46
+
47
+ ### Changed
48
+ - Stop using `module_function` and change methods into singleton methods.
49
+ - Update `bundler` version.
50
+
51
+ ## [0.3.0] - 2024-06-02
52
+ ### Added
53
+ - `Farseer#ws_parser` to parse all leading whitespace.
54
+ - Multiple development dependencies:
55
+ - `flay`, `flog`, `guard`, `guard-rspec`, `guard-rubocop`, `lefthook`, and
56
+ `rubocop-performance` with corresponding `binstubs`.
57
+ - `Guardfile` with `rspec` and `rubocop` guards.
58
+ - `.lefthook.yml` including `pre-commit` and `pre-push` hooks, and `audit` and
59
+ `full_audit` tasks.
60
+
61
+ ### Changed
62
+ - Bump `muina` required version to `~> 0.4`.
63
+ - Enabled `Lint` `rubocop` department.
64
+
65
+
66
+ ## [0.2.0] - 2024-06-02
67
+ ### Added
68
+ - `Farseer::Result` to hold the result of succesful parses.
69
+ - `Farseer#char_parser` to parse a single specific character.
70
+ - `muina` as a dependency.
71
+ - `bin/console` to jump into `irb` with the project loaded.
72
+
73
+
74
+ ## [0.1.0] - 2024-06-02
75
+ ### Added
76
+ - Initial gem relase.
77
+ - Set up code quality dependencies:
78
+ - `rake`: for running common tasks.
79
+ - `rubocop`: for linting.
80
+ - `rspec`: for testing.
81
+ - `simplecov`: for code coverage.
82
+ - License the project with `The Unlicense`.
83
+ - `Rakefile` with `gem`, `rubocop`, and `rspec` tasks.
84
+ - `SECURITY.md` to keep track of maintained versions.
85
+ - `Farseer::VERSION`: Keep the gem version in a constant.
86
+ - `.ruby-version` for rbenv, with version `3.2.2`
87
+ - This `CHANGELOG.md`
data/SECURITY.md ADDED
@@ -0,0 +1,14 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Currently supported version are:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 0.6.0 | :white_check_mark: |
10
+ | < 0.6.0 | :x: |
11
+
12
+ ## Reporting a Vulnerability
13
+
14
+ If you find any vulnerability please open an issue.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Any
5
+ def initialize(parser)
6
+ @parser = parser
7
+ freeze
8
+ end
9
+
10
+ def parse(input)
11
+ helper(input)
12
+ end
13
+
14
+ def helper(input, tokens = [])
15
+ @parser.parse(input)
16
+ .bind { |r| helper(r.rest, [*tokens, r.token]) }
17
+ .map_none { Result.new(tokens.join, input) }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Char
5
+ def initialize(char)
6
+ @char = char
7
+ freeze
8
+ end
9
+
10
+ L_PARENS = new('(')
11
+ R_PARENS = new(')')
12
+ PLUS = new('+')
13
+ MINUS = new('-')
14
+ STAR = new('*')
15
+ SLASH = new('/')
16
+
17
+ def parse(input)
18
+ case input[0]
19
+ when @char then Maybe.return(Result.new(input[0], input[1..]))
20
+ else Maybe.none
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Chars
5
+ def initialize(chars)
6
+ @chars = chars
7
+ freeze
8
+ end
9
+
10
+ DIGITS = new(('0'..'9').to_a)
11
+ BASIC_MATH_OP = new(['+', '-', '*', '/'])
12
+
13
+ def parse(input)
14
+ case input[0]
15
+ when *@chars then Maybe.return(Result.new(input[0], input[1..]))
16
+ else Maybe.none
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Many
5
+ def initialize(parser)
6
+ @parser = parser
7
+ freeze
8
+ end
9
+
10
+ def parse(input)
11
+ @parser.parse(input)
12
+ .bind { |r| helper(r.rest, [r.token]) }
13
+ end
14
+
15
+ def helper(input, tokens = [])
16
+ @parser.parse(input)
17
+ .bind { |r| helper(r.rest, [*tokens, r.token]) }
18
+ .map_none { Result.new(tokens.join, input) }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Farseer
4
+ class Opt
5
+ def initialize(parser)
6
+ @parser = parser
7
+ freeze
8
+ end
9
+
10
+ def parse(input)
11
+ @parser.parse(input)
12
+ .map_none { Result.new('', input) }
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Farseer
4
- VERSION = '0.4.0'
4
+ VERSION = '0.6.0'
5
5
  public_constant :VERSION
6
6
  end
data/lib/farseer.rb CHANGED
@@ -10,11 +10,13 @@ module Farseer
10
10
  Maybe = Muina::Maybe
11
11
 
12
12
  def self.any_char_parser
13
- ->(chars, input) { Farseer.__send__(:any_char_parser_helper, chars, input) }.curry
13
+ ->(chars, input) { Chars.new(chars).parse(input) }
14
+ .curry
14
15
  end
15
16
 
16
17
  def self.char_parser
17
- ->(char, input) { Farseer.__send__(:char_parser_helper, char, input) }.curry
18
+ ->(char, input) { Char.new(char).parse(input) }
19
+ .curry
18
20
  end
19
21
 
20
22
  def self.ws_parser
@@ -24,23 +26,6 @@ module Farseer
24
26
  Maybe.return(Result.new(match[1], match[2]))
25
27
  }
26
28
  end
27
-
28
- private
29
-
30
- def self.char_parser_helper(char, input)
31
- case input[0]
32
- when char then Maybe.return(Result.new(input[0], input[1..]))
33
- else Maybe.none
34
- end
35
- end
36
-
37
- def self.any_char_parser_helper(chars, input)
38
- if chars.any? { |char| char == input[0] }
39
- Maybe.return(Result.new(input[0], input[1..]))
40
- else
41
- Maybe.none
42
- end
43
- end
44
29
  end
45
30
 
46
31
  loader.eager_load
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: farseer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaporyhumo
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: zeitwerk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,9 +45,16 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - CHANGELOG.md
48
49
  - LICENSE
49
50
  - README.md
51
+ - SECURITY.md
50
52
  - lib/farseer.rb
53
+ - lib/farseer/any.rb
54
+ - lib/farseer/char.rb
55
+ - lib/farseer/chars.rb
56
+ - lib/farseer/many.rb
57
+ - lib/farseer/opt.rb
51
58
  - lib/farseer/result.rb
52
59
  - lib/farseer/version.rb
53
60
  homepage: https://github.com/vaporyhumo/farseer