parser_combinator_dsl 1.0.0 → 1.0.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: 8ebac413cd45e47ff7de3b0b5d4aeb6c98dd265434620206e2ffd5c2d9f910ea
4
- data.tar.gz: 9ef20b739416d15763b8a1c9451245a54a509ebd9e0436046a735d3db0200575
3
+ metadata.gz: f4f09f2cab4d3a7ec337902226fa25de2b6dfd194d2cc1ac4e7c00bff724eb54
4
+ data.tar.gz: aaa5b7b18fca3ef2334a0bea97820aef96f732adf2b089c02ef71479832ca914
5
5
  SHA512:
6
- metadata.gz: c357783a6d1dd1009f7f3a329f7647764de90378e8ddc671f01d644080336886e950a009388c822772fd8fb05366a1025241966be7930e508dca6dd06878fcac
7
- data.tar.gz: 6073c6130917b7eeeb21d597224f4349732e4075454d6634cafcb2248bed3a95c627d687fa4638604158ce3dc62a07ed730e616a799f2c5530609919a358e84c
6
+ metadata.gz: f9926cf30554094f1fd5f736e52bc1173fb8ed857af09013de7a534c6f9ffaa6f332493ddbd58ad597b5213cd84c6ce36f8e24f68340adf62aef7f3ea05ceae7
7
+ data.tar.gz: 99e2a534ccbecbd89976c18f3bf85af51c04819367dbb454c4da76529af728d233ffaddd0d50abd9fb9af2901d309af0ecbcc751b32ea72bf035dc212688f372
data/lib/base_parsers.rb CHANGED
@@ -153,12 +153,16 @@ module BaseParsers
153
153
  Parser.new do |input|
154
154
  first_char = input[0]
155
155
  result = ParserResult.ok(matched: first_char, remaining: input[1..-1])
156
-
157
- chars.each do |char|
158
- if first_char == char
159
- result = ParserResult.fail(input)
160
- break
156
+
157
+ if !(input == "" || input.nil?)
158
+ chars.each do |char|
159
+ if first_char == char
160
+ result = ParserResult.fail(input)
161
+ break
162
+ end
161
163
  end
164
+ else
165
+ result = ParserResult.fail(input)
162
166
  end
163
167
 
164
168
  result
data/test/spec_helpers.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  def assert_parses(parser, with:, remaining:, matched: nil, should_fail: false)
2
2
  result = parser.run(with)
3
+ puts "with: " + with.to_s + " matched: " + result.matched.to_s + " remaining: " + result.remaining.to_s + " success: " + result.success.to_s
3
4
  assert_equal !should_fail, result.success
4
5
  assert_equal remaining, result.remaining
5
6
  assert_equal matched, result.matched unless matched.nil?
@@ -102,6 +102,18 @@ describe Grammar do
102
102
  assert_parses parser, with: "asd123", remaining: "123"
103
103
  end
104
104
 
105
+ it "matches many1 chars except newlines, followed by newline(s)" do
106
+ parser = Grammar.build do
107
+ rule(:eol) { many1 { anyChar(["\n"]) } | eof }
108
+ rule(:stuff) { many1 { anyCharBut(["\n"]) } >> (rule :eol) }
109
+ start(:stuff)
110
+ end
111
+
112
+ assert_parses parser, with: "Some stuff 123", remaining: ""
113
+ assert_parses parser, with: "Some stuff 123 \n thisremains", remaining: " thisremains"
114
+ assert_parses parser, with: "Some stuff 123öäü\nthisremains", remaining: "thisremains"
115
+ end
116
+
105
117
  it "matches many0" do
106
118
  parser = Grammar.build do
107
119
  rule(:word) { many0 { anyLetter } }
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_combinator_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Ramirez
8
+ - Matthias Ervens
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-05-20 00:00:00.000000000 Z
12
+ date: 2018-05-21 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: "\n\tThis library provides a DSL which you can use to easily generate
14
15
  parsers in Ruby.\n\n\tAt it's core, it's a parser combinator library, but you don't
15
16
  need to worry about that. You build more complex expression based on simple ones,
16
- and match any formal language you want.\n\t"
17
+ and match any formal language you want.\n\n\tOriginally by Federico Ramirez (https://github.com/gosukiwi)\n\t"
17
18
  email:
18
19
  executables: []
19
20
  extensions: []