ldpath 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7fcb1c90659a5df73d2317bb95e7b6e94a084b6
4
+ data.tar.gz: 126daa1e8f17111e55ee2778d3b1e0a20a44b486
5
+ SHA512:
6
+ metadata.gz: 16bbc3af47c263842b9ae8d370103cacc2b23665da21e1420cdd2c667b3c90dd8e0063e34339b8924b8c47aea8eeb4db54d84b4eca0502bfb100be895ec9c467
7
+ data.tar.gz: d9fc526a8eaa84254990752f45476244bfd826d83136b14c9304bd9316765ab3f4d361431a071967cd87d28f9ee2bafccd2285b83c0ac81e597fe207e00376eb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ldpath.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Beer
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Ldpath
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ldpath'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ldpath
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/ldpath/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/ldpath.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ldpath/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ldpath"
8
+ spec.version = Ldpath::VERSION
9
+ spec.authors = ["Chris Beer"]
10
+ spec.email = ["cabeer@stanford.edu"]
11
+ spec.summary = %q{Ruby implementation of LDPath}
12
+ spec.homepage = "http://github.com/cbeer"
13
+ spec.license = "Apache 2"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "parslet"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ end
data/lib/ldpath.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "ldpath/version"
2
+
3
+ module Ldpath
4
+ require 'ldpath/program'
5
+ end
@@ -0,0 +1,259 @@
1
+ require 'parslet'
2
+
3
+ class Ldpath::Program < Parslet::Parser
4
+ root :lines
5
+ rule(:lines) { line.repeat }
6
+ rule(:line) { expression >> newline }
7
+ rule(:newline) { any.absent? | str("\n") >> str("\r").maybe }
8
+ rule(:expression) { wsp | multiline_comment | namespace | mapping }
9
+
10
+ rule(:multiline_comment) { (str('/*') >> (str('*/').absent? >> any).repeat >> str('*/')) }
11
+
12
+ rule(:comma) { str(",") }
13
+ rule(:scolon) { str(";") }
14
+ rule(:colon) { str(":") }
15
+ rule(:dcolon) { str("::") }
16
+ rule(:assign) { str("=") }
17
+ rule(:k_prefix) { str("@prefix")}
18
+ rule(:k_graph) { str("@graph")}
19
+
20
+ rule(:self_op) { str(".") }
21
+ rule(:and_op) { str("&") }
22
+ rule(:or_op) { str("|") }
23
+ rule(:p_sep) { str("/") }
24
+ rule(:plus) { str("+") }
25
+ rule(:star) { str("*") }
26
+ rule(:not_op) { str("!") }
27
+ rule(:inverse) { str("^") }
28
+ rule(:is) { str "is" }
29
+ rule(:is_a) { str "is-a" }
30
+ rule(:func) { str "fn:"}
31
+ rule(:type) { str "^^" }
32
+ rule(:lang) { str "@" }
33
+
34
+ rule(:wsp) { (match["\s"] | str("\n")).repeat(1) }
35
+ rule(:wsp?) { wsp.maybe }
36
+
37
+ # todo: fixme
38
+ rule(:uri) { (str("<") >> (str(">").absent? >> any).repeat >> str(">")) | (identifier.as(:prefix) >> str(":") >> identifier.as(:localName) )}
39
+ rule(:identifier) { match["a-zA-Z0-9_"] >> (match["a-zA-Z0-9_'\\.-"]).repeat }
40
+
41
+ rule(:namespace) {
42
+ k_prefix >>
43
+ wsp? >>
44
+ identifier.as(:id) >>
45
+ wsp? >>
46
+ colon >>
47
+ wsp? >>
48
+ uri.as(:uri) >>
49
+ wsp? >>
50
+ scolon.maybe
51
+ }
52
+
53
+ rule(:mapping) {
54
+ name_selector_mapping
55
+ }
56
+
57
+ rule(:name_selector_mapping) {
58
+ identifier.as(:name) >>
59
+ wsp? >>
60
+ assign >>
61
+ wsp? >>
62
+ selector.as(:selector) >>
63
+ wsp? >>
64
+ (
65
+ dcolon >> wsp? >>
66
+ uri.as(:type)
67
+ ).maybe >>
68
+ wsp? >>
69
+ scolon
70
+ }
71
+
72
+ rule(:selector) {
73
+ (
74
+ compound_selector |
75
+ testing_selector |
76
+ atomic_selector
77
+ ).as(:result)
78
+ }
79
+
80
+ rule(:compound_selector) {
81
+ (
82
+ union_selector |
83
+ intersection_selector |
84
+ path_selector
85
+ ).as(:result)
86
+ }
87
+
88
+ rule(:grouped_selector) {
89
+ wsp? >>
90
+ str("(") >> wsp? >> selector.as(:result) >> wsp? >> str(")") >> wsp?
91
+ }
92
+
93
+ rule(:path_selector) {
94
+ wsp? >>
95
+ atomic_or_testing_selector.as(:left) >>
96
+ wsp? >>
97
+ p_sep >>
98
+ wsp? >>
99
+ atomic_or_testing_or_path_selector.as(:right) >>
100
+ wsp?
101
+ }
102
+
103
+ rule(:intersection_selector) {
104
+ wsp? >>
105
+ atomic_or_testing_or_path_selector.as(:left) >>
106
+ wsp? >>
107
+ and_op >>
108
+ wsp? >>
109
+ selector.as(:right) >>
110
+ wsp?
111
+ }
112
+
113
+ rule(:union_selector) {
114
+ wsp? >>
115
+ atomic_or_testing_or_path_selector.as(:left) >>
116
+
117
+ wsp? >>
118
+ or_op >>
119
+
120
+ wsp? >>
121
+ selector.as(:right) >>
122
+
123
+ wsp?
124
+ }
125
+
126
+ rule(:atomic_or_testing_or_path_selector) {
127
+ (path_selector | atomic_or_testing_selector).as(:result)
128
+ }
129
+
130
+ rule(:atomic_or_testing_selector) {
131
+ (testing_selector | atomic_selector).as(:result)
132
+ }
133
+
134
+ rule(:atomic_selector) {
135
+ (
136
+ self_selector |
137
+ property_selector |
138
+ wildcard_selector |
139
+ reverse_property_selector |
140
+ function_selector |
141
+ # string_constant_selector |
142
+ # recursive_path_selector |
143
+ grouped_selector
144
+ ).as(:result)
145
+ }
146
+
147
+ rule(:self_selector) {
148
+ wsp? >> self_op >> wsp?
149
+ }
150
+
151
+ rule(:property_selector) {
152
+ wsp? >> uri >> wsp?
153
+ }
154
+
155
+ rule(:reverse_property_selector) {
156
+ wsp? >> inverse >> uri.as(:uri) >> wsp?
157
+ }
158
+
159
+ rule(:wildcard_selector) {
160
+ wsp? >> star >> wsp?
161
+ }
162
+
163
+ rule(:testing_selector) {
164
+ wsp? >>
165
+ atomic_selector.as(:delegate) >>
166
+ str("[") >>
167
+ wsp? >>
168
+ node_test.as(:test) >>
169
+ wsp? >>
170
+ str("]") >> wsp?
171
+ }
172
+
173
+ rule(:node_test) {
174
+ grouped_test |
175
+ not_test |
176
+ and_test |
177
+ or_test |
178
+ atomic_node_test
179
+ }
180
+
181
+ rule(:grouped_test) {
182
+ wsp? >> str("(") >> wsp? >> node_test >> wsp? >> str(")") >> wsp?
183
+ }
184
+
185
+ rule(:atomic_node_test) {
186
+ # literal_language_test |
187
+ # literal_type_test |
188
+ is_a_test |
189
+ path_equality_test |
190
+ function_test |
191
+ path_test
192
+ }
193
+
194
+ rule(:not_test) {
195
+ wsp? >> not_op >> node_test.as(:delegate) >> wsp?
196
+ }
197
+
198
+ rule(:and_test) {
199
+ wsp? >> atomic_node_test >> wsp? >> and_op >> wsp? >> node_test >> wsp?
200
+ }
201
+
202
+ rule(:or_test) {
203
+ wsp? >> atomic_node_test >> wsp? >> or_op >> wsp? >> node_test >> wsp?
204
+ }
205
+
206
+ rule(:strlit) {
207
+ wsp? >> str('"') >> (str('"').absent? >> any).repeat >> str('"') >> wsp?
208
+ }
209
+
210
+ rule(:node) {
211
+ uri.as(:uri) | strlit.as(:literal)
212
+ }
213
+
214
+ rule(:is_a_test) {
215
+ wsp? >> is_a >> wsp? >> node.as(:node) >> wsp?
216
+ }
217
+
218
+ rule(:path_equality_test) {
219
+ selector.as(:path) >> is >> node.as(:node)
220
+ }
221
+
222
+ rule(:function_selector) {
223
+ (
224
+ func >> identifier.as(:fname) >> str("()") |
225
+ func >> identifier.as(:fname) >> str("(") >>
226
+ wsp? >>
227
+ (selector.as(:argument)) >>
228
+ (
229
+ (wsp? >> str(",") >> wsp? >> selector.as(:argument)).repeat
230
+ ).maybe >>
231
+ wsp? >>
232
+ str(")")
233
+ )
234
+ }
235
+
236
+ rule(:function_test) {
237
+ (
238
+ func >> identifier.as(:fname) >> str("()") |
239
+ func >> identifier.as(:fname) >> str("(") >>
240
+ wsp? >>
241
+ (selector.as(:argument)) >>
242
+ (
243
+ (wsp? >> str(",") >> wsp? >> selector.as(:argument)).repeat
244
+ ).maybe >>
245
+ wsp? >>
246
+ str(")")
247
+ )
248
+ }
249
+
250
+ rule(:path_test) {
251
+ (
252
+ path_selector |
253
+ testing_selector |
254
+ atomic_selector
255
+ ).as(:path)
256
+ }
257
+
258
+
259
+ end
@@ -0,0 +1,3 @@
1
+ module Ldpath
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ require 'parslet/convenience'
4
+ describe Ldpath::Program do
5
+ subject { Ldpath::Program.new }
6
+ context ".parse" do
7
+ it "should work" do
8
+ subject.parse ""
9
+ subject.parse "\n\n"
10
+ end
11
+
12
+ it "should not parse comments" do
13
+ subject.line.parse "/* xyz */"
14
+ end
15
+
16
+ it "should parse namespaces" do
17
+ subject.namespace.parse "@prefix a : <xyz>"
18
+ end
19
+
20
+ it "should parse mappings" do
21
+ subject.parse("xyz = . ;\n")
22
+ end
23
+
24
+ it "should parse uri mappings" do
25
+ subject.parse("xyz = <info:a> ;\n")
26
+ end
27
+
28
+ it "should parse path mappings" do
29
+ subject.parse_with_debug("xyz = info:a / info:b :: a:b;\n")
30
+ end
31
+
32
+
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ldpath do
4
+ it 'should have a version number' do
5
+ expect(Ldpath::VERSION).to_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'ldpath'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ldpath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Beer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - cabeer@stanford.edu
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - ldpath.gemspec
84
+ - lib/ldpath.rb
85
+ - lib/ldpath/program.rb
86
+ - lib/ldpath/version.rb
87
+ - spec/ldpath_program_parser_spec.rb
88
+ - spec/ldpath_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: http://github.com/cbeer
91
+ licenses:
92
+ - Apache 2
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Ruby implementation of LDPath
114
+ test_files:
115
+ - spec/ldpath_program_parser_spec.rb
116
+ - spec/ldpath_spec.rb
117
+ - spec/spec_helper.rb