-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from danini-the-panini/kdl-2
KDL 2.0
- Loading branch information
Showing
66 changed files
with
3,032 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ | |
Gemfile.lock | ||
|
||
lib/kdl/kdl.tab.rb | ||
lib/kdl/v1/kdl.tab.rb | ||
kdl.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[submodule "test/kdl-org"] | ||
path = test/kdl-org | ||
url = [email protected]:kdl-org/kdl | ||
[submodule "test/v1/kdl-org"] | ||
path = test/v1/kdl-org | ||
url = [email protected]:kdl-org/kdl | ||
branch = release/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ require "kdl" | |
|
||
system 'bin/rake racc' | ||
|
||
puts KDL.parse_document(ARGF.read).to_s | ||
puts KDL.parse(ARGF.read).to_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,75 @@ | ||
module KDL | ||
class Document | ||
include Enumerable | ||
|
||
attr_accessor :nodes | ||
|
||
def initialize(nodes) | ||
@nodes = nodes | ||
end | ||
|
||
def [](key) | ||
case key | ||
when Integer | ||
nodes[key] | ||
when String, Symbol | ||
nodes.find { _1.name == key.to_s } | ||
else | ||
raise ArgumentError, "document can only be indexed by Integer, String, or Symbol" | ||
end | ||
end | ||
|
||
def arg(key) | ||
self[key]&.arguments&.first&.value | ||
end | ||
|
||
def args(key) | ||
self[key]&.arguments&.map(&:value) | ||
end | ||
|
||
def each_arg(key, &block) | ||
args(key)&.each(&block) | ||
end | ||
|
||
def dash_vals(key) | ||
self[key] | ||
&.children | ||
&.select { _1.name == "-" } | ||
&.map { _1.arguments.first&.value } | ||
end | ||
|
||
def each_dash_val(key, &block) | ||
dash_vals(key)&.each(&block) | ||
end | ||
|
||
def each(&block) | ||
nodes.each(&block) | ||
end | ||
|
||
def to_s | ||
@nodes.map(&:to_s).join("\n") + "\n" | ||
nodes.map(&:to_s).join("\n") + "\n" | ||
end | ||
|
||
def inspect | ||
nodes.map(&:inspect).join("\n") + "\n" | ||
end | ||
|
||
def ==(other) | ||
return false unless other.is_a?(Document) | ||
|
||
nodes == other.nodes | ||
end | ||
|
||
def version | ||
2 | ||
end | ||
|
||
def to_v2 | ||
self | ||
end | ||
|
||
def to_v1 | ||
KDL::V1::Document.new(nodes.map(&:to_v1)) | ||
end | ||
end | ||
end |
Oops, something went wrong.