compser 0.2.0 → 0.2.1

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: 2772b2accc3f032d8ca438c0510c439d17bcd036339d33fbbb4c9aea8ac1292c
4
- data.tar.gz: cc6ee194f1f60bf428057eda00d43d7119d264939bea9acd54925b746d4d339f
3
+ metadata.gz: 323319e8a15dae0341e6c2c9def9238fb14587e5a90d65a4c2366ef6c6c67725
4
+ data.tar.gz: 6f3ec1d93cb1c702745f363bd586cbd85f18b9ec53c6d49b6fda2a856f63f86d
5
5
  SHA512:
6
- metadata.gz: 360a5566bf3d8fd5621662ec57d2a744e68a001ca72b66890a9b8095ab06e4ed7a26eae7bd965fff3f47c5eb35f8ad6c297db591de513fc7fdbf56ee0040d79d
7
- data.tar.gz: 65eef3b42ac80f16fadfe202e9d46e3fc84c48ef95c0f2cb76c42a37e69995f62bf21976fd6fee59c7b55fd80ac837fc7e457a8447e99eabfd7fb15dcf3b9a7d
6
+ metadata.gz: b69786e8a9a448ab47a494a2388e608e46546bea33902e0c68ecac9598655e92a7b1cc3abb2214b39a874fc97b3322c32a05228b53894fc3b5404c4212a48fb1
7
+ data.tar.gz: 6fe207a4536aa12062681558cfdf340709c0a9cab191cf9dea65c6f865c4260e5593ebfcd4e41ef10db56f77957b8c3d9b3de53bcf7bf047a03865282231a949
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compser (0.1.0)
4
+ compser (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Compser
2
2
 
3
- Compser is a parser builder library for Ruby inspired by [elm-parser](https://package.elm-lang.org/packages/elm/parser/latest/).
4
- Take a look at the [JSON parser](https://github.com/luizpvas/Compser/blob/main/examples/json.rb) to get a glimpse of the syntax
5
- and available building blocks you can use to compose more complex and sophisticated parsers.
3
+ Compser is a parser library for Ruby inspired by [elm-parser](https://package.elm-lang.org/packages/elm/parser/latest/).
4
+ Take a look at the [JSON parser](https://github.com/luizpvas/Compser/blob/main/examples/json.rb) and [Calculator](https://github.com/luizpvas/compser/blob/main/examples/calculator.rb) to get a glimpse of the syntax
5
+ and the building blocks you can sue to compose more complex and sophisticated parsers.
6
6
 
7
+ * [Installation](#installation)
7
8
  * Building blocks
8
9
  * [`drop`](#drop)
9
10
  * [`integer`](#integer)
@@ -20,6 +21,16 @@ and available building blocks you can use to compose more complex and sophistica
20
21
  * [`chomp_while`](#chomp_while)
21
22
  * [Benchmark](#benchmark)
22
23
 
24
+ ## Installation
25
+
26
+ Add the following line to your Gemfile:
27
+
28
+ ```ruby
29
+ gem 'compser', '~> 0.2'
30
+ ```
31
+
32
+ See more details at [https://rubygems.org/gems/compser](https://rubygems.org/gems/compser).
33
+
23
34
  #### `drop`
24
35
 
25
36
  Discard any result or chomped string produced by the parser.
@@ -3,8 +3,8 @@
3
3
  require_relative "../lib/compser"
4
4
 
5
5
  module Compser::Calculator
6
- extend Compser
7
6
  extend self
7
+ include Compser
8
8
 
9
9
  def evaluate(...)
10
10
  expression.parse(...)
data/examples/json.rb CHANGED
@@ -3,11 +3,11 @@
3
3
  require_relative "../lib/compser"
4
4
 
5
5
  module Compser::Json
6
- extend Compser
7
6
  extend self
7
+ include Compser
8
8
 
9
- def parse(str)
10
- value.parse(str)
9
+ def parse(...)
10
+ value.parse(...)
11
11
  end
12
12
 
13
13
  def value
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Compser::Step
4
- IsDigit = ->(char) do
5
- char =~ /\d/
6
- end
4
+ DIGIT = /\d/.freeze
5
+
6
+ IsDigit = ->(ch) { DIGIT.match?(ch) }
7
7
 
8
8
  NotFollowedByAlpha = ->(state) do
9
9
  return state if state.eof?
data/lib/compser/step.rb CHANGED
@@ -16,9 +16,9 @@ class Compser::Step
16
16
  token: Token.curry
17
17
  }.freeze
18
18
 
19
- def initialize(mapper = nil)
20
- @mapper = mapper
21
- @steps = []
19
+ def initialize(to_value = nil)
20
+ @to_value = to_value
21
+ @steps = []
22
22
  end
23
23
 
24
24
  def parse(src)
@@ -36,10 +36,10 @@ class Compser::Step
36
36
 
37
37
  results_after = state.result_stack.size
38
38
 
39
- if @mapper && state.good?
39
+ if @to_value && state.good?
40
40
  args = state.pop_results(results_after - results_before).map(&:value)
41
41
 
42
- state.good!(@mapper.call(*args))
42
+ state.good!(@to_value.call(*args))
43
43
  end
44
44
 
45
45
  state
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Compser
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/compser.rb CHANGED
@@ -24,12 +24,12 @@ module Compser
24
24
  Step.new
25
25
  end
26
26
 
27
- def map(mapper)
28
- Step.new(mapper)
27
+ def map(to_value)
28
+ Step.new(to_value)
29
29
  end
30
30
 
31
31
  def take(...)
32
- Step.new.and_then(...)
32
+ Step.new.take(...)
33
33
  end
34
34
 
35
35
  def drop(...)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Vasconcellos
@@ -72,5 +72,5 @@ requirements: []
72
72
  rubygems_version: 3.4.10
73
73
  signing_key:
74
74
  specification_version: 4
75
- summary: Compser is a parser builder library for Ruby.
75
+ summary: Compser is a parser library for Ruby inspired by elm-parser.
76
76
  test_files: []