d-parse 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 +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +104 -0
- data/Guardfile +3 -0
- data/LICENSE +19 -0
- data/NEWS.md +0 -0
- data/README.md +137 -0
- data/Rakefile +14 -0
- data/d-parse.gemspec +26 -0
- data/lib/d-parse.rb +10 -0
- data/lib/d-parse/dsl.rb +71 -0
- data/lib/d-parse/failure.rb +46 -0
- data/lib/d-parse/parser.rb +102 -0
- data/lib/d-parse/parsers.rb +26 -0
- data/lib/d-parse/parsers/combinators/alt.rb +32 -0
- data/lib/d-parse/parsers/combinators/repeat.rb +42 -0
- data/lib/d-parse/parsers/combinators/seq.rb +49 -0
- data/lib/d-parse/parsers/highlevel/char_in.rb +13 -0
- data/lib/d-parse/parsers/highlevel/intersperse.rb +18 -0
- data/lib/d-parse/parsers/highlevel/json.rb +237 -0
- data/lib/d-parse/parsers/highlevel/opt.rb +16 -0
- data/lib/d-parse/parsers/highlevel/string.rb +13 -0
- data/lib/d-parse/parsers/highlevel/whitespace_char.rb +15 -0
- data/lib/d-parse/parsers/modifiers/capturing.rb +13 -0
- data/lib/d-parse/parsers/modifiers/describe.rb +28 -0
- data/lib/d-parse/parsers/modifiers/ignore.rb +17 -0
- data/lib/d-parse/parsers/modifiers/lazy.rb +18 -0
- data/lib/d-parse/parsers/modifiers/map.rb +24 -0
- data/lib/d-parse/parsers/primitives/any.rb +22 -0
- data/lib/d-parse/parsers/primitives/bind.rb +25 -0
- data/lib/d-parse/parsers/primitives/char.rb +27 -0
- data/lib/d-parse/parsers/primitives/char_not.rb +27 -0
- data/lib/d-parse/parsers/primitives/char_not_in.rb +30 -0
- data/lib/d-parse/parsers/primitives/eof.rb +21 -0
- data/lib/d-parse/parsers/primitives/except.rb +33 -0
- data/lib/d-parse/parsers/primitives/fail.rb +17 -0
- data/lib/d-parse/parsers/primitives/succeed.rb +13 -0
- data/lib/d-parse/position.rb +31 -0
- data/lib/d-parse/success.rb +35 -0
- data/lib/d-parse/version.rb +3 -0
- data/samples/parse-bind +25 -0
- data/samples/parse-csv +19 -0
- data/samples/parse-errortest +45 -0
- data/samples/parse-fun +61 -0
- data/samples/parse-json +18 -0
- data/samples/parse-readme +27 -0
- data/spec/d-parse/failure_spec.rb +36 -0
- data/spec/d-parse/parser_spec.rb +77 -0
- data/spec/d-parse/parsers/alt_spec.rb +48 -0
- data/spec/d-parse/parsers/any_spec.rb +15 -0
- data/spec/d-parse/parsers/bind_spec.rb +31 -0
- data/spec/d-parse/parsers/capture_spec.rb +11 -0
- data/spec/d-parse/parsers/char_in_spec.rb +22 -0
- data/spec/d-parse/parsers/char_not_in_spec.rb +23 -0
- data/spec/d-parse/parsers/char_not_spec.rb +16 -0
- data/spec/d-parse/parsers/char_spec.rb +22 -0
- data/spec/d-parse/parsers/describe_spec.rb +22 -0
- data/spec/d-parse/parsers/end_of_input_spec.rb +20 -0
- data/spec/d-parse/parsers/except_spec.rb +20 -0
- data/spec/d-parse/parsers/fail_spec.rb +12 -0
- data/spec/d-parse/parsers/intersperse_spec.rb +18 -0
- data/spec/d-parse/parsers/json_spec.rb +69 -0
- data/spec/d-parse/parsers/lazy_spec.rb +16 -0
- data/spec/d-parse/parsers/map_spec.rb +54 -0
- data/spec/d-parse/parsers/optional_spec.rb +16 -0
- data/spec/d-parse/parsers/or_spec.rb +26 -0
- data/spec/d-parse/parsers/repeat_spec.rb +40 -0
- data/spec/d-parse/parsers/sequence_spec.rb +52 -0
- data/spec/d-parse/parsers/string_spec.rb +19 -0
- data/spec/d-parse/parsers/succeed_spec.rb +12 -0
- data/spec/d-parse/parsers/whitespace_char_spec.rb +14 -0
- data/spec/spec_helper.rb +97 -0
- metadata +140 -0
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            describe DParse::Parsers::String do
         | 
