self-ml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +3 -0
- data/Manifest.txt +7 -0
- data/README.txt +61 -0
- data/Rakefile +12 -0
- data/lib/self-ml.rb +133 -0
- data/test/test_self_ml.rb +40 -0
- metadata +111 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= SelfML-ruby
|
2
|
+
|
3
|
+
* https://github.com/fileability/self-ml
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A SelfML parser in Ruby.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* parses SelfML
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
Parses SelfML, like
|
16
|
+
(food
|
17
|
+
(fruit Apple Banana Orange)
|
18
|
+
(veggies Potato Carrot Onion))
|
19
|
+
|
20
|
+
|
21
|
+
== REQUIREMENTS:
|
22
|
+
|
23
|
+
* parslet
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* gem install self-ml
|
28
|
+
|
29
|
+
== DEVELOPERS:
|
30
|
+
|
31
|
+
After checking out the source, run:
|
32
|
+
|
33
|
+
$ rake newb
|
34
|
+
|
35
|
+
This task will install any missing dependencies, run the tests/specs,
|
36
|
+
and generate the RDoc.
|
37
|
+
|
38
|
+
== LICENSE:
|
39
|
+
|
40
|
+
(The MIT License)
|
41
|
+
|
42
|
+
Copyright (c) 2011 FIX
|
43
|
+
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
45
|
+
a copy of this software and associated documentation files (the
|
46
|
+
'Software'), to deal in the Software without restriction, including
|
47
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
48
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
49
|
+
permit persons to whom the Software is furnished to do so, subject to
|
50
|
+
the following conditions:
|
51
|
+
|
52
|
+
The above copyright notice and this permission notice shall be
|
53
|
+
included in all copies or substantial portions of the Software.
|
54
|
+
|
55
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
56
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
57
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
58
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
59
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
60
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
61
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/self-ml.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
require 'parslet'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
# SelfML is a simple, human writable, machine readable, configuration
|
6
|
+
# language. This is the ruby implementation.
|
7
|
+
module SelfML
|
8
|
+
# The current version.
|
9
|
+
VERSION = "0.0.1"
|
10
|
+
|
11
|
+
module_function
|
12
|
+
# Parse a SelfML document inputed as a string.
|
13
|
+
# Returns an array. That array will contain both strings an arrays,
|
14
|
+
# and so on.
|
15
|
+
#
|
16
|
+
# SelfML.parse("(test awesome x)") #=> [["test", "awesome", "x"]]
|
17
|
+
#
|
18
|
+
# SelfML.parse("(x (1 2 3) [This is a test])")
|
19
|
+
# #=> [[:x, [1, 2, 3], "This is a test"]]
|
20
|
+
def parse(string)
|
21
|
+
Transformer.new.apply(Parser.new.parse(string))
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is a slightly heavier weight way of parsing SelfML strings.
|
25
|
+
#
|
26
|
+
# ml = SelfML::Document.new
|
27
|
+
# ml.parse("test") #=> ["test"]
|
28
|
+
#
|
29
|
+
# This might be slightly more efficient (what with alocating parser
|
30
|
+
# and transformer resources) but it's more verbose.
|
31
|
+
class Document
|
32
|
+
# Create a new document object, with which, you can parse SelfML
|
33
|
+
# documents.
|
34
|
+
def initialize
|
35
|
+
@parser = Parser.new
|
36
|
+
@transformer = Transformer.new
|
37
|
+
end
|
38
|
+
|
39
|
+
# Parse a string of SelfML. See SelfML#parse for more information on
|
40
|
+
# SelfML parsing.
|
41
|
+
def parse(string)
|
42
|
+
@transformer.apply(@parser.parse(string))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# This is the parser for SelfML. Looking at this might be useful. This
|
47
|
+
# outputs a strange, verbose parse tree full of hashes, arrays, and
|
48
|
+
# symbols. See SelfML::Transformer to convert this tree into useable
|
49
|
+
# data.
|
50
|
+
class Parser < Parslet::Parser
|
51
|
+
# Whitespace stuff
|
52
|
+
rule(:space) { match('\s').repeat(1) }
|
53
|
+
rule(:space?) { space.maybe }
|
54
|
+
|
55
|
+
rule(:line_comment) { match("#.+\n") }
|
56
|
+
rule(:block_comment) {
|
57
|
+
str("{#") >>
|
58
|
+
(str("#}").absent? >> any).repeat >>
|
59
|
+
str("#}")
|
60
|
+
}
|
61
|
+
|
62
|
+
# String literals
|
63
|
+
rule(:word_literal) { match('[^\(\)\[\]\{\}#` \n]').repeat(1).as(:literal) }
|
64
|
+
rule(:bracket_literal) {
|
65
|
+
str("[") >>
|
66
|
+
space? >>
|
67
|
+
(
|
68
|
+
(str("]").absent? >> any) # []] and [[] are valid, shouldn't be
|
69
|
+
).repeat.as(:literal) >>
|
70
|
+
str("]") >>
|
71
|
+
space?
|
72
|
+
}
|
73
|
+
|
74
|
+
rule(:backtick_literal) {
|
75
|
+
str("`") >>
|
76
|
+
space? >>
|
77
|
+
(
|
78
|
+
(str("`").absent? >> any).as(:tmp_literal) |
|
79
|
+
(str("``")).as(:double_backtick)
|
80
|
+
).repeat.as(:backtick_literal) >>
|
81
|
+
str("`") >>
|
82
|
+
space?
|
83
|
+
}
|
84
|
+
rule(:literal) { ( bracket_literal | backtick_literal | word_literal ) >> space? }
|
85
|
+
|
86
|
+
rule(:subnodes) { str("(") >> nodes >> space? >> str(")") >> space? }
|
87
|
+
|
88
|
+
rule(:line_comment) {
|
89
|
+
str("#") >>
|
90
|
+
(str("\n").absent? >> any).repeat.maybe >>
|
91
|
+
str("\n")
|
92
|
+
}
|
93
|
+
|
94
|
+
# Node!
|
95
|
+
rule(:node) { ( literal | line_comment | block_comment | subnodes.as(:nodes) ) >> space? }
|
96
|
+
|
97
|
+
# Root stuff
|
98
|
+
rule(:nodes) { node.repeat }
|
99
|
+
root(:nodes)
|
100
|
+
end
|
101
|
+
|
102
|
+
# This is the transformer for SelfML. This takes the parse tree and
|
103
|
+
# converts it to useful data.
|
104
|
+
class Transformer < Parslet::Transform
|
105
|
+
rule(:backtick_literal => subtree(:x)) do
|
106
|
+
x.map do |y|
|
107
|
+
if y.has_key?(:double_backtick)
|
108
|
+
'`'
|
109
|
+
else
|
110
|
+
y[:tmp_literal]
|
111
|
+
end
|
112
|
+
end.join("")
|
113
|
+
end
|
114
|
+
|
115
|
+
rule(:literal => simple(:y)) do
|
116
|
+
x = y.to_s
|
117
|
+
if x =~ /[0-9]+/
|
118
|
+
x.to_i
|
119
|
+
elsif x.split(" ").length == 1
|
120
|
+
x.to_sym
|
121
|
+
else
|
122
|
+
x
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
rule(:nodes => subtree(:x)) { x }
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
if $0 == __FILE__
|
132
|
+
pp SelfML.parse(IO.readlines(ARGV.first).join(''))
|
133
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "self-ml"
|
3
|
+
|
4
|
+
class TestSelfML < Test::Unit::TestCase
|
5
|
+
def parse(string)
|
6
|
+
SelfML.parse(string)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_single_literals
|
10
|
+
assert_equal([:test], parse("test"))
|
11
|
+
assert_equal([:awesome], parse("awesome"))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_numbers
|
15
|
+
assert_equal([1], parse("1"))
|
16
|
+
assert_equal([1234], parse("1234"))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_brackets
|
20
|
+
assert_equal(["This is a test"], parse("[This is a test]"))
|
21
|
+
assert_equal(["This is pretty cool"], parse("[This is pretty cool]"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_backticks
|
25
|
+
assert_equal(["This is a test"], parse("`This is a test`"))
|
26
|
+
assert_equal(["This is a ` test"], parse("`This is a `` test`"))
|
27
|
+
assert_equal([""], parse("``"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_groups
|
31
|
+
assert_equal([[:test]], parse("(test)"))
|
32
|
+
assert_equal([[:test, :awesome]], parse("(test awesome)"))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_recursive_groups
|
36
|
+
assert_equal([[:test, [:awesome]]], parse("(test (awesome))"))
|
37
|
+
assert_equal([[:test, [1, 2, 3], [:qwer, :asdf, :zxcv]]], parse("(test (1 2 3) (qwer asdf zxcv))"))
|
38
|
+
assert_equal([[1, 2, 3, 4], [5, 6, 7, 8]], parse("(1 2 3 4) (5 6 7 8)"))
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: self-ml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Indigo Casson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- ! '-----BEGIN CERTIFICATE-----
|
13
|
+
|
14
|
+
MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhhdGFt
|
15
|
+
|
16
|
+
aXNlcjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
17
|
+
|
18
|
+
MB4XDTExMDgwNzAzMDYxMVoXDTEyMDgwNjAzMDYxMVowPzERMA8GA1UEAwwIYXRh
|
19
|
+
|
20
|
+
bWlzZXIxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
21
|
+
|
22
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKNm6LW3D89zuX8mc+3E
|
23
|
+
|
24
|
+
dP6GcHB0d2UOPjkK56fgIsFVL7/iZW5WWKC48oZNW/Xj5kdV/UJUeObpHkUjfIlM
|
25
|
+
|
26
|
+
7Enjly2L4Dx6ksBrumZm3rIAMXSkqusjGrOAhhKW5nEREai3mvOgC1IF4vbg+wK0
|
27
|
+
|
28
|
+
57uFypWnVQKuEmdZZxtx/4WqxR265ANY+tmzVzZ/yzNLOSdZd8O/t1SBeFWyeJR7
|
29
|
+
|
30
|
+
yK640vPTj0EXJg8WQX8isIJQo++FhNutbX1rdwQV8z1yiiN8k3kV9uNyulI6YoRB
|
31
|
+
|
32
|
+
uVYChQ+vSZuGtoFLEYIlHrRDtpV9Fz0czNoMiSh26PKjyfE8ApHuXz17+owMphQA
|
33
|
+
|
34
|
+
qDkCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUN94xcCFdEJsU9VnUQ2hx
|
35
|
+
|
36
|
+
kl3okEcwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQB3QwcdeoeQEroJ
|
37
|
+
|
38
|
+
zRlxHCUCmVcgmdprEGcP/kyQyKsWjn6L9Meq2eehBIcKDui86ZUVxthDcR9jikM6
|
39
|
+
|
40
|
+
Z0k83Ozuz7BeAax6yHOpCw9ffo/CSfYcQda6iKMKkE0uJjEZBUYLqr+2IzqsvftW
|
41
|
+
|
42
|
+
IYFOJB0i8EsYWApaom3HcGc4AEQsWTMwmz2AofaYhLx/L9blsIA+yq+TJ4aCAMzj
|
43
|
+
|
44
|
+
4R8pYP5HnGmdzD9Ae+fhw4xPyuyI5dT8vxbaQLpK1ev1xPe6ibDZ5Sb41OAd2teX
|
45
|
+
|
46
|
+
cp2ZVwyMXrsOlwoNJiRrAWkRXLVZwb/p+/goBVOdvNyEojn+CgHNFySmXGKuYxEn
|
47
|
+
|
48
|
+
9Dfv1Urv
|
49
|
+
|
50
|
+
-----END CERTIFICATE-----
|
51
|
+
|
52
|
+
'
|
53
|
+
date: 2011-08-07 00:00:00.000000000Z
|
54
|
+
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
requirement: &18951520 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.10'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: *18951520
|
66
|
+
description: A SelfML parser in Ruby.
|
67
|
+
email:
|
68
|
+
- atamiser@gmail.com
|
69
|
+
executables: []
|
70
|
+
extensions: []
|
71
|
+
extra_rdoc_files:
|
72
|
+
- History.txt
|
73
|
+
- Manifest.txt
|
74
|
+
- README.txt
|
75
|
+
files:
|
76
|
+
- .autotest
|
77
|
+
- History.txt
|
78
|
+
- Manifest.txt
|
79
|
+
- README.txt
|
80
|
+
- Rakefile
|
81
|
+
- lib/self-ml.rb
|
82
|
+
- test/test_self_ml.rb
|
83
|
+
- .gemtest
|
84
|
+
homepage: https://github.com/fileability/self-ml
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --main
|
89
|
+
- README.txt
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: self-ml
|
106
|
+
rubygems_version: 1.8.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: A SelfML parser in Ruby.
|
110
|
+
test_files:
|
111
|
+
- test/test_self_ml.rb
|
metadata.gz.sig
ADDED
Binary file
|