farseer 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/farseer/char.rb +24 -0
- data/lib/farseer/chars.rb +18 -0
- data/lib/farseer/version.rb +1 -1
- data/lib/farseer.rb +8 -12
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faf7eb2a08edee2ef9fac3c334377895fdec31998d3f4de95f97d87c6cdc8d25
|
4
|
+
data.tar.gz: af09bea3a95f554886f66ef09034a0723c7384d57a924534a94da1166ea8d2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9da67d2aeab63fc0d89e43d9034ebc9f3c4abe5e79736d2508231907ed1acaff01cb6e7cb0e3337f0c06540977a97c07d0badd1e632e8aaf474c07a42fe044f2
|
7
|
+
data.tar.gz: a27eb0388cf156ee964a90788de733bd9ad923ef1abbde9a7121812ffd30021c15d806ea0a108f9772ed3af3e4a06c8e2f699b4412afa383dfab297ff98989f1
|
data/lib/farseer/char.rb
ADDED
@@ -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,18 @@
|
|
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
|
+
def parse(input)
|
11
|
+
if @chars.any? { |char| char == input[0] }
|
12
|
+
Maybe.return(Result.new(input[0], input[1..]))
|
13
|
+
else
|
14
|
+
Maybe.none
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/farseer/version.rb
CHANGED
data/lib/farseer.rb
CHANGED
@@ -9,27 +9,23 @@ module Farseer
|
|
9
9
|
WS_REGEX = /^(\s*)(.*)$/
|
10
10
|
Maybe = Muina::Maybe
|
11
11
|
|
12
|
-
|
12
|
+
def self.any_char_parser
|
13
|
+
->(chars, input) { Chars.new(chars).parse(input) }
|
14
|
+
.curry
|
15
|
+
end
|
13
16
|
|
14
|
-
def char_parser
|
15
|
-
->(char, input) {
|
17
|
+
def self.char_parser
|
18
|
+
->(char, input) { Char.new(char).parse(input) }
|
19
|
+
.curry
|
16
20
|
end
|
17
21
|
|
18
|
-
def ws_parser
|
22
|
+
def self.ws_parser
|
19
23
|
->(input) {
|
20
24
|
match = input.match(WS_REGEX)
|
21
25
|
|
22
26
|
Maybe.return(Result.new(match[1], match[2]))
|
23
27
|
}
|
24
28
|
end
|
25
|
-
|
26
|
-
def char_parser_helper(char, input)
|
27
|
-
case input[0]
|
28
|
-
when char then Maybe.return(Result.new(input[0], input[1..]))
|
29
|
-
else Maybe.none
|
30
|
-
end
|
31
|
-
end
|
32
|
-
private :char_parser_helper
|
33
29
|
end
|
34
30
|
|
35
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
|
+
version: 0.5.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.
|
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.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: zeitwerk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,6 +48,8 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- lib/farseer.rb
|
51
|
+
- lib/farseer/char.rb
|
52
|
+
- lib/farseer/chars.rb
|
51
53
|
- lib/farseer/result.rb
|
52
54
|
- lib/farseer/version.rb
|
53
55
|
homepage: https://github.com/vaporyhumo/farseer
|