| 2 | 
            +
              let(:parser) { described_class.new('donkey') }
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              example { expect(parser).to parse('donkey').up_to(6) }
         | 
| 5 | 
            +
              example { expect(parser).to parse('donkeys').up_to(6) }
         | 
| 6 | 
            +
              example { expect(parser).to parse('donkey mania').up_to(6) }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              example { expect(parser).not_to parse('') }
         | 
| 9 | 
            +
              example { expect(parser).not_to parse('d') }
         | 
| 10 | 
            +
              example { expect(parser).not_to parse('donke') }
         | 
| 11 | 
            +
              example { expect(parser).not_to parse('some donkey') }
         | 
| 12 | 
            +
              example { expect(parser).not_to parse('giraffe') }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              describe '#inspect' do
         | 
| 15 | 
            +
                subject { parser.inspect }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                it { is_expected.to eql('seq(char("d"),char("o"),char("n"),char("k"),char("e"),char("y"))') }
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            describe DParse::Parsers::Succeed do
         | 
| 2 | 
            +
              let(:parser) { described_class.new }
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              example { expect(parser).to parse('').up_to(0).line(0).column(0) }
         | 
| 5 | 
            +
              example { expect(parser).to parse('a').up_to(0).line(0).column(0) }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              describe '#inspect' do
         | 
| 8 | 
            +
                subject { parser.inspect }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it { is_expected.to eql('succeed()') }
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            describe DParse::Parsers::WhitespaceChar do
         | 
| 2 | 
            +
              let(:parser) { described_class.new }
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              example { expect(parser).to parse(' ').up_to(1) }
         | 
| 5 | 
            +
              example { expect(parser).to parse("\t").up_to(1) }
         | 
| 6 | 
            +
              example { expect(parser).to parse("\t ").up_to(1) }
         | 
| 7 | 
            +
              example { expect(parser).to parse(" \t").up_to(1) }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              describe '#inspect' do
         | 
| 10 | 
            +
                subject { parser.inspect }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                it { is_expected.to eql('alt(char(" "),char("\\t"))') }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,97 @@ | |
| 1 | 
            +
            require 'rspec'
         | 
| 2 | 
            +
            require 'coveralls'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Coveralls.wear!
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'd-parse'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            RSpec::Matchers.define :parse do |text|
         | 
| 9 | 
            +
              match do |actual|
         | 
| 10 | 
            +
                res = actual.apply(text)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                conditions = [
         | 
| 13 | 
            +
                  res.is_a?(DParse::Success),
         | 
| 14 | 
            +
                  -> { (@new_pos.nil? || res.pos.index == @new_pos) },
         | 
| 15 | 
            +
                  -> { (@line.nil? || res.pos.line == @line) },
         | 
| 16 | 
            +
                  -> { (@column.nil? || res.pos.column == @column) },
         | 
| 17 | 
            +
                  -> { (@capture.nil? || @capture == res.data) },
         | 
| 18 | 
            +
                ]
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                conditions.all? { |e| e.respond_to?(:call) ? e.call : e }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              match_when_negated do |actual|
         | 
