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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -3
- data/examples/calculator.rb +1 -1
- data/examples/json.rb +3 -3
- data/lib/compser/step/integer.rb +3 -3
- data/lib/compser/step.rb +5 -5
- data/lib/compser/version.rb +1 -1
- data/lib/compser.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 323319e8a15dae0341e6c2c9def9238fb14587e5a90d65a4c2366ef6c6c67725
|
4
|
+
data.tar.gz: 6f3ec1d93cb1c702745f363bd586cbd85f18b9ec53c6d49b6fda2a856f63f86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b69786e8a9a448ab47a494a2388e608e46546bea33902e0c68ecac9598655e92a7b1cc3abb2214b39a874fc97b3322c32a05228b53894fc3b5404c4212a48fb1
|
7
|
+
data.tar.gz: 6fe207a4536aa12062681558cfdf340709c0a9cab191cf9dea65c6f865c4260e5593ebfcd4e41ef10db56f77957b8c3d9b3de53bcf7bf047a03865282231a949
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# Compser
|
2
2
|
|
3
|
-
Compser is a parser
|
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
|
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.
|
data/examples/calculator.rb
CHANGED
data/examples/json.rb
CHANGED
data/lib/compser/step/integer.rb
CHANGED
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(
|
20
|
-
@
|
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 @
|
39
|
+
if @to_value && state.good?
|
40
40
|
args = state.pop_results(results_after - results_before).map(&:value)
|
41
41
|
|
42
|
-
state.good!(@
|
42
|
+
state.good!(@to_value.call(*args))
|
43
43
|
end
|
44
44
|
|
45
45
|
state
|
data/lib/compser/version.rb
CHANGED
data/lib/compser.rb
CHANGED
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.
|
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
|
75
|
+
summary: Compser is a parser library for Ruby inspired by elm-parser.
|
76
76
|
test_files: []
|