| 24 | 
            +
                res = actual.read(text, DParse::Position.new)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                conditions = [
         | 
| 27 | 
            +
                  res.is_a?(DParse::Failure),
         | 
| 28 | 
            +
                  -> { (@new_pos.nil? || res.pos.index == @new_pos) },
         | 
| 29 | 
            +
                  -> { (@line.nil? || res.pos.line == @line) },
         | 
| 30 | 
            +
                  -> { (@column.nil? || res.pos.column == @column) },
         | 
| 31 | 
            +
                  -> { (@failure_msg.nil? || res.message == @failure_msg) },
         | 
| 32 | 
            +
                ]
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                conditions.all? { |e| e.respond_to?(:call) ? e.call : e }
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              failure_message do |actual| # expected success, is other success or failure
         | 
| 38 | 
            +
                res = actual.read(text, DParse::Position.new)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                s = []
         | 
| 41 | 
            +
                s << "parse #{expected.inspect}"
         | 
| 42 | 
            +
                case res
         | 
| 43 | 
            +
                when DParse::Failure
         | 
| 44 | 
            +
                  s << "and not fail (rather than fail with #{res.message.inspect})"
         | 
| 45 | 
            +
                when DParse::Success
         | 
| 46 | 
            +
                  s << "up to position #{@new_pos} (rather than #{res.pos.index})" if @new_pos && @new_pos != res.pos.index
         | 
| 47 | 
            +
                  s << "line #{@line} (rather than #{res.pos.line})" if @line && @line != res.pos.line
         | 
| 48 | 
            +
                  s << "column #{@column} (rather than #{res.pos.column})" if @column && @column != res.pos.column
         | 
| 49 | 
            +
                  s << "and capture #{@capture.inspect} (rather than #{res.data.inspect})" if @capture && @capture != res.data
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                "expected #{actual} to #{s.join(' ')}"
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              failure_message_when_negated do |actual| # expected failure, is other failure or success
         | 
| 56 | 
            +
                res = actual.read(text, DParse::Position.new)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                s = []
         | 
| 59 | 
            +
                s << "not to parse #{expected.inspect}"
         | 
| 60 | 
            +
                case res
         | 
| 61 | 
            +
                when DParse::Success
         | 
| 62 | 
            +
                  s << "and fail (rather than parse up to #{res.pos.inspect})"
         | 
| 63 | 
            +
                when DParse::Failure
         | 
| 64 | 
            +
                  buts = []
         | 
| 65 | 
            +
                  buts << "with #{@failure_msg.inspect} (rather than #{res.message.inspect})" if @failure_msg && @failure_msg != res.message
         | 
| 66 | 
            +
                  buts << "at position #{@new_pos} (rather than #{res.pos.index})" if @new_pos && @new_pos != res.pos.index
         | 
| 67 | 
            +
                  buts << "line #{@line} (rather than #{res.pos.line})" if @line && @line != res.pos.line
         | 
| 68 | 
            +
                  buts << "column #{@column} (rather than #{res.pos.column})" if @column && @column != res.pos.column
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  s <<
         | 
| 71 | 
            +
                    if buts.any?
         | 
| 72 | 
            +
                      "and fail, but #{buts.join(', ')}"
         | 
| 73 | 
            +
                    else
         | 
| 74 | 
            +
                      'and fail'
         | 
| 75 | 
            +
                    end
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                "expected #{actual} to #{s.join(' ')}"
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              chain :up_to, :new_pos
         | 
| 82 | 
            +
              chain :and_fail_at, :new_pos
         | 
| 83 | 
            +
              chain :column, :column
         | 
| 84 | 
            +
              chain :line, :line
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              chain :and_capture, :capture
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              chain :with_failure, :failure_msg
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              description do
         | 
| 91 | 
            +
                s = []
         | 
| 92 | 
            +
                s << "parse #{expected.inspect}"
         | 
| 93 | 
            +
                s << "up to position #{@new_pos}" if @new_pos
         | 
| 94 | 
            +
                s << "and capture #{@capture.inspect}" if @capture
         | 
| 95 | 
            +
                s.join(' ')
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,140 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: d-parse
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: '0.1'
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Denis Defreyne
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-07-02 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 1.11.2
         | 
| 20 | 
            +
                - - "<"
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: '2.0'
         | 
| 23 | 
            +
              type: :development
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ">="
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 1.11.2
         | 
| 30 | 
            +
                - - "<"
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '2.0'
         | 
| 33 | 
            +
            description: D★Parse is a library for building parser combinators.
         | 
| 34 | 
            +
            email: denis.defreyne@stoneship.org
         | 
| 35 | 
            +
            executables: []
         | 
| 36 | 
            +
            extensions: []
         | 
| 37 | 
            +
            extra_rdoc_files:
         | 
| 38 | 
            +
            - LICENSE
         | 
| 39 | 
            +
            - README.md
         | 
| 40 | 
            +
            - NEWS.md
         | 
| 41 | 
            +
            files:
         | 
| 42 | 
            +
            - Gemfile
         | 
| 43 | 
            +
            - Gemfile.lock
         | 
| 44 | 
            +
            - Guardfile
         | 
| 45 | 
            +
            - LICENSE
         | 
| 46 | 
            +
            - NEWS.md
         | 
| 47 | 
            +
            - README.md
         | 
| 48 | 
            +
            - Rakefile
         | 
| 49 | 
            +
            - d-parse.gemspec
         | 
| 50 | 
            +
            - lib/d-parse.rb
         | 
| 51 | 
            +
            - lib/d-parse/dsl.rb
         | 
| 52 | 
            +
            - lib/d-parse/failure.rb
         | 
| 53 | 
            +
            - lib/d-parse/parser.rb
         | 
| 54 | 
            +
            - lib/d-parse/parsers.rb
         | 
| 55 | 
            +
            - lib/d-parse/parsers/combinators/alt.rb
         | 
| 56 | 
            +
            - lib/d-parse/parsers/combinators/repeat.rb
         | 
| 57 | 
            +
            - lib/d-parse/parsers/combinators/seq.rb
         | 
| 58 | 
            +
            - lib/d-parse/parsers/highlevel/char_in.rb
         | 
| 59 | 
            +
            - lib/d-parse/parsers/highlevel/intersperse.rb
         | 
| 60 | 
            +
            - lib/d-parse/parsers/highlevel/json.rb
         | 
| 61 | 
            +
            - lib/d-parse/parsers/highlevel/opt.rb
         | 
| 62 | 
            +
            - lib/d-parse/parsers/highlevel/string.rb
         | 
| 63 | 
            +
            - lib/d-parse/parsers/highlevel/whitespace_char.rb
         | 
| 64 | 
            +
            - lib/d-parse/parsers/modifiers/capturing.rb
         | 
| 65 | 
            +
            - lib/d-parse/parsers/modifiers/describe.rb
         | 
| 66 | 
            +
            - lib/d-parse/parsers/modifiers/ignore.rb
         | 
| 67 | 
            +
            - lib/d-parse/parsers/modifiers/lazy.rb
         | 
| 68 | 
            +
            - lib/d-parse/parsers/modifiers/map.rb
         | 
| 69 | 
            +
            - lib/d-parse/parsers/primitives/any.rb
         | 
| 70 | 
            +
            - lib/d-parse/parsers/primitives/bind.rb
         | 
| 71 | 
            +
            - lib/d-parse/parsers/primitives/char.rb
         | 
| 72 | 
            +
            - lib/d-parse/parsers/primitives/char_not.rb
         | 
| 73 | 
            +
            - lib/d-parse/parsers/primitives/char_not_in.rb
         | 
| 74 | 
            +
            - lib/d-parse/parsers/primitives/eof.rb
         | 
| 75 | 
            +
            - lib/d-parse/parsers/primitives/except.rb
         | 
| 76 | 
            +
            - lib/d-parse/parsers/primitives/fail.rb
         | 
| 77 | 
            +
            - lib/d-parse/parsers/primitives/succeed.rb
         | 
| 78 | 
            +
            - lib/d-parse/position.rb
         | 
| 79 | 
            +
            - lib/d-parse/success.rb
         | 
| 80 | 
            +
            - lib/d-parse/version.rb
         | 
| 81 | 
            +
            - samples/parse-bind
         | 
| 82 | 
            +
            - samples/parse-csv
         | 
| 83 | 
            +
            - samples/parse-errortest
         | 
| 84 | 
            +
            - samples/parse-fun
         | 
| 85 | 
            +
            - samples/parse-json
         | 
| 86 | 
            +
            - samples/parse-readme
         | 
| 87 | 
            +
            - spec/d-parse/failure_spec.rb
         | 
| 88 | 
            +
            - spec/d-parse/parser_spec.rb
         | 
| 89 | 
            +
            - spec/d-parse/parsers/alt_spec.rb
         | 
| 90 | 
            +
            - spec/d-parse/parsers/any_spec.rb
         | 
| 91 | 
            +
            - spec/d-parse/parsers/bind_spec.rb
         | 
| 92 | 
            +
            - spec/d-parse/parsers/capture_spec.rb
         | 
| 93 | 
            +
            - spec/d-parse/parsers/char_in_spec.rb
         | 
| 94 | 
            +
            - spec/d-parse/parsers/char_not_in_spec.rb
         | 
| 95 | 
            +
            - spec/d-parse/parsers/char_not_spec.rb
         | 
| 96 | 
            +
            - spec/d-parse/parsers/char_spec.rb
         | 
| 97 | 
            +
            - spec/d-parse/parsers/describe_spec.rb
         | 
| 98 | 
            +
            - spec/d-parse/parsers/end_of_input_spec.rb
         | 
| 99 | 
            +
            - spec/d-parse/parsers/except_spec.rb
         | 
| 100 | 
            +
            - spec/d-parse/parsers/fail_spec.rb
         | 
| 101 | 
            +
            - spec/d-parse/parsers/intersperse_spec.rb
         | 
| 102 | 
            +
            - spec/d-parse/parsers/json_spec.rb
         | 
| 103 | 
            +
            - spec/d-parse/parsers/lazy_spec.rb
         | 
| 104 | 
            +
            - spec/d-parse/parsers/map_spec.rb
         | 
| 105 | 
            +
            - spec/d-parse/parsers/optional_spec.rb
         | 
| 106 | 
            +
            - spec/d-parse/parsers/or_spec.rb
         | 
| 107 | 
            +
            - spec/d-parse/parsers/repeat_spec.rb
         | 
| 108 | 
            +
            - spec/d-parse/parsers/sequence_spec.rb
         | 
| 109 | 
            +
            - spec/d-parse/parsers/string_spec.rb
         | 
| 110 | 
            +
            - spec/d-parse/parsers/succeed_spec.rb
         | 
| 111 | 
            +
            - spec/d-parse/parsers/whitespace_char_spec.rb
         | 
| 112 | 
            +
            - spec/spec_helper.rb
         | 
| 113 | 
            +
            homepage: http://rubygems.org/gems/d-parse
         | 
| 114 | 
            +
            licenses:
         | 
| 115 | 
            +
            - MIT
         | 
| 116 | 
            +
            metadata: {}
         | 
| 117 | 
            +
            post_install_message: 
         | 
| 118 | 
            +
            rdoc_options:
         | 
| 119 | 
            +
            - "--main"
         | 
| 120 | 
            +
            - README.md
         | 
| 121 | 
            +
            require_paths:
         | 
| 122 | 
            +
            - lib
         | 
| 123 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 124 | 
            +
              requirements:
         | 
| 125 | 
            +
              - - ">="
         | 
| 126 | 
            +
                - !ruby/object:Gem::Version
         | 
| 127 | 
            +
                  version: 2.1.0
         | 
| 128 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
              requirements:
         | 
| 130 | 
            +
              - - ">="
         | 
| 131 | 
            +
                - !ruby/object:Gem::Version
         | 
| 132 | 
            +
                  version: '0'
         | 
| 133 | 
            +
            requirements: []
         | 
| 134 | 
            +
            rubyforge_project: 
         | 
| 135 | 
            +
            rubygems_version: 2.6.6
         | 
| 136 | 
            +
            signing_key: 
         | 
| 137 | 
            +
            specification_version: 4
         | 
| 138 | 
            +
            summary: parser combinator library
         | 
| 139 | 
            +
            test_files: []
         | 
| 140 | 
            +
            has_rdoc: 
         |